ronny.haryan.to

Icon

Print: $9.50 — Online: free

Build Your Own URL Shortening Service

Everyone seems to have their own favourite URL shortening service, TinyURL, is.gd, tr.im, pendek.in, and so on. Some even do more than just shorten URLs, e.g. tr.im can track stats.

It’s relatively easy to roll own your own URL shortening service once you know the magic behind it. I’m going to explain the basic idea so you can start rolling out your own.

UPDATE: check out django-shorturls, a Django app recently created by Simon Willison and Jacob Kaplan-Moss, it uses a similar base 62 approach.

Read the rest of this entry »

psycopg2 and 64-bit Apache on Leopard

The Apache httpd that comes with Mac OS X Leopard runs in 64-bit mode, so everything else that’s loaded, including mod_wsgi and psycopg2 must be able to run in 64-bit mode as well. Graham Dumpleton explained this behaviour in a post to the django-users mailing list.

Compiling psycopg2 using MacPorts as well as from the tarball would result in something like this when loaded from a web application that runs on Apache:

ImproperlyConfigured: Error loading psycopg2 module: dlopen(/Library/Python/2.5/site-packages/psycopg2/_psycopg.so, 2): no suitable image found.  Did find: /Library/Python/2.5/site-packages/psycopg2/_psycopg.so: no matching architecture in universal wrapper

So all I needed to do was force psycopg2 extension to be built for 64-bit as well as 32-bit. After extracting the latest psycopg2 source, do this instead:

LDFLAGS="-arch ppc -arch i386 -arch x86_64" CFLAGS="-arch ppc -arch i386 -arch x86_64" python setup.py build

Then sudo python setup.py install. After that, check the .so file, it should look something like this:

$ file /Library/Python/2.5/site-packages/psycopg2/_psycopg.so 
/Library/Python/2.5/site-packages/psycopg2/_psycopg.so: Mach-O universal binary with 3 architectures
/Library/Python/2.5/site-packages/psycopg2/_psycopg.so (for architecture i386): Mach-O bundle i386
/Library/Python/2.5/site-packages/psycopg2/_psycopg.so (for architecture ppc7400):      Mach-O bundle ppc
/Library/Python/2.5/site-packages/psycopg2/_psycopg.so (for architecture x86_64):       Mach-O 64-bit bundle x86_64

Don’t forget to restart Apache, and that should be it.

Update: It happened to PIL too, it was giving this error: The _imaging C module is not installed, so I had to do the same thing as above: LDFLAGS=... CFLAGS=... python setup.py build followed by sudo python setup.py install.

D-Bus Multimedia Keys Plugin for Quod Libet

Since upgrading my Ubuntu desktop to Feisty my multimedia keys stopped working when using Quod Libet, although they work fine with Rhythmbox and Totem. This is because in GNOME 2.18 that comes with Feisty, gnome-settings-daemon ‘grabs’ all multimedia keys preventing other applications to capture them. Multimedia key press events are now being broadcast via D-Bus. Therefore applications that need to listen to those events could subscribe to the proper D-Bus interface. Other GNOME apps like Rhythmbox and Totem had picked up the changes and had been adjusted accordingly. That’s why they still work in Feisty. But Quod Libet is not a GNOME application, so this new method of multimedia keys handling that is specific to GNOME should not be implemented inside the Quod Libet core. This is documented in bug #43464 in Launchpad.

Joe Wreschnig, Quod Libet’s author, suggested that this could be implemented as a plugin. After an email conversation with him, and seeing a patch posted to the bug in launchpad, I started writing the plugin last night. Now the multimedia keys work again in Quod Libet. The plugin can be downloaded from launchpad or from here (rename to dbusmmkey.py). Simply put this file in ~/.quodlibet/plugins/events/ and enable it in Quod Libet.

PS. Python is so much fun!

WP Yahoo! Smileys Plugin Hacking

I’ve spent most of my Good Friday holiday installing Priyadi’s im_smiley plugin. The install process itself was very quick and painless, but I found some bugs, and I wanted to have clickable smileys, and I had to figure out how to have live preview of the comment, so it took a while. The bugs were quickly ironed out by Priyadi. The live preview bit didn’t take very long to implement either.

The clickable smileys was not part of the original plugin, so I modified the plugin to provide that functionality. I notified Priyadi about my modifications, he quickly incorporated my changes and adjusted them to his code. He released version 4.0 of the plugin right away. :D

You can get the plugin from Priyadi’s im_smiley plugin, or from my local copy.

My .muttrc for Mutt

Yes, let’s make the RC day complete. Here’s my .muttrc for Mutt as well. This time it’s a bit different than before, because I split my original muttrc into several files. So here’s the complete set of the files:

I put everything in $HOME/.mutt/ except the .muttrc file. You also need your own $HOME/.mutt/aliases containing your personal address book.

About

Ronny Haryanto is a technology addict/chef wannabe living in beautiful Melbourne, Australia.

Read more…

Follow Me on Twitter

Follow @ronny on Twitter where I post much more often than my blog.