Saturday, 1 November 2014

Asha likes Emacs

Baby Asha at six months, seeing Emacs for the first time.

Tuesday, 14 October 2014

Selecting a strong password that's easy to remember and hard to break

I use Clipperz as my online password manager, and it comes with an easy option to generate strong, secure passwords. I generate one for each site and forget about memorizing it, since that's what a password manager's job is. But there are some passwords I don't put there, such as my bank's and my laptop's. I've come up with a simple and effective way to come up with a password that is both strong and easy to remember.

Here's how it works: pick a song that's currently ear-wormed its way into your head. For this example, I'm picking Queen's Bohemian Rhapsody. Pick a few lines from the song, such as these:
Is this the real life?
Is this just fantasy?

Now take the first letter of each word in those lines: 

Since most websites insist on a mix of special characters and numbers, let's add a comma after the first line, and a question mark at the end, just like in the song:
Now to get numbers, convert a few characters to l33t speak. I usually map A to 4, E to 3, I to 1, and O to 0.  Let's also capitalize the 'F' in 'fantasy' to add some strength to the password. That gives us:
And we're done! You can make the password as long as you need it to be by adding subsequent lines, and strengthen it further with different combinations of easy-to-remember special characters in the right places. But the general principle remains the same. I tested that password out on and it said this:

It would take a desktop PC about 7 thousand years to crack your password
I usually hum the song along as I type the password, so it ties into muscle memory pretty soon. I don't usually run out of good songs, so for the 2-3 passwords that I have to remember, this method works pretty well.

Wednesday, 17 September 2014

Java factorial program with recursion and BigIntegers

Another initiative at work expects me to have a certain amount of Java knowledge. Oh well. Here are some good resources I am currently going through:
Learneroo's first chapter has a factorial method recursively. No biggie. I wrote a quick program, ran and tested it for small values. When I tried it for '100', though:

Enter a number for which I will find the factorial:

Oops. The same program worked fine with Python, what was I doing wrong? A quick check showed that my program returned the result as an int. The highest Int you can get is 2^(31)-1. So, enter the BigInteger class. It is not a native data type and I had to tweak the program a bit to handle it. This is what it shows as the output now:

Enter a number for which I will find the factorial:

And here is the full program:

import java.math.BigInteger;
import java.util.Scanner;

public class Factorial {

    public static void main(String[] args) {
        Scanner read = new Scanner(;
                .println("Enter a number for which I will find the factorial:");
        int num = read.nextInt();
        Factorial test = new Factorial();
        BigInteger result = test.findfact(num);

    public BigInteger findfact(int n) {
        if (n == 1) {
            return BigInteger.ONE;
        } else {
            return BigInteger.valueOf(n).multiply(findfact(n - 1));

Friday, 22 August 2014

Python for day-to-day tasks: the webbrowser module

An initiative at work requires me to analyze a large spreadsheet of data. One of the columns contains a csv-separated list of bugs that I need to take a look at. Normally, this would be a painful job of copying each defect and pasting it in the browser repeatedly. When hundreds of rows needed analysis, each involving multiple defect IDs,  I switched to python to ease my pain.

I knew where to look because of this cute easter-egg in python:

import antigravity

The help text for this module led me to the library, c:\python33\lib\ in my case. The webbrowser module imported here showed how easy it is to launch a browser tab by passing a URL from python:

import webbrowser
import hashlib"")

This was all I need for my job as well. I wrote a 10 line script that basically:
  1. asked the user for input (in my case a comma separated list of defects),
  2. converted the input to a list and stripped unneeded whitespace,
  3. iterated through this list and appended the defect ID to the base URL, and
  4. called the webbrowser module to open the tabs.
The resulting script looks like this:

import webbrowser

bugs=input('Paste the list of bugs:\n')


for i,x in enumerate(buglist):

for i in buglist:

And that's it! A half-dozen tabs open immediately and I can move on to analyzing them. Python has proved to be a boon in my daily job for quick and dirty scripts like this.

Tuesday, 12 August 2014

Heard joke once

Heard joke once:

Man goes to doctor.  Says he's depressed.  Says life seems harsh and cruel.

Says he feels all alone in a threatening world where what lies ahead is vague and uncertain.

Doctor says "Treatment is simple.  Great clown Pagliacci is in town tonight.  Go and see him.  That should pick you up."

Man bursts into tears.

Says "But, doctor..."

"...I am Pagliacci."

Good joke.

Everybody laugh.

Roll on snare drum.

- Alan Moore, Watchmen.

Wednesday, 30 April 2014

Resident Evil 5 Impressions

Am I glad I got RE:Revelations on the 3DS. Since then I’ve moved on to RE: Mercenaries (3DS) and Resident Evil 5 on the PC. I finally got around to finishing the latter over the weekend, and thoroughly enjoyed it. There was a bit of a difficulty spike towards the ending but I blame myself for trying to shoot my way through the enemies instead of observing their weaknesses and attack patterns (damn those Reapers). Mercenaries was what got me into the series’ rhythm of shooting a limb off and closing in for a melee attack.

Where Revelations told the story from multiple characters’ perspectives, RE5 allows you to play only as Chris for the entirety of the game (completing the campaign does allow you to play as his partner Sheva). I decided to stick with the handgun and shotgun for most of the game. The inventory box gets a bit frustrating due to its small size, so I did not have the luxury of carrying (and experimenting with) a lot of weapons.

The campaign is suitably long, and manages to be so without any unnecessary padding. The pacing is great: quiet moments allow you to soak in the atmosphere. A couple of zombie attacks follow, progressively ratcheting up into bigger fights (more enemies, or a mini-boss), all of which finally culminate into a massive boss fight.The levels are well designed and fit the setting pretty well. The game throws in a few driving missions to keep things fresh. These work pretty well and do not outstay their welcome.

Special mention should be made of Chris’s partner Sheva, who does not get in your way all the time, knows how to find her way to you without running in circles, does not continuously demand support in the middle of a firefight, and actually feels like a useful partner. Of course a blindly helpful teammate would have been too boring, and there is enough give and take to make it feel like a true partnership.

Finishing the main campaign unlocks some nice goodies, such as Mercenaries mode and an infinite ammo option that I’m looking forward to try.

The RE movies have long been a bit of a guilty pleasure of mine, and I’ve now become a fan of the games as well.

Thursday, 3 April 2014

Turtle Power

Thanks to this great website, I’ve been having some more fun with Python.  I’m now in the chapter on Recursion, which introduces Python’s Turtle module. Turtle is an implementation of Logo, a language I remember playing with happily in my younger years. What you can do with it in Python is quite amazing sometimes.  There are some demo scripts that come pre-installed, and can be accessed this way:
python -m turtledemo
I’ve still not wrapped my head around the more complex ones, but the Sierpinski example in the tutorial is a nice start. I learned from their example and wrote my own (fairly similar) version. The result looks pretty nice:

A couple of weeks back I wouldn’t have been able to come up with something like this at all, so I’m pretty happy with what I’ve learned so far.
Below is the script. Just pasting it in a python3 prompt should suffice.