Authorizing a twitter-bot

So last night I ran into a small issue, how to authorize a twitter bot to use an application without stubbing together a website and logging in with the bot account?  The answer, this little script using twython: import twython app_key = raw_input("Your app key: ") app_secret = raw_input("Your app…

The Python "in" Operator – Theoretical vs Actual Time Complexity

Background Sometimes we may generate or retrieve a list, set or even dict when creating collection of things that we will be testing against.  Theoretically a set, frozenset or dictionary should be the fastest (and equivalent) forms of storage for this operation.  However, what I've found is that on some…

C-Style Unions And Python

So, you're creating a C Union (used to create a variant type) and writing it to a file, socket, etc and want to read that in Python. There are two ways to deal with this. Assume the following union definition in C typedef union { int i; unsigned int u;…

A Better AsyncTestCase for Python

If you need asynchronous support in python unit tests, there are a few possibilities.  A simple google search points you to a few packages, one being tornado.  Tornado's tornado.testing.AsyncTestCase seems straight-forward.  However it does have a shortcoming: it's not thread-safe.  Trying to use it with a thread will result in…

Automating Pylint with Gulp.js

Automating Pylint (and other Python Tasks) can be achieved with several viable python-based methods, but what if we used Gulp.js?  The following code snippet gathers runs Pylint on the set of python files defined by pySource. var gulp = require('gulp'), shell =  require('gulp-shell'); gulp.task("pylint", function() { log('Linting with pylint ->…