indian weather command line tool

Inspired by http://fungi.yuggoth.org/weather, I made a small command line tool to show the weather from a given automatic weather station (AWS) in India.

While fungi’s weather parses US METAR data, such data is usually only available for airports in India. But the IMD has a nice Google maps-enabled page which shows the weather from the different AWS. The data is available as a CSV file with the weather encoded in SYNOP format, which this tool decodes and shows on the terminal.

The code is available at http://github.com/abhidg/inwthr.

Typing the Indian rupee symbol in Debian/Ubuntu

(If you have got a font which has the Indian rupee symbol installed, then the rest of the instructions should hold good for any other Linux distribution as well. I also assume you are using Gnome for a few of the instructions. Note: If you have one of the fonts listed below installed, then you can type Ctrl+Shift+u 20b9 to get the rupee symbol. This works in all GTK/Gnome applications and in OpenOffice. However it is cumbersome and the method below shows you how to get the rupee symbol by typing right Alt + 3.)

First, you have to get a font which has the Indian Rupee symbol, which has the Unicode codepoint U20B9. As of writing, I know of two fonts which support it (at the correct Unicode location instead of replacing other letters), the Ubuntu font and the Rupakara font.

If you are using Ubuntu maverick (10.10), then the Ubuntu font already comes out of the box, so you don’t need to install anything. If you are using older Ubuntu versions or Debian then you can

These packages can be installed by using sudo dpkg -i filename.deb at a Terminal.

To type the rupee symbol, you either need to replace one of the existing characters on the keyboard or use the AltGr key, using which one can use the extended keyboard and get a lot of extra glyphs. If you are using the standard keyboard layout (US English), you do not have an AltGr key and have to remap one of the existing Alt keys. Users with the US International or US Alternative International or UK keyboard layouts have the right Alt key mapped as the AltGr key. [ You can find out which keyboard layout you are using now by going to System » Preferences » Keyboard and selecting Layouts. The top option is your default layout and if you have more than one layout in the list then the keyboard indicator icon at the top right should show the current layout. ]

An alternative to switching to the US International/UK layout is to simply remap your right Alt key to the AltGr key, which can be done in Keyboard preferences » Layouts » Options. Select Keys to choose 3rd level and tick the Right Alt option. Also check Enable extra typographic characters under Miscellaneous compatibility options (Figure 1). A way of doing this from the command line is to use the first part of the tutorial given here.

Figure 1

Once you have an AltGr key, the next step is to assign the Rupee symbol to AltGr+a key of your choice. I choose 3, so AltGr+3 will give you the rupee sign. To do this open a text editor and type:

keycode  12 = 3 numbersign 3 numbersign U20B9 sterling U20B9 sterling

Save the file with the name .Xmodmap (note the dot at the front) in your home folder.

This will assign the rupee to AltGr+3 and the pound (£) symbol to AltGr+Shift+3.

Log out and log back in, Gnome should ask if you want to load the .Xmodmap file, click on the file and then click Load. Enjoy the rupee symbol!

PS If you are use Openbox or a lightweight window manager then you should put xmodmap ~/.Xmodmap in your ~/.xinitrc or ~/.xsession. Of course, if you already have a .Xmodmap file then append the previous line there.

Music players of the next generation

I read this post and felt really inspired. It got me thinking about what music players of the next generation could look like.

My first music player was iTunes 4 or maybe Winamp. My music collection could be counted on fingers and I never really used playlists (I still use them rarely). Then I moved on to Linux and started using audacious and rhythmbox. I tried out banshee for sometime, but that really hogged my system.

So my ideas for the next generation of music players:

  1. Someone implements rainct’s suggestion and it is also media player independent 🙂
  2. The volume goes up and down depending on how far you are from the computer (using some sort of algorithm which is used by say, blueproximity for locking the screen when you are away)
  3. Building on #1, sync popular tracks to the media player (hopefully players also get the same kind of stuff as #1).
  4. Remember the volume used for each track. This should be simple to implement.
  5. All of this is in a nice data store (zeitgeist/couchdb). Sync with Ubuntu one or similar services to get zeroconf sharing of settings across all computers.
  6. A simple way of using blueproximity like things is to shift music playing from different speakers as one moves around the house.
  7. Integrate with shackleton, which is an awesome tool for detecting context. Example: in the office, turn off loud rock and roll songs and switch to ambient music.
  8. Filter by language of the music and/or instrument *without* any manual tagging.
  9. Integrate live data from social networking (twitter/jabber status), so if your friends are playing something which is in your library you can listen to it, right now!

And we need good speech recognition, soon. Then we can take the leap to sci-fi music players 🙂

making keyboard shortcuts in linux as uniform as the mac

Keyboard shortcuts in GNU/Linux are not as uniform as in, say the Macintosh. Having uniform keyboard shortcuts for common tasks which do not conflict is an integral part of a good user interface. While the trinity of cut-copy-paste shortcuts have been almost universally implemented, there are quite a few other shortcuts that should be common (closing a window, quitting an application, opening preferences). Yesterday, I tried to get some uniformity in keyboard shortcuts in my GNOME desktop.

The first thing to do is to allow changing the accelerators (keyboard shortcuts) in the GNOME configuration. This can be done by issuing the following command at a Terminal:
gconftool-2 -t bool -s /desktop/gnome/interface/can_change_accels true

Then I mapped Ctrl to the Alt key (which is just in the place where the Command key is on the Mac) and the Alt key to the Windows key. This can be done in GNOME by going to System »Preferences » Keyboard » Layout » Layout Options… and changing Alt/Win key behaviour. This is not really necessary, but mapping the Ctrl key to the Alt key made it a lot easier for my fingers.

Now to change the keyboard shortcut corresponding to any menu in GNOME, you simply have to select the menu item and press the shortcut you wish to have associated with the menu item. However, this does not work for all GTK programs. The programs for which I could change the shortcuts using this way included Nautilus, Rhythmbox, Pidgin, Totem, Terminal, Gedit, Image Viewer. For example, I changed all the preferences shortcuts to Control+comma. Keep in mind that if the shortcut you assign is already assigned to some other function, then the shortcut will be reassigned to the menu item you’ve selected and the previous functionality corresponding to the shortcut will not have any shortcut assigned to it.

Some other shortcuts that I changed in Nautilus are: Control+I for Properties (this is consistent with the same shortcut for Firefox’s Page Info and the Mac OS X Finder), Control+D for Duplicate, Control+Shift+Delete for Empty Trash and Control+Shift+C for Computer.

Of course, we also have to change the shortcuts for the window manager we’re using. Since I’m using Compiz, I used ccsm (Arch: ccsm, Ubuntu/Debian: compizconfig-settings-manager package), to change the shortcut for closing an window to Control+W (in General Options » Key bindings). Also I changed the default shortcut for Run Command… from Alt+F2 to Control+space in Gnome Compatibility. Since I’d gotten used to pressing Alt+Tab for switching windows, and now Alt had become the Win key, I also had to change the shortcut for switching windows to Control+tab (in Application Switcher).

Firefox: I used the Keyconfig extension to change the keyboard shortcuts in Firefox. I changed the Preferences, Back and Forward shortcuts, as well as the shortcuts for switching to tabs 1 to 9. Since Control+W was now used to close the window, I assigned Control+Shift+W for closing the tab (the same applied for other applications which use tabs a lot, like Gedit).

VLC. I tried to change the shortcut for preferences in VLC to Control+comma but I could not find any way of doing so. There is an option for changing the hotkeys, but that does not include Preferences. So I’ve to stick with the default for the time being. GIMP had a nice shortcut editor, using which I could easily change the shortcut for Preferences.

After all this, you might want to turn off the ability to change accelerators in GNOME by issuing this at the terminal: gconftool-2 -t bool -s /desktop/gnome/interface/can_change_accels false

Update (18 Oct 2009): Registered the uniform-keyboard-shortcuts blueprint in Launchpad.

date hack

The computers at our institute don’t have NTP installed, and the time
is rarely synchronized. The date on the computer I am writing this post
on is about half an hour behind. So here’s how you can get the correct
date from the terminal using wget, sed and the good ol’ date:


#!/bin/sh
# Prints the date.

x="$(wget -q -O - http://tycho.usno.navy.mil/cgi-bin/timer.pl | grep UTC | cut -c 5- | sed s/\,//g)"
date -d "${x}"

Put this file somewhere in your $PATH, make it executable and run it. It’ll print the
date in the local timezone. Here’s how it works:

  1. It gets the date from http://tycho.usno.navy.mil/cgi-bin/timer.pl and dumps it on the
    terminal.
  2. It gets the first line in UTC using grep
  3. It cuts out the
    .
  4. and removes the comma which causes date to choke
  5. Finally date -d converts the date into the local timezone and displays it.

I’ve this script running with watch -n 5 to give the date every five seconds in the terminal.

Xams come..

Exams are coming up in Feb end. Quite early this time. Should manage to scrape through.

———————–
The Mac Mini is a good move by Apple. It will make the Mac more affordable in developing countries like India (and increase my feeble hope of getting one) and create awareness.
I just tried out some of the Linuces a while ago. While they are definitely very good, improvements have to be made in the area of media playback and a decent developer IDE (for GNOME).
Bye for now.