2009-09-20

Word permutations

I wrote a web-based word permutator in perl for getting all legal letter combos (also known as... words) given a string of characters. Why I wrote it? So that I can cheat when I get stuck when playing Scrabble and the like.

You can play with it here: http://blahonga2.yanson.org/ww

Modifying gnome-terminal to understand Spotify URIs

My primary tool on my Debian box (asides from emacs) is gnome-terminal. I use mutt for email, and irssi for irc.

And since I'm an avid user of Spotify, and trade links to music with my friends and collegues, I've been irritated about the fact that I cant click on Spotify URIs in the terminal like I can with mailto: and http: tags.

So I fixed it. Its a rather simple fix, but very useful. Here's how I did it. Oh and btw, since Lenny's version of gnome-terminal is rather old, this fix works only on gnome-terminal version 2.22.3- the version which comes with Lenny.

Anyway, quick summary of what we'll do. We download the source for gnome-terminal, apply a little patch to it, compile the code, and register the spotify: URI with gnome.

  1. Download and unpack the source code
    $ wget  http://ftp.acc.umu.se/pub/gnome/sources/gnome-terminal/2.22/gnome-terminal-2.22.3.tar.gz
    $ tar zxvf gnome-terminal-2.22.3.tar.gz
    $ cd gnome-terminal-2.22.3/
  2. Apply patch
    $ cat > gnome-terminal-spotify.diff <<EOF
    87c87,88
    <   FLAVOR_EMAIL
    ---
    >   FLAVOR_EMAIL,
    >   FLAVOR_SPOTIFY
    314c315
    < #define SCHEME    "(news:|telnet:|nntp:|file:/|https?:|ftps?:|webcal:)"
    ---
    > #define SCHEME    "(news:|telnet:|nntp:|file:/|https?:|ftps?:|webcal:|spotify:)"
    332a334,337
    >                            "\\<(spotify:)[^<>\ \t\n\r]*\\>",
    >                            FLAVOR_SPOTIFY);
    > 
    >   terminal_widget_match_add (screen->priv->term,
    1438a1444,1446
    >     case FLAVOR_SPOTIFY:
    >       url = g_strdup (orig_url);
    >       break;
    EOF
    $ patch src/terminal-screen.c gnome-terminal-spotify.diff
  3. Compile the code
    $ ./configure
    $ make
    $ sudo make install
  4. Register the spotify: URI
    $ gconftool-2 --set --type=string /desktop/gnome/url-handlers/spotify/command " wine 'c:\Program Files\Spotify\Spotify.exe' '-uri' '%s'"
    $ gconftool-2 --set --type=bool /desktop/gnome/url-handlers/spotify/enabled true
    $ gconftool-2 --set --type=bool /desktop/gnome/url-handlers/spotify/need-terminal false

Remember that all the different gnome-terminals run under the same process, so when testing you'll want to spawn one as a separate process:

/usr/local/bin/gnome-terminal --disable-factory

All done!

2009-07-11

Pain upgrading the iPhone to 3.0 under Virtualbox

Edit: I was informed by neh that all this was unnecessary, as you can get Vbox to auto-connects devices. Thanks Nathan!

Long story short: An upgrade to iphone version 3.0 under virtualbox and Debian as host system is possible, but it has to be done just right.

What you need to know before upgrading:

  • During the upgrade, the iPhone changes USB ID twice.

Yep thats about it. What you do is this.

  1. Jack in your iPhone to your linux box.
  2. Verify that it has been connected by running the command 'lsusb' in a terminal. You should see something like this:
    $ lsusb | grep -i apple
    Bus 001 Device 006: ID 05ac:1292 Apple, Inc. 
    $
    
  3. Now start virtualbox. In the settings for your Windows guestOS, under USB: check that your iPhone is visible and selected.
  4. Start the guestOS. Your iPhone should be autodetected and iTunes should start up.
  5. Tell iTunes to start the upgrade. (I have to admit I dont remember if iTunes prompted me to upgrade or if I somehow chose to. Click around till you get to upgrade.)
  6. Once it starts to upgrade, you'll notice that an icon at the bottom of the vbox window (dont run full screen!) looks kind of like a usb stick. Hover your mouse over it, and you should see a popup with a string like "Apple Iphone".
  7. Here's the tricky part. Once it is ready to upgrade, the iPhone drops into 'recovery mode', and it changes USB ID. When it changes USB ID it VirtualBox will
    1. Detect that the old usb device (Apple Inc. iPhone) has disappeared.
    2. not automatically present the new device which your linux machine has detected.
  8. Turn off your guestOS (even if you need to SIGKILL it).
  9. Start up Virtualbox again.
  10. In the Settings for USB, look for the new device. It should be called something like "iPhone recovery device" or something.
  11. Make sure that both your original iPhone device and the new device are visible in your list of USB devices. Only the recovery device need be checked.
  12. Start up your guestOS.
  13. Once started, check that the Recovery USB device is actually activated, by hovering over the USB icon at the bottom of the vbox window. If it doesn't show the name of the recovery device in bold, right click the icon and select it to activate it.
    For me, this happened a number of times. There seems to be a timer involved- if you dont re-activate the device in time, you'll have to start again from the previous bullet. You'll get an error message- I think it was error 1604. Like I said, just restart the guestOS, and you should be fine.
    Note: I had to restart my hostOS as well once, since I uncleanly killed the virtualbox process, leaving a tainted kernel module which refused to work properly.
  14. After a while, the process reverses itself- that is, the recovery device is not considered necessary anymore, and it disappears from the list of USB devices. Instead, you'll need to actively select the regular iPhone device. The normal timer rule applies.
  15. After a few more activating devices manually, you should be told by iTunes that the upgrade is complete. Now you'll need to re-activate the iphone device one last time for the final sync, to get all your precious data back into your system.

Thats about it!

2009-03-21

Text-based Graphical Desktop Environment

I was directed by reddit over to a project by a certain gentleman called Andrew Wales; where he has managed to run a X server using aalib to render the display.

You really have to check out the screenshots, totally awesome! http://www.meow.org.uk/stan/xserver

Imagine running mplayer with aalib as video out under an aalib X server!

2009-03-19

emacs unstable?

For the first time ever (as far as I remember anyway), emacs crashed on me. Or rather- it froze. I'm guessing it wasn't the core application as delivered by the GNU folks- its probably in one of the modules I loaded when I was testing connecting to twitter and running ssh from emacs.

I guess I've learned my lesson- start a separate instance of emacs for testing, leave the ordinary one alone. Right now I have no idea how many buffers and shells I had open... All I know is that my machine has an uptime of two months, and I'm rather certain that the first program I started was emacs. And I never turn it off...

Oh well.

2009-03-13

Japanese music via last.fm

For years I've been moaning over how hard it was to get a feel for what was popular in Japanese music. The other day I realized that I could satiate my desire for Japanese music from last.fm.

Hurrah!

2009-03-11

emacs via plink, Hummingbird, but no putty window

At the office about 95% of all work I do is on unix machines, inside of emacs. Inside of emacs, I do most of my command-line work, SQL connections to sybase, I do my IRCing, I send email, and of course I edit and compile code in emacs as well. Typically I have between twenty to fifty buffers open at any given time.

But I sit by a windows machine. I have to use putty to connect to my primary development machine, where I commence with starting emacs which opens a window on my local machine under Hummingbird's X server.

The problem with this is that after a couple of days (or hours!) I forget which putty session spawned the emacs I'm sitting with. Inevitably I end up hitting ctrl-d to close the window, and it then... just hangs there, waiting for all daughter processes to die. And emacs proudly floats there on my screen, with all my open files, notes, running programs and sql sessions.

And I don't want to close it. But the hanging putty window is there, in my taskbar, taunting me. What to do?

I realized that I wanted to be able to start emacs on a remote machine without first opening a putty session. I wanted the windows equivalent of

ssh -XY remotemachine.foo.com "emacs --eval \(server-start\)"
.

Here's what I did.

  1. First I made sure that pageant was running, and that it had my private key loaded. I made sure that it was auto-started by windos when I logged in.
  2. Next I created a putty session which contained the configurations necessary for X11 tunnelling etc, gave it a name 'remoteSession'.
  3. Now I created a .bat script which contained the following:
    REM Startup emacs on remote machine
    plink -X -A -agent -load remoteSession -l my_username ". .bash_profile ; emacs --eval \(server-start\)"
    This script will, when run, connect to the remote machine and start up emacs as a server. I source .bash_profile since I have some environment settings there, yhou might not need it.
  4. The thing is, the previous step works, but it leaves an ugly windows commandprompt window which just... well hangs there. If there's something that bugs me more than a useless putty session window, its the worlds ugliest shell. So I wrote a VBscript which starts the .bat script, but without a window.
    Set WshShell = CreateObject("WScript.Shell")
    WshShell.Run chr(34) & "c:\mattias_progs\devapp_emacs_server.bat" & 
    Chr(34), 0 
    Set WshShell = Nothing 
  5. Finally I made a shortcut to the vb script into my start menu, so that I could fire it up at will.

Its a very small improvement, but it makes everything a little easier.