Skip navigation

Category Archives: Hacks

I was always worried about having to go up in a unix directory tree with cd ../. Then I was introduced to this project at work where I noticed that I was doing so much cd-ing around. Sometimes I went so deep in the directory tree I had this scary feeling inside that I’d get lost in a dark pit (true story).

I wanted a better way to do it. So I did what anyone these days would do. But the best the internet could offer were using pusd/popd, aliasing multiple ../s to ..n and using CDPATH. None of these felt natural enough.

So on one boring evening at work I started to scratch my own itch. I started to do it in python but I ended up in a simpler, much better solution. A function for my bashrc.

I call it za because …

cd to za

cd to za (image: markhillary flickr)

you can use za to jumpback any number of directories up to your $HOME directory. Just put the following function in your .bashrc

za 2 #will jump 2 directories up
za #will jump one directory up

Just see it in action.


za in action

Hope you find it useful.

PS: My blog marked 6 years to yesterday (8th August 2012). I’m out of (a year?) long block with this post :)

Update (07-03-2014): There’s a Fish Shell port of Za now.

I was really fascinated by the stuff I have read about Truecrypt. I wanted to try that but I had two reasons to not do that. First, I had nothing really to hide; Second, I thought my poor hp mini won’t be able to handle encrypting a partition, if not the whole disk. And also I was lazy. My close friends, bro and sis know my password anyway. Sis won’t find anything I don’t want her to and I have no problem others finding those. So the only reason I’d try encrypting is curiosity.

One day I was struck by a fireball of curiosity. And I was looking for ways to make portable, encrypted disk I can even put in Dropbox [referral link]. I found few good howtos with lot of details but what I’m going to put together will be an easier howto for a better virtual disk that is encrypted on-the-fly.

I am using Ubuntu 10.04 Lucid Lynx so there maybe a leetle Ubuntu specific things that I’m not sure of. The process has commands that can destroy your data if not used with care. I have tried this and it works perfect for me. If you manage to screw things up in the process that should be purely because you are stupid or careless or even both. And that was my disclaimer.

Alright let’s go make it.

We need dmsetup and cryptsetup installed for this.
$sudo aptitude install dmsetup cryptsetup

Once the installation process is finished we can start making our encrypted vitual disk.

First we create a file with random data in it. You can chose a size that matches your needs. In this example I’m making a 20MB virtual disk so I will create a 20MB file in this step.

$ dd if=/dev/urandom of=~/sekret bs=1M count=20

Here, the dd command creates 20 1MB blocks and fill it with random data. ~/sekret means that we create the filee named sekret in your home directory. You can chose a file name you like and also a path you like.

Next we need to create a block device from the file. For that find a free loop device with
$ sudo losetup -f

And use that loop device and create the block device. Let’s assume /dev/loop0 is free.
$ sudo losetup /dev/loop0 ~/sekret

Now we need to luks format the device. FYI: LUKS stands for Linux Unified Key System.
$ sudo cryptsetup luksFormat -c aes-cbc-essiv:sha256 /dev/loop0

This will warn you that the data in /dev/loop0 are gonna be overwritten. Hope you are confident enough to say yes. Then you are required to enter a pass-phrase for this encrypted this. Chose a powerful pass-phrase here. And then confirm the pass-phrase. The process will report success if we are lucky.


Map the crypto partition using

$ sudo cryptsetup luksOpen /dev/loop0 mycrypt

To be sure about the success run
$ sudo dmsetup ls

This will output something like mycrypt (252, 0).

Now we create file system on the device we created.
$ sudo mkfs.ext3 /dev/mapper/mycrypt

This will create EXT3 file system on the device. You can format it with your choice of file system. At the successful finishing of formatting, we have our own encrypted disk ready to use.

We can mount it with..
$ sudo mount /dev/mapper/mycrypt /media/sekret

Once you are done adding juicy stuff on your device you should unmount it AND REMOVE THE DEVICE FILE.
$ sudo umount /mnt/sekret
$ sudo cryptsetup luksClose mycrypt
$ sudo losetup -d /dev/loop0

Once you have created an encrypted disk, to use next time you only have to follow the steps 2), 4) and 6). Once you are done using the device, unmount with step 7).

I have put an encrypted virtual disk in my Dropbox and it works pretty well. Maybe you’d like to try that too. To use it in Dropbox, copy the encrypted virtual disk file (~/sekret in our case) in to your Dropbox directory.

I have put together a bash script to automate the process and I named it crysp :). You have to run the script as root so use sudo when running it. I might be an evil bastard trying to destroy your data so take a look at the script before you run. With the script you can easily mount and unmount the encrypted devices similar to the usage of mount/umount commands. I have added a dirty hack to allow read/write access to the device from Nautilus. To use this, change chanux to your login name in line 08 in the script.

Find the source in it’s Google Code repository. There’s a version that prevents the existence of thumbnails related to the encrypted disk. check crysp-no-thumb branch for that.

Update: 27-01-2013 Updated the script and put it on a github gist.

It was just after the time cellular phone began to leak in to the middle class Sri Lanka. My father became a victim of a contract too, sharing the destiny of many others in his social circle. I was amazed by it’s powers but not as much as the other non tech savvy people were. I had a friend who shared my thinking and even influenced me more in tech. And I had a brother who always honored his rascal brothers geekdom, and he was there with me, happily, for any seemingly dangerous assignment.


Steve Wozniac, The Woz Phreaking (credit:

And the other day my brother came with a trick. A trick he found somewhere and we had to get our hands on dads phone for this. And this was the time me and my friend were reading some old bunch of magazines, to be specific, called 2600. We were fascinated by the stuff we read. But most of them seemed technically outdated despite the excitement. And we were eagerly trying nasty stuff on whatever we got our hands on. And my brother promised that the trick works.

The phone charges were so high. And dad never wanted us doing something nasty. Pretending just moving through the menus just for the fun of it was the key to get the phone. And we tried the trick. We just dialed a sequence of numbers pressed this and that and we had access to something looked like a voice mail box system, just like that. There were voice menus to present the basics. After a bit of fiddling we knew how to make something seemed to be new accounts. The accounts had a four digit number. We could send voice messages to another number. And receive messages on the ones we create. I can’t remember whether we have a time limit per message. Anyway the good news was “It’s free!”.

With this we had virtually quenched the thirst of phreaking [1], the cool thing we read on 2600 [2]. Me my friend and my brother were exploring the new world we found. Each and everyday we were trying out new things, Going through new voice box numbers and see what they have in them. We didn’t find much of interesting things. The boxes were spread all over a 4 digit number space and we tried some random combinations. I the mean time we used this as a way of communication. Apart from being free, it was so fun be on it. We introduced it to another less techy friend so we had more people to communicate with.

One thing that made the experience so fun was that the guy who apparently leaked to my brother was pretty much a dumb ass. Being what he was, he was also so determined keep things under cover. We found the voice box of that guy with funny messages recorded in it. It was fun to listen to them. We didn’t forget to scare the crap out him by vocally posing as the administrators of the network. As I can remember, the message we sent him saying that we have tracked him down, stating his address precisely, silenced his dumb roars forever. Not only that, he was also useful in some of our experiments.

I was checking one of our boxes, which had an obsolete number, and probably have used for sending nasty messages to other seemingly active numbers. There was this message threatening to stop fucking with the system. But we never knew whether he is a real deal. But later we found some of the numbers being reset. With time the cellular network had a major infrastructure overhaul and the system was not available there after. But by this time we had had the portion of fun it had for us.

After this I never got to hear of the existence of such a voice mail system. Maybe some other curious kids have had found this system and hopefully one of them find this blog. Or even the real administrators of the system :D.

I got my hands on the book “The best of 2600, A hacker odyssey” thanks to @gihangamos. Going through the first few pages gave me these memories back and thought I should put those together on a blog post. The people who read my blog / knows about me will instantly translate “My friend” in to a name. Hope you are reading this buddy :).

[1] –

[2] –

It’s 2300 right now. I should finish this soon and go to sleep.

I wanted share something I use with you guys. It’s actually two Firefox features (probably on other browsers too) combined with some nifty web tools. So the two features are keyword bookmarking and %s variable. Check the following image.

Bookmark - Properties

You see the properties for a firefox bookmark. There you see %s pointed with number 1 and the keyword whois pointed with number 2. With these set, if you type ‘whois’ in to your firefox location bar (awesomebar?) the keyword whois will refer to and the variable %s will be replaced with So you directly go to the whois page for Neat huh?

So I have quite a set of bookmarks setup this way and I’m gonna share them with you.
Bookmarks (right click > save link as..)
save the link to your machine and import the file in to your bookmarks. I’ll list the keywords I use and the purpose below.

gd linux – Performs Google search for keyword ‘linux’ for past 24 hours.
gw linux – Performs Google search for keyword ‘linux’ for past week.
time sri lanka – Googles for ‘time sri lanka’ so I can check time :D // try time new york :P
isdown – Checks whether is down using

hostr – Find where is hosted using
whois – Looks up for whois record using
myip – shows your IP as visible to the internet using
roomatic #tweetupsl – Realtime twitter updates of #tweetupsl hastag with
pdf – Gets a pdf of google home page using
bimg hot chicks – Perorms Bing image search for ‘hot chicks’. // Added this when I heard bing image search is good
unu – get a short url for your long urls

You can edit the keywords as you wish. Hope it’ll be usefull. Yawn!

PS: Oh BTW, got any cool tools to add?

PPS: Some lifehacker links.

Hacking is always fun. That’s why I always lose focus on everything once I find something to hack around. And that’s why I spent whole last night trying to figure out how to mimic Window focus event in a shell script. Though this is completely new to _me_, you maybe very much comfortable with implementing it :) . If so please let me know in comments.

Anyway here is my story.

I found this nice command line IM client called centerIM (Thanx @chathuraw for info). Once I got it set up I was just scanning on it’s documentation page & came across this interesting part “External actions & auto-responses“. I wrote a script right away for GUI notifications, inspired by script for irssi. Here is the script if you are interested.

Since the load of IM messages was very high at a time & It was useless when the terminal window with centerIM was already focused (which means I’m chatting on centerIM) I was thinking of getting notifications only when centerIM window is not in focus. Few Google searches lead me to very limited resources & I chose xwininfo & xdpyinfo commands for my work.

Workaround: I’m using gnome for now & so gnome-terminal as my terminal emulator. I had to set Edit >Pprofile Preferences > Title & command option to keep initial title, in order to have “Terminal” as the terminal window name all the time.

And ran xininfo to get following output.

chanux@nim:~$ xwininfo -name Terminal

xwininfo: Window id: 0x3800003 "Terminal"

 Absolute upper-left X:  0
 Absolute upper-left Y:  52
 Relative upper-left X:  0
 Relative upper-left Y:  27
 Width: 1280
 Height: 691
 Depth: 24
 Visual Class: TrueColor
 Border width: 0
 Class: InputOutput
 Colormap: 0x20 (installed)
 Bit Gravity State: NorthWestGravity
 Window Gravity State: NorthWestGravity
 Backing Store State: NotUseful
 Save Under State: no
 Map State: IsViewable
 Override Redirect State: no
 Corners:  +0+52  -0+52  -0-25  +0-25
 -geometry 156x37+0+25

This can be used to get the window id of the window which runs the script.

Then I can find the focused window at the moment as following.

chanux@nim:~$ xdpyinfo |grep focus
focus:  window 0x3800004, revert to Parent

I fetched the window IDs with a little bit more work.

Anyway the problem I had is that, I get 0x3800003 (at this example) or likewise for the Terminal window id & even when the Terminal id is focused I get 0x3800004 as the focused window id. Yes I know with some more work I can manage to handle that & come to a point that I can compare those window Ids to check for the focused window. But I really like to know why that difference come up. Anyone have an explanation? Or anyone like to mess with this?

Following is the way I fetched window ids from above outputs

chanux@nim:~$ xwininfo -name "Terminal" | grep xwininfo | cut -d " " -f 4
chanux@nim:~$ xdpyinfo | grep focus | cut -d " " -f 4 | sed s/,//