Electricmonk

Ferry Boender

Programmer, DevOpper, Open Source enthusiast.

Blog

Category: python

gCountDown: Systray countdown timer for Linux

I needed an easy way to set timers on my desktop PC. All I really want is to set a countdown in hours, minutes and seconds, and have it alert me when that time has elapsed. I couldn’t find anything simple with some exceptions that wouldn’t compile (anymore) due to missing libs (which weren’t available […]

Redirect stdout and stderr to a logger in Python

I’m writing a daemon and needed a method of redirecting anything that gets sent to the standard out and standard error file descriptors (stdout and stderr) to a logging facility. I googled around a bit, but couldn’t find a satisfactory solution, so I came up with this. import logging import sys class StreamToLogger(object): “”” Fake […]

(Finite-) State Machines in practice

(The lastest version of this article is always available in from this location). 1. Introduction A (Finite-) State Machine is a method of determining output by reading input and switching the state of the machine (computer program). Depending on the type of State Machine (more on this later), the state of the machine is changed […]

Closures, and when they’re useful.

When is a closure useful? Before we start with why a closure is useful, we might first need to understand what exactly a closure is. First-class functions In order to understand what a closure is, we must realize that in many, if not most, languages we can not just call functions, but we can also […]

Simple function caching in Python

Python dynamic nature continues to astound me. I was working on a small library when I noted it did a lot of redundant IO calls. Now I’m not one for premature optimization, but a while ago I was thinking about writing a decorator or something that would wrap around functions and methods, and cache the […]

HIrcd – minimal IRC server in Python

I wrote a little IRC server in Python: HIrcd is a minimal, hacky implementation of an IRC server daemon written in Python in about 400 lines of code, including comments, etc. It is mostly useful as a testing tool or perhaps for building something like a private proxy on. Do NOT use it in any […]

Encodings in Python

There’s a whole slew of information regarding all kinds of encoding issues out there on the big bad Internet. Some deal with how unicode works, some with what UTF-8 is and how it relates to other encodings and some with how to transform from one encoding to another. All that theory is nice, but I’ve […]

Apache, FastCGI and Python

FastCGI is a hybrid solution to serving web applications written in a wide variety of programming languages. It sits somewhere between CGI, which spawns a new instance of the web application for each request, and the various web server modules (such as mod_php, mod_python and mod_wsgi) which take care of pre-spawning a pool of interpreters […]

Dependency resolving algorithm

Here’s a little explanation of a possible dependency resolution algorithm. I’ve made this as basic as possible, so it’s easy to understand. If you’re at home in (graph) algorithms, this post is probably not of much interest to you. Premise Suppose we have five objects which all depend on some of the other objects. The […]

Rant: Dicts that are not dicts

There’s something I have to get off my chest. I HATE it when things in Python pretend to be something they are not. I often use IPython to introspect things so I know how to use them. Lately, I’ve been running into more and more libraries which return things that pretend to be one thing, […]

The text of all posts on this blog, unless specificly mentioned otherwise, are licensed under this license.