You are currently browsing the archives for the Python category.

Posted on April 21, 2009 at 7:13 pm

Counting bloom filters in python and javascript

Continuing the theme of implementing simple datastructures in python and javascript, here’s a simple counting bloom filter implementation in python and javascript which I’d written for Tagz. I’d almost forgotten about this, until a thread today on compsci.reddit reminded me of it. With this implementation, you can build a bloom filter in python and add/remove/lookup elements. You [...]

Posted on April 11, 2009 at 9:07 am

Tries and Ternary Search Trees in Python and Javascript

There are a couple of places in which Tagz, where I needed efficient prefix matching. The most obvious way to do this is to use a Trie or a Ternary Search Tree. So, I ended up implementing both in Python. I’ve had this stuff lying around in my mercurial repo for Tagz for quite some [...]

Posted on December 12, 2008 at 4:59 am

Playing with Django Querysets

I use base36 for all most object ids in tagz. I previously used to manually convert all base36 values into integers before doing the lookups. Yesterday it dawned to me that I could subclass QuerySets and remove a lot of boilerplate code. The idea here is that I can do something like Model.objects.get(pk_base36=’2kk’) instead of something like [...]

Posted on November 4, 2008 at 12:00 pm

Looking for a Job

Due to various reasons beyond the scope of this blog, I’ve had to quit my current job as a Programming Specialist at Position2. So, if you’re looking for a python / django hacker in Bangalore (although telecommuting certainly is an option I’d consider), drop me a line.

Posted on October 1, 2008 at 8:20 pm

Merging Django querysets

This one’s pretty basic (from the docs) , but I end up using it all the times. Being able to “AND” and “OR” django querysets can really simplify a lot of code. Here’s an instance (a simplification of the setup I have in tagz). Lets start by defining 2 models. Now, lets say I want [...]

Posted on August 29, 2008 at 4:44 pm

Low level template file caching in Django

In one of my django projects, I use a lot of recursive template tags, which seem to cause quite a bit of slowdown while rendering them. I looked at the code in django.template.loaders.filesystem Looks like the template is reloaded from the filesystem every time the a template is loaded. This gets really bad with custom [...]

Posted on June 26, 2008 at 1:47 pm

Fun with mercurial precommit hooks

I use Mercurial for all my coding projects. Today I hit upon the idea of using mercurial precommit hooks to run django tests before committing. I didn’t really expect it to be so easy I use postgresql on the server, but I found that on win32, running tests with postgresql is excruciatingly slow. For comparison, [...]

Posted on May 31, 2008 at 2:16 pm

Building Python Extensions on Win32 with MS VC++ 2008 Express

These days, I’m mostly working on linux and I haven’t had to use the Microsoft dev tools for a long time. I’m using Vista on my new laptop. Yesterday, I had to install pycrypto from source on Windows. The only compiler I had was MinGW, which doesn’t quite cut it with distutils. I figured that [...]

Posted on May 28, 2008 at 11:53 am

Embedding a Python shell scripts

Everybody knows “import pdb; pdb.set_trace()”, that’s probably the first thing anyone would do when you’re trying to hunt for a bug or hit an exception (“pdb.pm()” ?). Its just as easy to embed IPython or a plain old Python shell in a python script. The IPython manual covers this in detail. Another way would be [...]

Posted on May 31, 2007 at 7:36 pm

Whats wrong with reduce ?

Of late, Among the Python crowd, I’ve seen that people generally dispise using map, filter and reduce. A friend was reviewing my code the other day and he’s like surprised with the number of maps with lambdas spewed across. I was reading a post on John Resig’s blog and I saw some comments by someone. [...]