Per-host for Django projects

When working as part of a team on a Django project, it is often useful to have a per-host settings file. There are many ways to do this but the approach that I liked most is creating a file in each environment.

I’m often the only programmer on web projects, but even then I still find it helpful to have a file on my local host. In it I include things such as debug-related settings, test keys for the different API providers, a modified logger configuration and flags that turn off any added security measures.

As part of a team, this gives me the added benefit that each team member gets to use any local tools or configuration that they prefer while maintaining control over the production environment. Anything in that can apply globally gets promoted to I find this decreases any chances of politics or religious wars over tooling that programmers are famous for.

This is a typical snippet that I include in every file.

This allows me to override settings on a per-host basis and has minimal impact on performance. It also allows me to add any debug utilities, apps or middleware, to a running instance.

My file would look something like this.

As you can see, this snippet does a number of useful things. It turns on the debug flags. It sets the email backend to print emails to console instead of actually sending them out. It defines and configures a set of locally installed apps that help with development but shouldn’t be on the production server. It also sets the default database to use sqlite instead of whatever one is used in production(Postgres).

This technique will also offer some protection against mistakes such as forgetting to turn off your DEBUG flag before deploying to your production server. And will save you from feeling silly when you mass email your userbase with a test email. I, of course, have never done anything like that before. Ahem, you can thank me later…

Intercepting USSD calls in Android

Dialing a USSD code from a custom activity is straight forward using a DIAL or CALL intent, but listening to the returned result is not due to Android not having proper support for intercepting USSD calls within the platform, but partial though undocumented support exists within the native dialer application.

As a start, look at the PhoneUtils class in the Android source code. The link is for 4.0.3 but I believe this partial support has been present since 2.3.

Specifically, looking at line 217, an intent with the name “” is being composed. So what you need to do is implement your own service that responds to that intent. The service needs to be implemented according to the IExtendedNetworkService.aidl which is a part of the Android framework.

The aidl exposes several functions but the one we care about is the getUserMessage(text) function in that service. The text is the final value returned from the USSD call.


  • Since the service is binded on by PhoneUtils, then you need to start the service at phone boot up. It also means that any modification to the service will need a phone reboot.
  • Returning null from getUserMessage will suppress the dialer from showing the USSD result but there’s no way to completely hide the dialer.
  • You can also use the other functions to change the text shown while the call is in progress
  • This doesn’t seem to work on USSD prompts(menus), only on final results

Nothing explains code like a code sample, right? So I wrote a sample service and you can take a look at this link.

Inspiration for this post and code came from this Russian blog post.

Project: TaskIt

The TaskIt application aims to help you in your Getting things Done(GTD) approach and thus provides a task list or a ToDo list. When you organize your thoughts and put them down in your TaskIt list, you will get a much better view of your tasks.

This is a Work In Progress(WIP) and was done on my free time on weekends. I had a need for such an application, and i love Qt and i love Python, so i wanted to see how flexible their daemon spawn(PyQt) is. This was also an excuse to experiment with the all-powerful SQLAlchemy in a desktop application. I would appreciate any feedback and/or bugs, comments….you can use my email for that or the launchpad page. The application is released under the GPL. You can get the released application from here.

You can always access the latest source code from the project page at launchpad at

This application is implemented in Python(ver 2.5) with the Qt framework(ver 4.*) in the form of PyQt(ver 4.*) and it also uses SQLAlchemy(ver 4.0) as a gateway to the sqlite(ver 3) database and uses the famfam icon set. And thus you need these dependencies to run it.


To launch the application, just launch This application is still under development and thus you have to take care of a few things.

  • You cannot reorder tasks and categories.
  • There is no concept of priority of tasks.

In any case, you can always access the sqlite database directly(file called tasklist.db) and fix whatever you want just be careful not to mess with the relations between the categories and tasks. The source tarball also includes a makefile to regenerate the .ui files if you change them.

Project: Space Explorer(SpaceX)

I am a big fan of the Galactic Konquest game. It is similar to the risk board game, except it occurs in space and it may have different rules, i am not familiar with risk myself…ahem…

It is a part of the kdegames package and thus comes with some strings attached. People who don’t use kde need to get a part of kde to be able to play it, and users of “other” operating systems are just out of luck. I am Gnome user myself, and so at the beginning, i tried to get rid of the kde dependency and keep it to barebones QT, but i didn’t like the state of its source code. I also needed to port it to Qt4 if it was to be distributed on windows operating systems, because Qt4 is the first version that is available under the GPL on windows. That also turned out to be a complex task, so i decided to do a re-write instead.

I got busy with some commercial work before i was able to finish it. The game still needs about 3 or 4 hours before it is playable. The source code is available from here. It is a bz2 package of the bzr archive so that you can take a look at the history and changes.

The configuration dialog at the start of each new game.

The main game play screen. There are some graphic widgets that do not show up properly because of the dark color.

If you are interested in this game or would like to help me with its development, please contact with me and we will work together. I was thinking of porting this game away from C++ to minimize the entry barrier. I was thinking of Python, so let me know….

I also have some big plans for this game once i have some free time. Some plans are SVG graphics, network gameplay or internet gameplay, a smart AI, and perhaps some 3D work.

Project: DisplayShelf Modifications

The DisplayShelf’s original website is at and this is a quote from that website.

The DisplayShelf component demonstrates using a number of flex and flash concepts to provide a rich, templatable control to display a faux-3d view of a list of items. Its behavior is similar to the CoverFlow visualization added to iTunes in version 7.

The sample is broken into two pieces. The first, the TiltingPane component, takes any content and wraps it in a faux ‘3d’ effect, allowing you to tilt it from side to side. The second, the DisplayShelf component, uses the TiltingPane component to render a list of items along a virtual shelf, with the selected item pulled out for display.

Some of the concepts this sample illustrates: * matrix transformations * graphics API * masking * bitmap manipulation * templating * item renderers * the IList interface * implementing dataProviders * effective animation

This sample was the centerpiece from my MAX 2006 presentation, “Flex under the hood: A tour through the Flex architecture.”

I was contracted to implement the following modifications on the component: – Dynamic loading of images through a remote xml photos.xml file with the following schema <Images><Image title=”title” shortdesc=”foo bar” longdesc=”bla bla” javacall=”somefunction(id)” linkto=”url”>PHOTO_URL</Image></Images> The schema has the following definition:

  • Title: The items title (Title Text)
  • Shortdesc : A short overview/headline of the item
  • Longdesc : A longer text area to give bigger drill down description of the item. Optional.
  • Javacall : Specifies a Javascript call to make on focus of item. Optional.
  • LinkTo : Specifies a URL to link the “VISIT PAGE” hyperlink/button to. Optional.

– An info overlay appears above the displayshelf, appearing after 1 second of the item being in focus. The overlay will include:

  • Title Text
  • Short Description
  • A ‘Visit Page’ Link if the “linkto” attribute is defined in the xml file. When this link is clicked, the url is opened in the browser.
  • A ‘Read More’ Link if the “longdesc” attribute is defined in the xml file. When this link is clicked, the read more overlay is shown.

– A read more overlay that is optional. If the “longdesc” attribute is provided in the xml file, this overlay will show this information when “Read More” is clicked. The overlay will include:

  • Title Text
  • Long Description
  • A ‘Visit Page’ Link if the “linkto” attribute is defined in the xml file. When this link is clicked, the url is opened in the browser.
  • A ‘Go Back’ link. When this link is clicked, this overlay fades away.

– Both of the overlays are fade tweened in their animation. – The javacall function has to be in the form function(param1, param2….). And if it exists in the xml, upon focus, the function will subsequently be called with a parameter array. This functionality can be turned on and off through the boolean “calljs” variable passed through flashVars – Some small additional modifications to the code which don’t fall under any specific functionality as well as skinning.

To run it, you just need to compile the swf. And then define the location of the photos.xml file(you can name it something else if you want) and pass it in photosurl var in the flashvars in the html page. The photos.xml will need to reflect your environment. A sample of the xml file as well as the html page is provided in the archive. The tarball also includes an ant build file to make things easier.

The modifications are released under the same license as the original component.

Book Review: Banat Al-Riyad

Warning: This book is in Arabic.

This book tells the story of 4 girls, and their struggle in the Saudi society. Lamis, Komra, Michelle, and Sadim are 4 friends each from a different background and with a different personality but they all share a common struggle within the highly conservative Saudi society.

The kind of struggle that i am talking about is the simple “live your life as you see fit” experience that people who live in a western culture often take for granted. Living in a conservative society, and specifically within the Arab culture is quite a demanding lifestyle. Even more so within the Saudi community.

The fact that Saudi women have to cover their heads and bodies with a black garment whenever they go outside of the privacy of their homes might seem harsh and incomprehensible to some. But the life that they are forced to lead and the even more imposing restrictions even within the security of their own homes is even more incomprehensible.

The story goes on to describe how each girl goes through a different, yet similar, tale of seeking love, life and an overall achievement of one’s dreams. Each story ends differently and although all are full with sad tales and suffering, they all somehow reach a positive outcome.( i don’t want to ruin the book for you)

One story goes on about an arranged marriage and how it fails miserably to the detriment of the woman who believes that by following the path that her mother shows her, she would go on to achieve every Saudi girl’s dream….that of marrying a man and having kids….Some dream that is.

Another story describes a blossoming relationship that has to be lived in secret and how that secret, and again because of the overwhelming restrictions placed on men and women, leads to the destruction of the relationship.

Another story also tells us about the unusual quest of one of the girls to excel at her career(medicine) and the different experiences that this girl goes through because of this dream. The unusual part being that Saudi women in general should only look forward to marrying a God-fearing man with some money and having a bunch of kids…i do not personally share that view.

And And And…..You get the picture.

Overall, this book was a very interesting read. But being an Arab myself and knowing first hand about such do’s and don’t’s in our culture(which is no way near the Saudi restriction), the book probably didn’t have the proper effect on me. Don’t get me wrong, i think its a very good book. But…..I have no sympathy for such stories. I have always said that extreme restrictions will lead to extreme ideologies(it actually sounds better in Arabic). And we hear about such stories all the time(being closer to Saudi Arabia and it being the largest tourism source for my country, Lebanon).

I think that this is an excellent read that fits well in the “read before you go to sleep” list. But a word of caution. This book will probably never get translated because of the language used. The Saudi dialect and the English-Arabic words(writing the English pronunciation but in Arabic letters) make this a book somewhat harder to read. So if you find yourself wondering what a certain word means…this is probably the reason.

I give this book 3 stars out of 5.


Update: The book was translated but I haven’t read it in English.