Category Archives: Utility Functions

Fast Peak Autocorrelation

So, I was at geekcon. It was a blast. There were many interesting projects, and I didn’t get to play with them all. I did get to work a bit on the Lunar Lander from last year, and this year … Continue reading

Posted in Algorithms, Math, Programming, Projects, Python, Utility Functions | Tagged , , , , , | Leave a comment

Easy Harvesting

Image by existentist. I’ve been doing a lot of harvesting (aka screen-scraping) lately. Fortunately, I don’t need forms automation, so I’m using urllib2 and not Mechanize like my friend Ron Reiter recommended. At first, when I wanted to get some … Continue reading

Posted in Programming, Python, Utility Functions | Tagged , , , | Leave a comment

Small Python Interactive Interface Trick

Not too long ago, I helped someone with some research work, and one of the research tools was also used from the Python interactive prompt. The interface used was handy enough for development: intuitive, readable, short, and useful. Still, for … Continue reading

Posted in Programming, Python, Research, Utility Functions | Tagged , , , | 9 Comments

Python Tidbits

Memory Leaks With the advent of the Python’s garbage collector, it would seem that Python programs should not leak memory. However, this is not always the case. With just a bit of circular references, you can find yourself leaking quite … Continue reading

Posted in Programming, Python, Utility Functions | Tagged , , , , | Leave a comment

Various Small Python Helpers

I’ve been working lately with arkon on various projects related to diStorm. One of these projects involved writing a solid Python API around an existing C API. This C API uses a lot of flags as arguments and return values … Continue reading

Posted in Programming, Python, Utility Functions | Tagged , , | 5 Comments

Solution for the Random Selection Challenge

A few days ago, I wrote up two small Python Challenges. Several people have presented solutions for the first challenge, and I also posted my solution in the comments there. However, the second challenge remained unsolved, and I will present … Continue reading

Posted in computer science, Math, Programming, Python, Statistics, Utility Functions | Tagged , , , , , , , , | Leave a comment

Harvesting with threadmap

From time to time, I need to harvest a website, or many websites. For example, to collect the data from IMDB to run the Pagerank algorithm. Other times I need to query some non-web servers. Usually in such cases, I … Continue reading

Posted in Programming, Python, Utility Functions | Tagged , , , , | 4 Comments

Small Python Challenge No. 2 – LRU Cache

Caching is easy. Consider the cache I used to optimize the recursive spring: class _NotInDict(object): pass _NotInDict = _NotInDict() def cached(func): cache = {} def wrapper_func(*args): prev_result = cache.get(args, _NotInDict) if prev_result is _NotInDict: result = func(*args) cache[args] = result … Continue reading

Posted in Algorithms, Challenges, computer science, Programming, Python, Utility Functions | Tagged , , | 2 Comments

Simple word lookup for crosswords and such…

I am swamped with university homework. I did manage to come up with some small somewhat useful utility. Do you know when you need a word that ends with a double letter and then an ‘n’? you would want to … Continue reading

Posted in Programming, Python, Utility Functions | Tagged , , , | Leave a comment

Small Python Utility Functions

While working with Gil Dabach on Distorm3, I found out that I’ve been missing a lot of utility functions. I’m going to write about some of them now. def classify_to_dict(seq, key_func): result = {} for item in seq: key = … Continue reading

Posted in Programming, Python, Utility Functions | Tagged | 3 Comments