Welcome to Farhan’s personal blog

During the course of the day I encounter lots of challenges, few that take minutes to solve and others that take longer. My goal for this section is to keep track of these challenges and their solutions. I will turn the longer ones into articles, while the shorter ones will stay as blog entries. You can expect topics to range from very specific programming challenges to broader topics like life.

Below is a list of the recent blog entries. You can also browse the blog by using the tags on the right side, or if you know what you are looking for then you can use the search box at the top left.

Speeding up django's development server on Windows

I am very picky about my development environment and I need it to be just right, otherwise the fun part of programming disappears. I have a dedicated Linux server in my office that is sharing and serving the development files. This is a solid server, fast enough that django’s development server refreshes as soon as I save the files, even before I have switched to my browser; and that’s how I like it! :) Lately I have been on the road quite a bit so I have had to run the development environment on my tablet (when in Windows 7; runs excellent in Linux). The tablet has OK specs: 1.4GHz Core Duo with 2GB RAM and a 7200 RPM drive (generally the bottleneck). But for some reason django’s development server seems especially slow at serving the files. The refreshes after changes are OK, not fast, but OK. It is the media that it is very slow at serving (understandably so).

I did a lot of research on my options to speed this up. I am using the standard CPython distribution on Windows. I saw a lot of references to unladden-swallow, but there weren’t a lot of benchmarks to prove the speed gain yet. I realize that this is still under very heavy development, but the one benchmark that I found really excited me so I decided to give it a try. Unfortunately, after hunting for a number of source code packages necessary for compilation and still not succeeding I concluded that it wasn’t worth the time yet :| I decided to rule out pypy because of the possibility of compatibility issues, I wanted something that I could plug into the existing system. For some of my projects I am using external libraries, which might not work with pypy.

Anyways, my solution ended up involving Apache. Based on the console output of django’s dev server I had an idea that it was slow at serving multiple files. So I decided to serve the media, which generally is the majority of the files in a given view, using Apache and let django’s server deal only with the views. Microsoft’s IIS is also an option, but I had Apache setup for another project so I decided to use that. Below is a part of my dev_settings.py that makes this change.

1
2
3
4
5
6
7
8
9
import socket
# ...

# System specific dev settings.
if socket.gethostname() == "mystic":
	MEDIA_URL = 'http://localhost:8080/projectname_media/'
	SERVE_STATIC_FILES = False
else:
	SERVE_STATIC_FILES = True

With this new combination and using 127.0.0.1 instead of localhost now my dev environment on Windows is fast enough to keep things interesting.

0 comments | Read more

Two weeks ago when I came home after using the tablet in a car for a few hours I noticed that the screen won’t turn and that there was a lot of bend by the hinge. I have had this tablet for about three years and the warranty had recently expired. I knew getting it fixed from Lenovo would be expensive and probably more than I was willing to pay. Luckily, Lenovo publishes the hardware guide for most of their products so I downloaded X60’s hardware manual for reference and opened up the LCD to figure out what was wrong.

A very blurry picture of the broken hinge.

As you can see in the picture on the right, the left half of the hinge was broken. I didn’t blame Lenovo for it because I have used this tablet almost everyday, opening, closing and turning multiple times in a single day. The hardware manual was very helpful because it gave me the exact part number (which, as I found out, is also on almost every replaceable part in this laptop, a big plus!) and after about 20 minutes I knew that I could get a replacement part for less $50 (including shipping).

0 comments | Read more

SBC?

Haha, SBC! :)

SBC, what?

As a programmer I know sometimes this is what you want to say, but what can I say, we have to live with backwards compatibility even if it means twice as much work.

0 comments | Read more

Wake-on-LAN for WebOS (Palm Pre)

I recently published the Wake-on-LAN client for webOS (used by Palm Pre and Pixi) and finally got a chance to create a video showing how it works. You can see it below. I had to write a Java dbus service to accomplish this functionality so, unfortunately, this won’t be showing up in the Palm app catalog, but you can install it using Preware. For more information checkout the WoL project page.

0 comments | Read more

Windows not going to sleep?

Recently my laptop stopped going into sleep mode, which it used to do without any hesitation. I restarted because many times restarting takes care of minor issues, but that didn’t do it. Next try to get it to sleep resulted in the same behavior, the display would turn off, but the system would stay on. A quick look at the event viewer didn’t reveal any issues. A quick search online didn’t reveal much either. So, I was back on my own to solve this issue.

0 comments | Read more

In the past whenever applying to a job I have tried to go a step beyond what the employer might have requested. In a few cases the requirement was C++, so what better way to demonstrate your skills than writing a C++ program? After some thinking I decided that a C++ based resume would be a good sample. So, I ended up writing a program that renders my resume almost exactly as it would have been rendered by Microsoft Word. Instead of hard coding the complete resume I wrote a text rendering engine that reads an array of string and renders it on screen based on some simple rules.

To make it simple for the hiring manager to run this program I embedded the text in a string array so they can just pass the exe around without having to worry about sending multiple files. The program works just as well reading from a text file. Here is a quick screenshot of this program.

This program renders my resume just as Microsoft Word would have rendered it.

So, what extra steps have you taken to increase your chance of getting an interview?

0 comments | Read more

Migrating MySQL data to PostgreSQL

I just finished posting a new article about migrating a django application database from MySQL to PostgreSQL. This article is very technical and only covers the actual migration steps (i.e. does not explain why I made the move). Check it out if you are interested or curious.

Migrating MySQL data to PostgreSQL

0 comments | Read more

"device not managed" in Ubuntu Karmic 9.10

I just finished upgrading my laptop to Ubuntu 9.10 (Karmic Koala). After the upgrade finished I noticed that for my wireless card the Network Manger applet in gnome claimed “device not managed.” A quick search revealed that this had happened in the past. I had to set managed=true in /etc/NetworkManager/nm-system-settings.conf. Doing this again and restarting the network service didn’t seem to fix the issue. After a few minutes of looking around in /etc/init.d I saw another service (network-manager!) that needed to be restarted. In summary is here is what you need to do.

1. Edit /etc/NetworkManager/nm-system-settings.conf and set managed=true

Specifically change the 'managed’ under ifupdown…

1
2
[ifupdown]
managed=false

...to true.

1
2
[ifupdown]
managed=true

2. Restart networking and network-manager services.

You can always restart the computer, but where is the fun in that :) To get things to work without restarting, run the following commands.

1
2
sudo /etc/init.d/network-manager restart
sudo /etc/init.d/networking restart

3. Have fun!

0 comments | Read more