Archive for the 'code-snippets' Category

A simple python tcp server
November 8, 2007

# a simple tcp server

import SocketServer

class EchoRequestHandler(SocketServer.BaseRequestHandler ):
def setup(self):
print self.client_address, ‘connected!’
self.request.send(’hi ‘ + str(self.client_address) + ‘\n’)

def handle(self):
data = ‘dummy’
[...]

HotKeys
September 16, 2007

jQuery Keyboard Shortcut Hooker Plugin is now called Hotkeys. Make sense, right? The script was tested on Linux, Windows, and MacOS, IE, Safari and Firefox.
The final result is relatively small file (121 lines of code). But do not let this fact misleading you by underestimating its value.
> See Live Demo  
Read more at Google Code [...]

Calc start date and end date of a given week.
July 16, 2007

from datetime import date, timedelta

def calc(year, week):
d = date(year,1,1)
d = d - timedelta(d.weekday())
dlt = timedelta(days = (week-1)*7)
return d + dlt, d + dlt + timedelta(days=6)

Numbers are passion, Python is fascinating, I am amused
July 16, 2007

The following 4 lines says it all:
x = 2
for y in range(2,24):
… x= x*x*y
… print x, ‘\n’
Watching the generated numbers running on the screen get me so high that I feel I can start writing poetry.
Try it for yourself