Monthly Archives: February 2009

Programmer Productivity Tips At Work

Some nice tips in an article that caught my attention, Most of the tips are general, but some are specifically suited to programmers/engineers in situations with long compile/simulation phases (compiling is the act of building an executable, simulation is the act of running it to completion).

Click here to start reading

Installing Python & PyGTK on Mac OsX

Recently i have been asked to develop an application that will work on Linux, and Mac os, so i started developing it on my Ubuntu, i chosed Python as the programming language and PyGTK as the GUI for it.

The application worked fine on my Ubuntu, but when i moved it to Mac OSx (Leopard), i had a problem importing the PyGTK module and the program GUI didn’t run. so i tried to install PyGTK from sources with all its dependencies, but after spending a day doing so i ended up with many errors in compiling the dependencies and finding them.

after some search i found out that i can do this using MacPorts.

so here is the steps i followed :

– Install X11

– Install Xcode tools

– Install MacPorts

– Make sure the paths are configured in your shell profile

– Restart your shell, and follow the next commands :

1- Install Python

sudo port -v install python25

2- Install Python select

sudo port -v install python_select

3- Activate our installed python version

sudo python_select python25

4- Install pygtk

sudo port -v install py25-gtk

5- Install some gnome themes and engines

sudo port -v install gnome-themes
sudo port -v install gtk-nodoka-engine
sudo port -v install gtk-smooth-engine
sudo port -v install gtk2-aurora
sudo port -v install gtk2-clearlooks
sudo port -v install gtk2-extra
sudo port -v install gtk2-industrial
sudo port -v install gtk2-murrine

6- Install theme switch

sudo port -v install gtk-theme-switch

7- Select which theme to be used by your applications by running the theme switch


Now you can have the applications you develop using python and pygtk running smoothly on mac os leopard.

How to enable Remote Desktop on Ubuntu from Terminal

The remote desktop function in ubuntu is a nice handy one, to enable it from terminal
first ssh to the server you wanna remote desktop, then install tightvncserver

sudo apt-get install tightvncserver

then run it


it will ask you to set a password for using this option and it will return the x desktop id.
Now go to Applications -> Internet ->Remote Desktop Viewer, and enter the address of the machine followed by the x desktop id like this :


where 1 is the x server id.


here is a good comparison between remote desktop apps.
remote desktop software

Install Yum on RHEL4

In my company they purchased some software from Autodesk that comes on Redhat Enterprise 4, i needed to install some packages on the system for the use of some internal applications, instead of installing packages and all the dependencies, i though using automatic installer like yum would be better, below is the steps to have yum installed on your RHEL4 machine :

1. Install rhel4
2. Download Yum rpm package


3. Install the package

rpm -Uvh yum-2.0.5-1.noarch.rpm

4. Edit repositories location

nano /etc/yum.conf

Change the baseurl in [base] to$basearch/

Change the baseurl in [updates] to$basearch/

5- Install the full yum with all its dependencies.

yum install yum

Build MySQL insert Query from Array that contains fields and values

The following function takes table name, and array where its keys are the table fields and it’s values are the values to insert in each field, it constructs the MySQL Query based on the input and executes it to insert the data.

function insertRow($table_name, $input_array){
	$link = mysql_connect(SERVER, USER, PASS);
	mysql_select_db(DATABASE, $link);
	$SQL = "INSERT INTO $table_name ";
	$fields = "(";
	$values = "(";
	foreach ($input_array as $k => $v) {
		$fields .= "`$k` ,";
		$values .= "'$v' ,";
	$fields .="#";
	$values .="#";
	$fields = explode(",#", $fields);
	$fields = $fields[0];
	$values = explode(",#", $values);
	$values = $values[0];
	$fields .= ")";
	$values .= ")";
	$SQL .= $fields . " VALUES " . $values;

List array Recursively in PHP

Code :

function listArrayRecursive($array_name, $ident = 0){
	if (is_array($array_name)){
		foreach ($array_name as $k => $v){
			if (is_array($v)){
				for ($i=0; $i < $ident * 10; $i++){ echo " "; }
				echo $k . " : " . "
"; listArrayRecursive($v, $ident + 1); }else{ for ($i=0; $i < $ident * 10; $i++){ echo " "; } echo $k . " : " . $v . "
"; } } }else{ echo "Variable = " . $array_name; } }

Usage :

$ages = array(
				"ahmed" => "25",
				"mohamed" => "35",
				"group" => array("omar" => "15", "abdalla" => "20", "sub group" => array("john" => "10", "peter" => "20")));

Output will be printed array in indented way.

Converting bin image to iso on Ubuntu

Well, first you have to install bchunk

sudo apt-get install bchunk

then use the command as following to convert the image

bchunk image.bin image.cue image.iso

and the bin image will be converted to iso one in the same folder.

ZendCasts – Free Zend Framework Screencasts

A really good Zend Framework Resource that has been posted in the ZF mailing lists couple of days ago.

very usefull