Latest Publications

The Passion of the Caffeine

This month in Dehradoon I rekindled an old flame. Coffee.

The truth is that I find it difficult to get decent coffee inside the campus of IIT Kharagpur (at least when you live in the Madan Mohan Malviya Hall of Residence). You are either stuck with some weird synthetic high-sugar stuff handed to you by the Nescafe guys (not to mention the paper cups) or have to carry your ass to the Veggies / Eggies restaurant to sit about fifteen minutes for something slightly less shitty. And I, trust me, do not want to get started on the detergent-smelling coffee we were served inside the MMM mess.

As a coffee freak, the mug is as important to me as the coffee. I (naturally) prefer a large mug, in earth colors. Right now I am sipping from a beautiful hand-painted light-brown mug I picked up a year and a half ago from a national trader’s fair thing in Dehradoon. I actually carried this thing to Kharagpur – too bad I never got to use it!

As far as the brew is concerned I love the plain Nescafe (this is not an advertisement, I am just voicing my personal opinions). And by plain I mean plain, not fuckin 30 % chicory bullshit. And I like it strong, about one heaped tablespoon per cup.

I have learned a lot in my one year stint in Kharagpur – not take-notes-in-the-classroom learning but download-video-lectures-from-dc-and-actually-make-some-good-use-of-the-internet learning. But now I sit in front of my terminal, listening to Dylan and Rammstein (I know I’m weird), sipping an unusually strong brew of coffee, my legs completely sore from today’s workout, typing code (well not exactly, but that’s what I was doing few minutes ago) I feel myself reconnecting with a part of me which I had lost – a part of myself I had abandoned. That will not happen again. I will not let that happen again.

There! My first non-technical post.

Converting to JFS

I finally did it! Now my root partition is, instead of a boring old ext3 a shiny new JFS parition.

The very first thing I did was build a new kernel with JFS support compiled into it. While configuring the kernel I also selected the deadline IO scheduler as the default scheduler since it tends to extract the best performance out of a JFS partition. Then I installed the new kernel. Now I needed some way to convert the existing root partition (in the device /dev/sda9) from ext3 to JFS. Since even after having installed every program I need (and two and a half desktop environments) the total size of the partition was a meager 9 GiB (compare that to a fresh installation of Windows Vista) this had a simple and safe solution – simply backup and restore the files. One nice automated way is to use some software like CloneZilla. I, however, like doing things my way. I burned an Arch Linux installation CD and started up my notebook from it.

The best part about the Arch Linux install live CD is that after booting up it gives you a very clean, no-frills bash environment to work on. Once I was up and running I did a simple mkdir /media/root and mounted the partition onto the new directory by mount /dev/sda9 /media/root. Since I was logged in as root I really did not need to use sudo or su. I also needed another partition with space to spare. I used /dev/sda5 – an ntfs partition. I mounted it by mkdir /media/backup and then mount -t ntfs-3g /dev/sda5 /media/backup. Instead of simply copying the data from /media/root to /media/backup I used TAR – cd /media/root; tar cvf * /media/backup/everything.tar. This actually sped up the process a little (or so I though) since it prevented the ntfs-3g driver from wasting time by allocating space for the tens of thousands of files. The entire thing took about twenty minutes to complete.

That done I unmounted the partition – umount /media/root and ran mkfs.jfs /dev/sda9. This warned me about losing all data and then converted the partition. The conversion, surprisingly, took only about a second or two.

Now it was time to restore the files again – I mounted the partition again using mount /dev/sda9 /media/root and extracted the tar files – cd /media/root; tar xvf /media/backup/everything.tar. Then I installed GRUB using grub-install. I restarted my system only to find the kernel unable to boot.

A little probing showed what was wrong – while initially installing Arch Linux the installer had configured my GRUB’s menu.lst to recognize my disk using its UUID. The reformatting some reset the UUID of my partitions (I really do not know how or why). I fixed that by changing the /by-uuid thingode>/dev/sda9. I know, I know - this was not the right way but it did work and I saved a lot of time. I had to fix /etc/fsatb for the same reason.

So now my computer boots faster, applications load without eating too much CPU and the system is more responsive overall.

Wrong framebuffer resolution in 2.6.30

The i915 driver for the Intel GM965 is broken in kernel 2.6.30 – instead of getting 1280×800 framebuffer console you end up getting up getting 1024×768. Please note that the (overall) resolution is perfectly fine – only the text will appear to remain constrained in an imaginary 1024×768 box. This happens at least in Acer 4720z and probably in other boxes too which use the GM965 and have a TV out. What really happens is that the kernel mistakenly detects a projector connected to the TV-OUT even though there is none and sets the framebuffer resolution to 1024×768. This is evident from the output of dmesg -

...
[drm] TV-12: set mode 1024x768 18
...

This is especially annoying for people like me who

  1. Like to use the console for things that do not require starting up X.org

  2. Have painstakingly created a boot-logo which the wrong resolution is ruining.

  3. Want every aspect of their computers to be flawless.

All the while I was trying to google with terms like “wrong resolution” and “changing the framebuffer resolution” only to find the forums invariably advising me to add vga=773 to the kernel boot line – something I knew would not work.

Anyways after googling with the above dmesg line I finally came across a patch which supposedly fixes the problem. When I tried to patch my kernel, however I got two failed hunks. So I tried to use my own hunking abilities and fired up my trusted vim.

To cut a long story short, the culprit is drivers/gpu/drm/i915/intel_display.c and you can download an edited version here. Just replace the file, re-compile and you are ready to go.

Experiencing Music

I just discovered a new companion (no, not an iPod), but the MPD – Music Player Daemon. This is the probably the first time I am feeling truly satisfied about my music player.

The MPD runs as a service. It binds to a port on your computer (6600 by default). Once you have the MPD up and running (you need to edit mpd.conf for one thing) you need to install (or write yourself) additional client software which talks to the daemon. Once such program is mpc.

mpc is essentially a console program. You need to set the MPD_HOST and MPD_PORT environmental before you start using it (unless you’ve really left everything to the defaults). So to first scan the directory you’ve set in mpd.conf as the root of music you need to run mpc update. This fetches the file names and the id3 tags to create a media library. Then you can search by running mpc search ANY some_term (hint – read the man-pages) to get a list of the songs which have some_term in any field. You may specifically search in the author field, in the title field among other things.

You run mpc add to add music to the playlist, mpc play to start playing it, mpc next to move to the next song and so on …

I have not tried this but it seems that in case you are on a network anyone on the network may stream music from your MPD server. However you do have access control – you may set a password and not allow the users who do not authenticate themselves with the password to, say, change the song. It is also reportedly easy to hook this up with IceCast to broadcast over HTTP.

Mounting an FTP folder

Recently I came across this very interesting utility – CurlFtpFS (curlftpfs.sourceforge.net/). It allows users to mount FTP sites as local folders. I had an inkling that something like this could be done but I never imagined that it would be this easy!

To mount ftp.subdomain.domain.org to /home/me/random_folder all you need to do is execute curlftpfs -o user=username:password ftp.subdomain.domain.org /home/me/random_folder. Of course curlftpfs allows for dozens of other options to completely customize what you want it to do.

One very nice use this concept can be put to is hosting a git repository on an ftp server in which you have an account. This is useful if only a handful of people need to access the repository and you do not wish to make the source code public on places like github. All you need is a free FTP account – once you have it you simply mount the server onto a local folder and initialize an empty repository in the folder. You can then push your commits onto the git repository. Practically speaking this will get problematic if multiple people want access to the repository at the same time but if the project involves only a small number of developers then this should not be a problem.

Technorati Formality

I just claimed my blog on Technorati.com – and they want me to put up a link to my profile on their website on my blog.

So here it is Technorati Profile

Reflection with Java

During my recent clean-my-hard-drive-of-all-obsolete-files spree I discovered a small article I had written about RTTI (Run Time Type Identification) in Java. Instead of pasting everything on the blog (and risk destroying the formatting) I decided to export it as a PDF file so that you can download it here.

Despite me not having edited the file at all after JDK 1.5 it should mostly be relevant.

Setting Pixels in Swing

Some time back I faced a problem in a (Java based) project on which I am still working on – I needed a swing component which would have a suitable interface allowing me to set the color of individual pixels. Since I could not find anything which had a similar functionality I extended javax.swing.JPanel and created a component of my own. Check it out here [test code included].

Blogging about Logging

I recently discovered a really nice package in Java – java.util.logging. Classes inside this package make adding logging functionality to your application both intuitively simple and fun. Here what I would like to think to be a short guide to using the package.

The very first thing you need to understand that there may be multiple loggers active in a Java application at a given time. Each such logger has a name associated with it. The names are hierarchical – you have the concept of a logged being the sibling or the parent of another logger. We will come to how that exactly works in a minute. Every logger has one or more handlers associated with it. It is these handlers which decide what exactly happens when you log a message (for example the handler may write to a file or print the messages out to the PrintStream). By default a logger also uses the handlers registered with its parents, recursively. You can change this behavior if you want to.

A global namespace is maintained containing the names of all the loggers. The logger names follow a dot-separated convention, somewhat like the one followed by the Java packaging system. This means that “parent.someChild” is a child of “parent” while “parent.someChild.someGrandChild” is a child of “parent.someChild“. “parent.sister” and “parent.brother” are siblings. “” is the root – the parent of each and every logger, either directly or indirectly.

Every logger has a Level associated with it – the minimum required urgency of a message for it to actually get logged. Similarly every log you make also have an associated Level, underlining the measure of its urgency. For instance if you wish your logger to log only the very critical messages you may set the level of the logger to Level.SEVERE or to Level.WARNING. There are other levels too, like Level.FINE and Level.INFO. You may set the level of a logger to Level.ALL or to Level.OFF to log all messages or no messages at all respectively.

The best part about the system is that you do not need to pass around objects – since there is a one to one mapping from the logger names to logger objects in global namespace, you can simply pull out the Logger associated with a name using Logger.getLogger (String name). The first call to Logger.getLogger ("mylogger") will create a new logger and return it while subsequent calls will simply return the previously constructed Logger instance.

So if you need to log from within your application you basically create Logger instances from inside each module you wish to log somewhat like Logger theLogger = Logger.getLogger ("myproject.thisModule"). Now you can use this object in your code – theLogger.warning ("Something happened"). In the application initialization code you have the liberty of setting the Levels of each logger to control what all information gets logged. You also have the freedom to write custom Filters using which you can control exactly what all is logged.

The world of a Hacker

I read this piece somewhere … It was written back in 1986; by someone named ‘The Mentor’

Another one got caught today, it’s all over the papers. “Teenager Arrested in Computer Crime Scandal”, “Hacker Arrested after Bank Tampering”…

Dang kids. They’re all alike.

But did you, in your three-piece psychology and 1950′s technobrain, ever take a look behind the eyes of the hacker? Did you ever wonder what made him tick, what forces shaped him, what may have molded him?

I am a hacker, enter my world…

Mine is a world that begins with school… I’m smarter than most of the other kids, this crud they teach us bores me…

Dang underachiever. They’re all alike.

I’m in junior high or high school. I’ve listened to teachers explain forthe fifteenth time how to reduce a fraction. I understand it. “No, Ms. Smith, I didn’t show my work. I did it in my head…”

Dang kid. Probably copied it. They’re all alike.

I made a discovery today. I found a computer. Wait a second, this is cool. It does what I want it to. If it makes a mistake, it’s because I screwed it up. Not because it doesn’t like me…

Or feels threatened by me…

Or thinks I’m a smart aleck…

Or doesn’t like teaching and shouldn’t be here…

Dang kid. All he does is play games. They’re all alike.

And then it happened… a door opened to a world… rushing through the phone line like heroin through an addict’s veins, an electronic pulse is sent out, a refuge from the day-to-day incompetencies is sought… a board is found.

“This is it… this is where I belong…”

I know everyone here… even if I’ve never met them, never talked to them, may never hear from them again… I know you all…

Dang kid. Tying up the phone line again. They’re all alike…

You bet your life we’re all alike… we’ve been spoon-fed baby food at school when we hungered for steak… the bits of meat that you did let slip through were pre-chewed and tasteless. We’ve been dominated by sadists, or ignored by the apathetic. The few that had something to teach found us willing pupils, but those few are like drops of water in the desert.

This is our world now… the world of the electron and the switch, the beauty of the baud. We make use of a service already existing without paying for what could be dirt-cheap if it wasn’t run by profiteering gluttons, and you callus criminals. We explore… and you call us criminals. We seek after knowledge… and you call us criminals. We exist without skin color, without nationality, without religious bias… and you call us criminals. You build atomic bombs, you wage wars, you murder, cheat, and lie to us and try to make us believe it’s for our own good, yet we’re the criminals.

Yes, I am a criminal. My crime is that of curiosity. My crime is that of judging people by what they say and think, not what they look like. My crime is that of outsmarting you, something that you will never forgive me for.

I am a hacker, and this is my manifesto. You may stop this individual, but you can’t stop us all… after all, we’re all alike.