Wednesday, June 24, 2009

Python string strip function..

I just realized a super blunder, I have committed all my life

url = 'abcdc.com'
print url.strip('.com')
Expect: abcdc
Resut: abcd

Instead try
url.rsplit('.com', 1)

strip function takes in an array of characters and chops any pattern of characters in the array.. :(

Friday, June 12, 2009

Lambda function and class in python

I had a hash with hash value an object. I wanted to sort by one of the elements (integer) of the class.. Here is neat way..

class cl:
def __init__(self, val):
self.val = val

arr = {'a' : cl(10), 'ab' : cl(75), 'bd' : cl(50)}

g = lambda (x, y): y.val
for (x, y) in sorted(arr.iteritems(), key = g):
print x + ' ' + str(y.val)

Wednesday, June 3, 2009

Mercurial on code.google

I played with mercurial on code.google.. Here are some simple instructions

a. Create the project in the interface
b. Create a local repository

hg clone https://USERNAME@PROJECT.googlecode.com/hg PROJECTDIR

When it prompts for a password, key-in the password available on
http://code.google.com/hosting/settings (Profile > Settings)

I created trunk directory and stored all the code.. (to allow branching).. This probably not mercurial way and is svnish..

c. I prefer to edit wiki through mercurial..

hg clone https://wiki.PROJECT.googlecode.com/hg wiki-PROJECTDIR