Category Archives: Python

Announcing Couch Crawler, a CouchDB search engine/crawler

Hi! So, for fun, I made couch-crawler, a search engine and crawler on top of the very excellent couchdb-lucene. I wanted to create a hackable search engine for my work intranet using modern tools. Lucene is great, but the Nutch search engine/crawler was kind of annoying to work with. I couldn’t figure out how to [...]

Tokyo Tyrant: The magic little database

I’ve been playing around with Tokyo Tyrant master-master replication and I have got to say that it is a magical little database. Here’s some sample code to configure two Tokyo Tyrant instances in master-master replication mode, as well as a script to show off some of Tyrant’s capabilities, including memcached protocol support.

#!/bin/bash
 
HOST=127.0.0.1
PORT=1978
SID=1
UPDATE_LOG_DIR=ulog/$SID
MASTER_HOST=127.0.0.1
MASTER_PORT=1979
 
mkdir -p $UPDATE_LOG_DIR
 
ttserver -host [...]

Ordered dicts in Python 3.1!

Hooray, at long last, they’ve added an ordered dict, appearing in Python 3.1 (and probably eventually backed ported to 2.7).

Determining image similarity

When I saw this question on stackoverflow asking about how to determine if an image is identical, it reminded me of my favorite class at JHU, Computer Vision. One of the things that I remember is that if you wanted to compute how similar two images are, you’d treat their pixels as vectors, normalize them, [...]

Pythonic lazy instantiation (singleton pattern)

Sometimes it’s useful to have global variables, like for config or database connections. However, you don’t want to introduce side effects when you import the module (with certain exceptions).
Normally to avoid this, you would wrap your global variables in functions, maybe memoizing the return value. For example:

def get_db():
db = getattr(get_db, ‘db’, [...]

Emergent

I recently published my pygame artificial life simulation: Emergent. Check it out. I’m not quite sure where to head with it so any suggestions are welcome.