Life Codecs @

Ruminations. Reflections. Refractions. Code.

Jul 22, 2012 - how to software dev

Javascript Core Concepts

Alex Russell’s Google I/O 2011 Learning to Love Javascript video is probably the best Javascript core concepts videos I have seen to date. While I still find the boilerplate required to model what other languages have built-in annoying, the elegance and hackery of building sophisticated things from a small, composable featureset is very neat.

I also love that syntactic sugar is acknowledged to be of use to avoid this boilerplate and unnecessary overload of existing keywords. 60000 incompatible ways to do modules has always been one of my pet peeves for something so fundamental. Javascript in this sense has a case of The Lisp Curse. I do understand that essentially the JS people wish to avoid changing syntax for compatibility, however I think at some point this reticence gets a bit much. Given the alternative browser languages coming up, CoffeeScript being the most mainstream, followed by the Dart initiative, I’d say we have hit that point. Admittedly, Dart is somewhat different, apart from syntactic constraints, it is also attempting to make semantic changes for performance optimisation purposes. CoffeeScript is much more about solving the problem at hand.

“De-Sugaring” as discussed, is the way to go to keep the language core small while allowing more syntactic support. Something like CoffeeScript essentially does this — people should still learn the Javascript core, IMO, before learning CoffeeScript to appreciate the elegance of both languages.

More generally, I had an aha-moment when closures were restated as behaviour that hold on to some state — an inversion of how most of us OO-language users think. This fits very well with my renewed understanding of closures as “closing over” a bunch of state — closed over vars do not go out of scope while the closure is alive. That local vars went out of scope once the function/method completed in many languages, in retrospect, has been the main thing that stopped me from fully “getting” closures when I first looked at it. Then again, it is a subtlety that I had failed to fully appreciate even in Java which does have limited closure support via returning class instances from functions that can reference local vars, so long as they are marked final. By implication, the objects referenced by those vars do not go out of scope whilst the class instance returned holding on to them is alive.

Second satori: As stated above, “the elegance and hackery of building sophisticated things from a small, composable featureset is very neat”, but the syntax is annoying — a language with macro facilities (various LISPs), provides both this composable core, and a unified, extensible syntax. Pretty amazing. In case of LISP, non-syntax really. If only I could get used to the gazillion parentheses of LISP.

Somewhat less elegant than macros (but I love the idea nevertheless) is Groovy‘s parser/compiler hooks which essentially allow you to transform your own syntax/constructs into plain ol’ Groovy at various compilation phases of the program. This is how Groovy allows arbitrary DSLs that do not fit its grammar, a famous example being the Spock Testing Framework.

Jul 8, 2012 - how to software dev

Defaulting to Dvorak on Linux

This is (mostly) a Debian (or derivatives) specific guide to get the Dvorak keyboard layout across the system. Unfortunately, the power of a Unix is also sometimes its curse, in this case, at least as far as I know, there’s no central place to say “use Dvorak”, and have the system honour it. But broadly speaking, there are 3 input areas:

  1. Virtual Console
  2. Display Manager
  3. X session / Desktop Environment (DE)

A ‘modern’ DE like KDE or Gnome, will easily allow you to configure Dvorak through some GUI. I am documenting the case where it is DE-agnostic, and focuses on the X session starting in Dvorak to begin with. So unless there’s a DE override, this should work across all DEs.

Virtual Console

To use Dvorak on the virtual console, on the console issue loadkeys dvorak. This requires the various console keymaps installed. Under Debian, ensure the package console-data is installed; if you issue the command and get a file dvorak not found error or some such, you know you are missing the aforementioned package.

I have not been able to persist a Dvorak-by-default-console setting unfortunately. Will Google some more. There must be a nicer Debian Way, besides just issuing loadkeys directly in some init script. At a per user session, putting it in ~/.profile (or your shell’s equivalent) should work.

Display Manager

Important: This will start your display manager (e.g. GDM, LightDM, XDM) in Dvorak mode! For a shared computer you may not want this!

Edit /etc/default/keyboard, and set/replace XKBVARIANT=”dvorak”, here’s mine:

 1# !/bin/sh
 2# If you change any of the following variables and HAL and X are
 3# configured to use this file, then the changes will become visible to
 4# X only if HAL is restarted.  In Debian you need to run
 5# /etc/init.d/hal restart
 7# The following variables describe your keyboard and can have the same
 8# values as the XkbModel, XkbLayout, XkbVariant and XkbOptions options
 9# in /etc/X11/xorg.conf.
13XKBVARIANT="dvorak" # was empty, set to "dvorak"
14XKBOPTIONS="compose:ralt" # set the Compose key, for accented characters, set to right alt.
15              # see
17# If you don't want to use the XKB layout on the console, you can
18# specify an alternative keymap.  Make sure it will be accessible
19# before /usr is mounted.
20# KMAP=/etc/console-setup/defkeymap.kmap.gz

Note the comment on HAL, I missed it and simply restarted my machine to get it to reload, very lame.

X Session/Desktop Environment

To simply enable a per user X session to start with Dvorak, I set setxkbmap dvorak in ~/.xsessionrc before spawning the window manager. Here’s the full contents of ~/.xsessionrc file (for my own reference):

 1# see:!msg/chrome/t3vPnF_CTBE/UBba0Dp5w3AJ
 2nvidia-settings -a InitialPixmapPlacement=0
 4# enable dvorak by default
 5setxkbmap dvorak
 7# rotate portrait monitor output, use 'xrandr -q' to find out output names.
 8xrandr --output DVI-I-1 --rotate left
10# compositing manager
11xcompmgr -c &
13# accented chars support
14xmodmap -e "keysym Alt_R = Multi_key"
16# Using xfce4-paneli (and thus all panel plugins) with openbox
17# openbox is a lighter wm compared to xfwm
18exec dbus-launch openbox-session

Note that you may have to configure your display manager to launch an appropriate X client script, I use Xsession with LightDM.

A slight digression: Many larger DEs do various magic to start-up, I really dislike this lack of transparency — I can see the value of it for absolute beginners of course, but you grow out of it pretty quickly once you come back to the Unix Way. To that effect, I modified LightDM — the display manager I use — to use Xsession. Here are my relevant changes to /etc/lightdm/lightdm.conf:


This will find a ~/.xsessionrc, and execute that post starting the X server. Note that my script is documented above, it’s nice having a central script to hook in everything you need to start your X session with, including the window manager itself.

Jul 8, 2012 - how to software dev

Switching to Dvorak

In the past 4 months or so, I have switched to the Dvorak Simplified Keyboard layout. This post documents the specifics of the journey.


*Added at Will’s request.

  • I never really learnt to touchtype properly. Thought this would be an interesting skill to have.
  • I was a little bored, and feeling a little crazy.
  • I wanted to be a l33t dvorakista. Work in progress.


  • To learn, I don’t think you can get any better than Dan Wood’s ABCD. It has been a joy to use!

    It is lowtech, so you will need to gauge your own accuracy; for me this worked out better. What you type out is also fairly entertaining!

  • ABCD does not list finger positions visually, so google a guide accordingly.

  • ABCD — it rocks. This is the only guide I used during the learning phase.

  • For general Dvorak information, check out Marcus Brooks’ Dvorak Page, very useful.


  • To practice short daily-use words, I use 10FastFingers.
  • For much longer words, fits the bill rather well.

Migration Strategy and Execution

  • Practice at home for about 2-3 weeks for 30 mins to an hour. It will take you at least that much time to complete an ABCD lesson at first!
  • After 3 weeks, use Dvorak exclusively at home, at the cost of feeling like a retard when chatting with friends. And crying each time I had to code.
  • After a month or so, switch to Dvorak at work. I am a programmer, so this was risky, I had to be confident enough to use it. Code completion was indispensable. Having a dev/team/architect lead who also uses Dvorak is likely even more indispensable. (Is “indispensable” subject to gradation? Also google “indispensIble” vs. “indispensAble”, what a mess.)
  • Around 2 to 2.5 months later, finally feel comfortable typing with Dvorak, though by no means fast. Around this time, reached 40-45wpm. Enough to stick to Dvorak!
  • Due to disuse, Qwerty muscle-memory began to fade!
  • 3.5 months or so later, likely covering my previous qwerty speeds. Able to chat without being considered a keyboard noob.
  • Qwerty muscle-memory gone.

Tips and Personal Ideosynchrasies

  • I found using sophisticated typing tutors, especially those with beeps very annoying. Visual cues are fine and useful, but beeps are frustrating and counterproductive IMO.
  • It will be painful at first, have no doubt about it.
  • It helped that I never learnt to formally touchtype, so this was a skill learnt from scratch.
  • Actually memorising the layout was extremely intuitive to me, all my attempts to learn qwerty touchtyping had failed in the past — it just made no sense. Dvorak actually has, for the most part, a logical system to the keyboard.
  • Shortcuts are one case where I have had to visually mind-map qwerty keys to Dvorak, so I do not have to move to the home keys just to execute a shortcut! It honestly is not that much effort though.
  • Passwords are another pain-point, you need to really let go and have your muscles do their thing, instead of relying on visual feedback too much — which you obviously don’t have when entering passwords.
  • Shell-foo: special characters and shell commands, some not being English words per se takes practice. I am still not as fast as I wish on the shell, unless I am in the zone.

Jul 8, 2012 - software dev

Converting from Mercurial to Git

This is basically augmenting (and repeating) this guide.

# get the hg-fast-export util
git clone git://

# create your git target repo, and cd into it.
git init git_migration_target_repo
cd git_migration_target_repo

# export the hg repo into (current git repo)
/path/to/ -r /path/to/old/mercurial_repo

# don't forget to do this! or git status will show you a bunch of deletes
git checkout HEAD


  • Under Debian, you can issue aptitude update && aptitude hg-fast-export, rather than cloning the repo, unless you want the latest and greatest I suppose.
  • My main use case was converting my bitbucket repo to git, I did the following:
    • bitbucket: renamed the mercurial repo (say call it “foo”) to foo-hg
    • bitbucket: created a git foo repo
    • local: git clone the empty foo bitbucket repo
    • local: perform the migration above into the cloned repo
    • local: push the cloned repo to bitbucket
    • bitbucket: trash foo-hg!

Jan 20, 2012 - general gripe politics

Loudmouth SOPA Proponents & Hypocrisy

It’s been several months since I stopped actively blogging with any real content (actively? real content? me? I know, “does not compute”), there had been nothing interesting to say, and overall I lost motivation.

Today, however, my blogging inertia has abated for a little while by virtue of coming across this article on BBC, discussing SOPA, One of the uniting traits of the world, for better or for worse, is the trait known as stupidity. Alas, there must be something most politicians and executives consume — their own steaming hot air aside — that inflicts this trait so readily in these poor (metaphorically speaking of course) humans.

The metaphor applies to both “poor” and “humans”. In case you were wondering.

I read the article on the way home from work today. My anger (and thus, inertia cure) stems from statements made by the Grand Overlord of the MPAA, a certain US ex-senator Chris Dodd.

Dear audience (or lack thereof), the previous sentence translated to Swahili would be “mgongano wa maslahi” (at least that’s what Google Translate tells me). In Indonesian, we get a clearer indication, “benturan kepentingan” — well okay, clearer if you’re Indonesian. Finally, in Swede: “intressekonflikt”.

To have initially worked for the people and then lobby for a broken corporation, that takes balls. Well, no, it takes very little effort for most politicians (ball bearings? Not even that heavy, sigh), you get the idea. Usually, Republicans are known for stunts like this; to my dismay, Monsieur Dodd is/was supposedly a Democrat. Perhaps, this is an instance of “I say to-may-toe, you say to-mah-toe”.

Let’s examine some statements made by the MPAA (henceforth all quotes are from the linked article):

But backers of the legislation, led by the Motion Picture Association of America (MPAA), described the action as an “irresponsible” publicity “stunt”.

This “stunt” is referring to sites, especially Wikipedia, that went offline, or publicly displayed their anti-SOPA stance. There was nothing irresponsible about it, a huge internet-based protest occurred, no one (except the MPAA and related clowns) got hurt — compare that to almost any other massive protest — the worst thing that happened (for MPAA of course), is enlightenment. People seeing the blackout (notice the irony?) woke up to the mess that is SOPA — which by the way, is irresponsible considering it wastes tax payer money to essentially assist a very, very rich bunch get even richer. This happened according to Wikipedia (in the article):

“More than 162 million people saw our message asking if you could imagine a world without free knowledge,” the site said. “You said no. You shut down Congress’s switchboards. You melted their servers. “From all around the world your messages dominated social media and the news. Millions of people have spoken in defence of a free and open internet.”

I am not a US citizen, however any bill that affects a global network needs to involve custodians and netizens of said network. I consider myself a netizen, so this matters to me.

The MPAA is neither a custodian, nor a netizen of the Internet.

It is a leech.

But pardon me, a leech has blood sucking as a natural instinct. Ergo the MPAA is a lot worse than a leech, incomparable even — please ignore my previous analogy.

The MPAA’s constituents happily use the Internet when it suits, then trash it when it doesn’t. In layperson terms, that’s akin to crapping in your community centre’s hall. That’s just how disgusted I am by this organisation. And if the organisation is not enough, let’s continue with Monsieur Dodd. Oh, boy… this is one broken toy… (woot, a rhyme):

Ex-Senator Chris Dodd, MPAA’s chief executive, described the blackouts as an “abuse of power”

One word: “intressekonflikt” (or is that two?). You’re talking about “abuse of power”? Really?

The above quote doesn’t take the cake though, next I reveal the real impetus behind my post. Check this Oscar-winning material out:

Ahead of the day’s action, Mr Dodd said: “It’s a dangerous and troubling development when the platforms that serve as gateways to information intentionally skew the facts to incite their users in order to further their corporate interests.”

I wonder if Mr. Dodd was in a room full of mirrors when he said this. Or perhaps he just came out of some form of freaky MPAA-sponsored Cataract-Vipassana 15-day retreat. I mean, really.

Okay, more talk of Mr. Dodd and yours truly will need to go on that retreat. Let’s move on to good ol’ Rupert Murdoch:

News Corporation chairman Rupert Murdoch, a vocal supporter of Sopa, continued to spar with users on Twitter. He tweeted: “Seems blogsphere has succeeded in terrorising many senators and congressmen who previously committed. Politicians all the same.”

“Terrorising”? If ever there was a Hackneyed Word of the Decade competition, this would get my vote. So protesting these days is “terrorising”? Hmm. And the News of the World crackery bullshit was, I suppose, ethical journalism in comparison. The only shred of truth in his tweet, in as far as generalisations go, is the last sentence. And Mr. Murdoch, Wikipedia is not a blog, in case you haven’t been doing rudimentary fact-checking in recent times. The Internet is not just the “blogosphere” (his actual tweet spelt it correctly).

And yes, when I said “good ol’”, it was sarcasm. In case you were wondering.

The sheer ease with which executives and politicians spout brobdingnagian volumes of pungent, diarrheic verbiage never ceases to both disgust and amaze me. I mean, that you can manage to stay in human form while expertly incanting turdspells like the above is nothing short of a miracle. The utter blindness to your own actions, the total inability to reflect on things as they are, the overreaching stupidity, the incomprehensible levels of arrogance… wow.

I need to do something about this naïveté of mine… one of these days.

As the Nihonjin say, well at least the Anime Nihonjin: yare yare…