A simple python tcp server

 # 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'
        while data:
            data = self.request.recv(1024)
            self.request.send(data)
            if data.strip() == 'bye':
                return

    def finish(self):
        print self.client_address, 'disconnected!'
        self.request.send('bye ' + str(self.client_address) + '\n')

    #server host is a tuple ('host', port)
server = SocketServer.ThreadingTCPServer(('', 50008), EchoRequestHandler)
server.serve_forever()

HotKeys

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 and jQuery Plugin Repository


Calc start date and end date of a given week.

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

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