Auto restarting python application

This is a cool sample on how to write an automatic self-restarting python application after a timeout, of course you can modify this application to be much more sophisticated so it can close all open files before restarting or restarting based on a signal (SIGHUP maybe?) or whatever you like

#!/usr/bin/env python

import os, sys, time

def main():
	print "AutoRes is starting"
	executable = sys.executable
	args = sys.argv[:]
	args.insert(0, sys.executable)

	time.sleep(1)
	print "Respawning"
	os.execvp(executable, args)

if __name__ == "__main__":
	main()

Building VirtualBox on Mac OS X Lion with Python Bindings

After building VirtualBox with VNC support in my previous post I discovered two problems with that installation (VirtualBox 4.1.2 on Mac OS X Lion 10.7):

  1. SDK was not installed by default, import vboxapi from python failed.
  2. VBox Python bindings were built for python 2.6 and segfaults on python 2.7

I contacted some guys on #vbox-dev on IRC and it what happened is that VirtualBox 4.1.2 was not built for Lion and all build scripts are configured for 10.6. So, I decided to hack my way around for the second time to fix the two issues.

To cut the very long story short, you need to create your own port local repository like how I described in that post and remove the virtualbox directory inside emulators/ and replace it with the patched port

Steps to do download and extract are:
$ cd ~/ports/emulators
$ curl -O "http://ahmedsoliman.com/myspace/patches/virtualbox-vnc-lion.tar.gz"
$ tar vxzf virtualbox-vnc-lion.tar.gz
The you should just try to install virtualbox again:
$ sudo port install virtualbox +vnc +vde2
After installation you should be able immediately to use the Python APIs, open iPython and try the following:
import vboxapi
mgr = vboxapi.VirtualBoxManager(None, None)

If this code succeeded without throwing any exceptions then you should be really happy :)

I’ve also created a relevant ticket on MacPorts for that 31328

Building VirtualBox on Mac OS X with VNC Support

I’ve been using VirtualBox for months for several reasons and recently I’ve been forced to use only the free version of vbox (without the Extensions Pack), which doesn’t include the sweet bits of VRDP server among other things. I wanted to boot my virtual machines headless and access it using VNC which doesn’t come by default in Oracle’s builds of VirtualBox, so I decided to roll my own build.

VirtualBox is available on MacPorts but doesn’t have VNC variant yet, unless my contribution to MacPorts is accepted.

First steps

I searched for a VirtualBox port and I was surprised to find one, but I wasn’t quite happy with it, because it doesn’t build VirtualBox with VNC support, so I had to hack my way around. I wanted to implement that cleanly by adding a new port variant +vnc to that port.

The following steps will help you do the same; I’ve tested that on Mac OS X Lion 10.7 64bit but should work exactly the same on Snow Leopard 10.6 too. Continue reading →

The pain in the web application development frameworks around

I’ve been working on a big project for more than a year now and during that year I’ve played with many web development frameworks with different approaches to tackle modern developer problems. Honestly, I’ve been impressed with some of the frameworks on how simple it’s designed and the elegance in their usability. I even wrote some articles about that. But that didn’t last long!

In any web development project, things start out cleanly organized and well-designed, and by adding more features, functionality, code, templates, and javascript, the application becomes very painful to maintain. Applying modularity concepts become harder, following good design rules become impossible, every piece of the web page is conditional. It’s simply a mess!

I’m still trying to figure out the best way to split a project into smaller pieces to maintain its tidiness, cleanness, and maintainability. Out of my experience, I can list some of the issues I’ve seen inherent in all of the frameworks I’ve used so far: Continue reading →

What if apple created a search engine?

What would happen if apple was to create a search engine?

  • They would call it iSearch
  • Steve jobs would come and say that they have “Reinvented the Internet”, iSearch — it changed everything!
  • Websites have to go through an approval process to be included in their search results
  • iSearch won’t index any website containing Adobe Flash
  • A yearly subscription will be required to include your website in their search results
  • They will build an API for their search engine and the whole internet has to use it in order to integrate with the search engine
  • Websites must be optimized for iOS to be indexed
  • Apple would ship a hardware search device that uses iSearch service
  • Any website promoting Microsoft cannot – for technical reasons – be included in their search engine index

What do you have in mind for the new iSearch? :)