Wednesday, April 23, 2014

More efficient night shelters

I was at Charity IT recently, a weekend event where developers help charities with IT projects. The projects selected are small and can be delivered by a small team in 2 days. We have a team member from the charity sitting with us througout, and answering any questions that we have.

One of the charities we worked with is the Wellington Night Shelter. They provide beds for the homeless, and we helped them speed up their reporting. The reports are used to generate more funds.

Many homeless people struggle to find a place to stay out of the wind, the rain and the cold. The night shelter starts admissions at 5:30 PM and there is a queue when it opens. It gets full quickly, and many people are left out at the end of the day to fend for themselves.

While there are so many buildings that are empty at nights.

I realized this last evening, I was walking past a school, and it was closed. It struck me that schools all over the world are closed at nights.

What a waste!

Friday, April 4, 2014

Would you pay someone to wash your car

I recently saw a a little girl and her brother carrying signs on a roadside -


A few adults stood next to a tap nearby with buckets, a pipe and soap.

These people were willing to work hard. But, they had no cars to wash. No one stopped.

It occurred to me that we need a way to bring together the people in a location who want their cars washed, and those who are willing to wash those cars.

I believe that, if it becomes as easy to call someone over to wash your car, as it is to drive your car to the nearest service station, a lot of people would do it.

What do you think? Would you pay someone to wash your car?

Sunday, March 30, 2014

How to move to Amsterdam

If you are a Perl developer and want to move to Amsterdam to work for, it is a good idea to do these first.

I don't work for, and I didn't get through the interview. But if I did these things, I would have had a much better chance.

The interview questions, and the suggestions here are based on what is actually being used by in production. They use MySQL, and a lot of their code is old and is written in object oriented Perl. So, understanding them and being able to work with them is important.

Practice writing Perl code:
Write object oriented Perl code (not Moose)
Write code to read from large files
Write code to work with MySQL databases
Write code which uses hashes of hashes and other complicated data structures
Write Perl versions of the examples in Programming Pearls

Read these:
Read the Perl FAQ
Read the MySQL documentation
Read Programming Pearls

Learn about the business model
Think about the problems they could possibly have, and how you would solve them.

Learn about database design, normalization, denormalization, sharding and anything else related to MySQL performance.

They are always looking for Perl developers. It would help to prepare well and then apply.

All the best!

Monday, March 24, 2014

MySQL commands

To login to mysql without selecting a database
mysql -h hostname -u username -p
(hostname can be an IP addrress)

To create a new database, and user and grant permissions on that database to the new user.
create database moodle;
create user 'moodle'@'localhost' identified by 'password';
grant all privileges on moodle.* to 'moodle'@'localhost';

To run the sql script in the file text_file.sql in the database databasename:
mysql -h hostname -u username databasename -p < text_file.sql

How to test creating a new row in the database

A webpage has a form and a 'Create my account' button on it which is used to create a new user.

initial = User.count
click_button "Create my account"
final = User.count
expect(initial).to eq final

Here, User is the resultset, which includes all users.
We didn't fill in any data, and we are clicking the button to submit an empty form. We expect that a new user will not be created.
So the initial count of users should remain unchanged after clicking the "Create my account" button.

To test the case where the User is successfullly created, you fill in all the values, and check that the final count is 1 more than the intial count.

visit signup_path
fill_in "Name",         with: "Example User"
fill_in "Email",        with: ""
fill_in "Password",     with: "foobar"
fill_in "Confirmation", with: "foobar"
expect do
  click_button "Create my account" change(User, :count).by(1)

RSpec allows you to write the first test this way-

expect { click_button "Create my account" }.not_to change(User, :count)

Working with Ruby on Rails

If you make a change to the Gemfile, run bundle install, and remember to restart the server.

bundle install
rails server

rails console
rails console test
rails server --environment=production
rake db:migrate RAILS_ENV=production

When you change a model and add a new column, if you want to use it in your form, you can't just update the view. You have to add the new column name to the whitelist in the controller.

    # Never trust parameters from the scary internet, only allow the white list through.
    def user_params
      params.require(:user).permit(:name, :email, :password, :password_confirmation)

Sunday, March 23, 2014

SQLite Commands

sqlite3 development.sqlite3
sqlite> .tables
sqlite> .schema users
sqlite> select * from users;
sqlite> .quit