Saturday, August 15, 2009

How to decode a URL using python

I was doing a task and i needed a function to decoded a url as a dictionary of parameters and its values,

since i used urllib.urlencode before i was sure that i will find urllib.decode method as well, but i didn't.

Here is the result of my search, to decode a url into dictionary of parameter and its values user the cgi module as the follwoing:



import cgi

import urllib

url = 'http://www.test.com/test?%s'

params = {'param1': 'value1', 'param2': 'value2'}

urlParams = urllib.urlencode(params)

url = url%urlParams

resultParams = dict(cgi.parse_qsl(url))

print result_params



Enjoy

Sunday, July 19, 2009

Notes on REST Architecture

REST stands for Representation State Transfer

the main characteristics of REST are:

  • Distributed Network of interlinked documents
  • Client-server architecture
  • Stateless Server
  • The concept of Resource and Resource Representation
the action of retrieving a resource must be Idempotent, the fact that you made the request should not change the contents of the resource.

From "Beginning Python 2005"

Wednesday, July 1, 2009

My trip to my hometown

I am traveling to my home city and while i am at the train i see the life of the way to the upper egypt and i wonder how ignorant i was, how much i dont know about my own country and the people who i share with them a religion , home and a future.

the thing that striks me is how different the life here from the crowded city of cairo, how peacefull the people are and how beautiful our upper egypt is.

Today i visited my grandparents grave and i got a feeling my words cannot help me explaining them, but one of the feelings is definitaly sadness, i was sad because the memories that suddenlly became like reality, i got the feeling that my grandfather have past away only yesterday and there is nothing compared to that feeling, those kind of feelings that makes even taking your bearth very defficult process.

and there were the part where i just sat there at this beautifull place outside the mosque, where the wheher cannot be better(the weather was one of the things that made me hisitate going on this trip).

Saturday, March 28, 2009

Google engineers takes python to the next level

Great news for all python fans, Google engineers are working on a project to create a Just In Time (JIT) compiler for python programming language to be used instead of the python virtual machine.
The project called Unladen Swallow and promises a five time faster python.
you can read more details about this great news here

Sunday, March 22, 2009

Linux Tips

How to take the output of a command and pass it as arguments to another command ?
  • using pips
  • using xargs: $ ls /bin/b& | xargs -t dpkg-query -S
How to watch commads:
  • $ watch -n 10 'ls -la'
  • $ watch -d 'ls -la'
Using bash history:
  • $ history
  • $ ! 33
  • $ ! !
  • $ ! ls:s/CF/1
Bash: the shell
there are two types of files holding the bash settings, startup files and initialization files
  • startup files: runs for any shell that is a login shell (/etc/profile/.bash_profile, .profile, and .bash_login)
  • initialization files: runs for interactively running shells (not shell scripts) (/etc/bash.bashrc, ~/.bashrc)

sudo:
  • every use of sudo gets logged in /var/log/secure