Friday, September 26, 2014

Jumping to conclusions

"The fake tree is dying. The leaves are falling off."
"Quick. Glue it back on."
"Wow. He knows the secret of bringing dead things to life."

English is a strange language

"Where's Philip?"
"In his room."
"How is he?"
"What's he doing"
"With whom?"
"Stupid, I said knackered. Not naked!"

Wednesday, June 25, 2014

Friendly Tech Support

"Can you please stop the rain?"
"Sure, what time would you like me to turn it off?"
"I was planning to go home at 4,  could you please turn it off from 4 to 4:15?"
"OK, Let me login to the server."
"The cloud server?"

Saturday, June 21, 2014


You do not plan on being lucky. You do not plan on being successful.
You just do a good job, and plan for all kinds of problems.

Do that right, and you just might get lucky and be successful.

How to bake bread

Tips for people like me who are new too cooking, and always get confused -
  • Tea spoon is the small one and table spoon is the big one. 
  • Remember to set the alarm every time you need to keep something aside for 15 minutes or half an hour.
  • Clean the bowls and pans as soon as you are done with them, cleaning them later when the dough has hardened is a big pain.
Stuff you need:
  • Flour
  • Yeast
  • Milk powder or milk
  • Oil or butter
  • A pan to bake bread in 
  • An oven
  • Warm water
  • Bowl
  • Table spoon
  • Tea spoon
  • Clean cloths
  • A nice warm place where the yeast can grow

Take a bowl and add two tea spoons of yeast, and a bit for luck. Add two table spoons of sugar and one tablespoon of milk powder (or two table spoons of milk), to feed the yeast.

If you are lucky enough to have 24 hours hot water at home, open the hot water tap, and wait until the water stays hot, then open the cold water tap, and make the water slightly warm to touch. Otherwise, find a way to make warm water. Make sure its not hot, or the yeast will die, and you'll end up making some terrible chapathis!

If you have a measuring jar, add one cup of water, if not, add a glass of water.
Mix well, until there are no clumps of yeast around.

Cover the bowl with a cloth and keep aside in a warm place for 15 minutes. When you take it out, you should see a frothy mixture and it should smell of yeast.

Add two tablespoons of salt and one table spoon of oil and mix well. Then add in maida or wheat flour and mix until it stops sticking to the bowl, but it still sticks to your hand. If that doesn't make sense, well, just don't make it too dry. You'll figure it out by the time you bake a few times.

Cover the bowl and with a cloth and keep it in a warm place for another half an hour.

Take a bread baking pan and spread oil on it. Transfer the dough from the bowl to this pan, cover with a cloth and keep aside for another half an hour. If you don't have a pan, don't worry, just oil a plate and use it. It won't be shaped like the shop bread, but it will taste the same.

20 minutes later, turn on the oven to Bake, and set it to 180 degerees Celcius.

10 minutes after that, take the pan with the dough and put it in the oven. You should start getting the sweet aroma of a bakery around 5 minutes later.

Wait for half an hour. Have a nice plastic or wooden spoon ready to help you scoop out the bread.

Take out the bread and turn it around, knock on it a few times and make sure it sounds hollow. If it doesn't, it needs more baking.

Cover the hot bread in a cloth and keep it till it cools. And if like me, you can't resist, every once in a way, cut out a slice and help yourself to it.

Friday, June 13, 2014

Good old Perl

What is Perl used for?

Testing, Web Applications, BioPerl.


Because it has always been used for them.

How are most Perl web applications  run?

Mod Perl.

How long more with this continue?

As long as possible. Probably many years into the future....

Where is Perl used for Web Applications and Testing? 

In the enterprise. A lot of HTML developers may have learnt PHP, and made it more popular than Perl. But for real projects, in large corporations, the choice was Perl.

What does an enterprise want?


This is where Perl shines. It has proven itself many times over.

Companies will keep their existing applications running without change for as long as they can. If they have existing frameworks, they will continue using them for new applications. If they can copy and paste existing code, and use it in a new appliction, they will. A new technology will only be considered if it provides a compelling advantage, generally in terms of money. 

If a company has an existing framework, and does decide to use a new language or framework, then they have to start supporting two frameworks, because they are never going to have the time to translate all the existing applications to the new one. Having to support two or more frameworks or languages is bad, because it leads to increased team size, support and training costs.

So, what should Perl do?

Learn about, support, and train people in the technologies used in the enterprise. And if that means supporting Red Hat Linux, Perl 5.8 and mod_perl, then so be it. 

Continue doing that, and the next enterprise application could well be written with Dancer or Mojolicious, while reusing the existing Perl modules at that company.

Tuesday, June 3, 2014

Redhat Linux commands

To check the status of samba and start it if needed.

chkconfig --list smb
service smb start

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!

What would it take to make a school a night shelter?

Here are my ideas.

A charity organization needs to organize security, to check how many people are entering the school in the evening. Then they wake up the people in the morning, let them get showered if possible, and then make sure they are out of the building an hour before the first student or the first teacher comes in. Also, arrange for portable beds, which can be folded and put aside in the day time.
I am sure the homeless people will be happy to move a few desks and chairs every evening and put beds in their place, and to move them back in the morning before leaving.

Also, we need to organize security for the homeless peoples belongings. We want them to sleep well at night, and not have to think about who is going to steal some of the few things that they have.

 What this means, is that the parents, the students, the teachers, the staff of the charity organization, and the homeless people, all of them feel safe and secure with this idea and with how it is implemented.

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

To create a table:
CREATE TABLE categories (
    name    VARCHAR(64) NOT NULL,
    created_on    DATE,
    created_by    INTEGER REFERENCES user(id),
    modified_by    INTEGER REFERENCES user(id),
    modified_on    DATE   

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

Ruby on Rails models

We generate a rails model only once, when we want to create a new table in the database. After that we use migrations to make changes to our tables.

rails generate model User name:string email:string
bundle exec rake db:migrate

bundle exec rake db:rollback

rails console                     # Saves to DB
rails console --sandbox    # Will not save to DB

>> user = "Test One", email: "")     #Create in memory
>>          # Write to DB, returns true on success
>> user.updated_at
>> user2 = User.create(name: "Test two", email: "")  # Create and write to DB
>> user2.destroy

>> User.find(1)
>> User.find_by(email: "")

>> User.first
>> User.all

>> = ""
>> user.reload   # If you don't want to save your changes, and read details from DB

>> user.update_attributes(name: "Testing One", email: "") # write to DB
>> user.update_attribute(:name, "Tester One")

rake test:prepare

rails generate migration add_password_digest_to_users password_digest:string

Sunday, February 2, 2014

bash tips

Check if the last command you ran was successful

echo $?

If it returns 0, the command completed successfully. 1 means, it errored out.

Monday, January 6, 2014

Useful Linux Commands (ubuntu)

Find the size of a directory
du -ah 

See how much space is free, and how much is used
df -h

List all the commands that you can use as sudo
sudo -l

If the output of the command is:
    (www-data) NOPASSWD: /usr/bin/php
    (www-data) NOPASSWD: ALL

You can run php as www-data, but also, you can run any other command as www-data.

To run chmod as www-data
sudo -u www-data chmod g+w testdir

Copying files from one machine to another, when you want to copy only the changes the next time around.
rsync -avz from_local_dir machinename:/some/dir/on_other_machine

Sunday, January 5, 2014

Postgres commands

dropdb dbname

createdb -E utf8 -O username databasename

pg_restore -O path_to_dump.pgdump -U username -d databasename