Archive for the ‘General’ Category

PijsMarietje

Tuesday, June 30th, 2009

At the faculty for sciences there are canteens for students. In each of these, there’s sound equipment connected to linux boxes. On each of those linux boxes, we run a music-request-server called Marietje. I just finished writing a front-end in Javascript. It wasn’t a pain. As instead, the use of jQuery was a bliss.

The frontend for one of those boxes and the source code (see the ajax folder).

Damned DOM (1)

Monday, June 22nd, 2009

When I wanted to react to any changes to a input textbox immediately, my first instrinct was to use onChange. onChange, however, is called when the input loses focus. onKeyPress then? Isn’t called on backspaces. onKeyDown, maybe? It does get called, but the effect of the keystroke isn’t yet applied, for the return value determines whether it that is done in the first place. (Same story for onKeyPress by the way.) onKeyUp does work a bit, except if someone is holding down a single key, for a while.

The solution: hook onKeyUp and use setTimeout with a timeout of 0. Yugh. I hate DOM.

Big Fat Disclaimer: I actually tested this only on one browser.

Unicode to ASCII (1)

Friday, June 19th, 2009

When I want to generate usernames from real names, which can contain non-ascii characters, you can’t simply ignore the unicode characters. For instance, danielle@blaat.org is the right e-mail address for Daniëlle, danille@blaat.org isn’t.

There’s trick. Unicode has got a single code for ë itself, but it has also got a code which (simplified) adds ¨ on top of the previous character. The unicode standard defines a normal form in which (at least) all such characters, which can be, are represented using such modifiers. If you then simply ignore the non-ascii representable codes, you’ll get the desired result.

In python: unicodedata.normalize('NFKD', txt).encode('ASCII', 'ignore').

However, this isn’t the right solution. For instance, in german, one prefers ue as a replacement of ü over u.

Django annoyances: no reverse select_related

Saturday, May 30th, 2009

Consider

for page in Page.objects.all():
  print page.title
  for comment in page.comments.all():
    print comment
.

There will be a single query to fetch all pages, but there will be for every page another query to fetch its comments. Luckily, Django has got a nice trick up its sleave: select_related. Would I use instead of Page.objects.all(), Page.objects.select_related('comments').all() then Django will use a single joined query to prefetch comments for each page.

However, Django’s select_related only supports forward one-to-many references. No many-to-many; certainly no reverce many-to-many; no reverse one-to-many and no, not even reverse one-to-one (yet). A developer claims it’s impossible (which is bullshit), another asks for patches, which means he doesn’t care doing it himself.

It’s quite easy to manually code around the missing reverse select_related, but it takes too many ugly lines compared to the single word it could’ve been.

Javascript’s stupid Date constructor

Wednesday, April 29th, 2009

new Date(2009, 1, 1) represents the first of February 2009. Not the second of February nor the first of January. Why this stupidity?

Spacing up- and downarrow properly for up- and downsets

Tuesday, March 24th, 2009

f(\uparrow x) is ugly, but f(\left\uparrow x\right.) is nice! The solution: prefix \uparrow with \mathopen.

Fosdem (3)

Friday, February 6th, 2009

In a few hours I’ll travel the short distance to Bruxelles to visit Fosdem. Once again I’m pretty excited :) . Lets hope this time the pink elephants of the Delirium Cafe don’t crush me. If you’re also going, drop me a comment.

Timestamp 1234567890

Thursday, January 29th, 2009

It’s soon. The 14th of februari, 00:31:30 (Europe/Amsterdam). Will the world end? Will ancient libc code giggle and break?

2009

Thursday, January 1st, 2009

Happy Newyear!

On-demand singleton for Python

Saturday, December 27th, 2008

Some singletons eat slightly more resources, than you want to give them for free. For instance, if you have a home-brew threadpool singleton, you don’t want it to create its threads if you are not going to use it. The solution: a simple function that creates a stub which proxies attribute access to an ad-hoc created instance.

Usage: create_ondemand_singleton('mylibrary.Threadpool', MyThreadPoolClass).

Music Animation Machine

Friday, October 10th, 2008

The sound and performance really aren’t that good, but the visual connection is so powerful:

Bach’s little fuge on a Music Animation Machine.

Vim Essentials

Friday, September 19th, 2008

Vim Essentials. Usefull.

20

Sunday, August 31st, 2008

Yesterday we turned 20. I’ll miss that one.

Wacken (2)

Saturday, July 26th, 2008

Tomorrow morning, way too early, I’ll be leaving for the picturesque town of Wacken in the north of Germany to attend the Wacken Open Air festival. I’ll probably be back the third of august and recovered the fourth.

iPhone WiFi weirdness

Tuesday, July 22nd, 2008

I’m having trouble with the wireless on my 3G iPhone. Either an action works perfectly (for instance downloading e-mail or visiting a website), or it will just time-out. I just jailbroke it and installed sshd. ssh-ing to my it via 3G miraculously works perfectly. However, when connecting to it via WiFi it’ll simply refuse data. That is, until you let the iPhone try to get data itself by for instance visiting a website. Then suddenly the ssh packets come through again. In the background (with screen) I’m running a very frequent ping to my local gateway which makes ssh work perfectly again via WiFi. A very unsatisfying hack.

It seems like an aggressive power safe on the WiFi.

iPhone (0)

Friday, July 18th, 2008

On the day of release, I bought an iPhone. We all know the great features; thus let’s talk about the annoyances.

It crashes and gets sluggish a lot. Especially Safari crashes a lot and the contact list at one moment took 10 seconds to get responsive. Over time random crashes in all applications appeared. Rebooting it, actually, seems to have solved it (for now).

Wifi is unreliable. Sitting right next to the router it’s still a game of chance whether it will load a website properly or just time-out. This often leaves me disabling Wifi, and using HSDPA instead (which is our 3G), which has a terrible coverage. Outside reception is great, but even inside a building near a window, it only shows one or two “pips”. This again, often leaves me disabling 3G in favor of the (slower) but the more reliable GRPS (?).

I use iTunes on Windows in VMWare to sync my iPhone, which works great for the music. For the other stuff, like contacts and photos it just does not work. Syncing with google contacts or the windows address book just doesn’t work on windows. There isn’t even any support for calendar syncing for windows. I still have to look intro a free exchange compatible server. (Anyone?)

T-Mobile in the Netherlands seems to have trouble with the administration of all new subscriptions. Billing information and visual voicemail still don’t work.

(Nevertheless, it’s a great toy)

PyX

Tuesday, July 8th, 2008

The software I use to render those great graphs might be of interest to some. Instead of using a clumsy GUI or an inflexible graph language, I use a Python library called PyX which is able to generate beautiful graphs. At its core it’s a generator for TeX, and rendering graphs is just one thing it does well!

Take a look at the examples and convince yourself!

find: invalid predicate `-delete'

Sunday, June 29th, 2008

Check for a stray version of find in /bin.

“waiting for x server to begin accepting connections”

Sunday, June 29th, 2008

Try DisallowTCP = false under [Security] in /etc/X11/Sessions/Gnome/custom.conf or similar for other window managers. Obviously this isn’t a very desirable solution, emerge --emptytree gnome might do the trick too.

(and obviously this might be just one of the many underlying causes for the very generic symptom of X not accepting connections)

cyv: syncing git and svn

Monday, May 26th, 2008

For codeyard I’m developing cyv, which is a (still quite specific) util (written in Python!) to keep svn and git repo’s in sync. On the serverside, at least. First, let me explain what exactly is synced.

When someone commits to a svn repo, the git repo is synced with git-svn. You can just clone the git repo and git pull instead of having to use git-svn yourself.

When pushing commits to the git repo on a branch that came from the svn repo, the commits are git-svn dcommit-ed. If it fails (svn doesn’t do merges that well), it’ll revert the updates and will receive the successful part of the dcommit on the next post-commit triggered fetch from the svn repo. The user will have to git-pull and fix the commits locally: the git manner.

If pushes don’t involve the svn backed branches, it won’t have any unusual side-effects. This allows for pushing and pulling of topic-branches separate from svn and pushing them, when mature enough, into subversion without ever having to hassle (as much) with git-svn.

An obvious huge advantage is that a git-clone of the git repo is a hell of a lot faster than a git svn clone. A second big advantage is that someone can choose to either use git or svn himself while not mutually excluding the other. This is of special concern to codeyard, where projects should be accessible to everyone: beginners and advanced. If instead we offered fully separated git repositories, the projects that prefer git would become inaccessible for most. And if we wouldn’t offer git repos, people would set them up themselves elsewhere, for they really don’t want to bother themselves with git-svn.

cyv contains some neat features. One I want to highlight is the cyv-layout file, you can place in the root of the svn repo. It tells cyv how the repository is laid out. Eg:

trunk:trunk
branches/*: branches/*
tags/*: releases/*
some-git-branch: some/path/in/the/svn/repo

Another one is a wrapper around git-shell to have per repository permissions for different users depending on their ssh pub key.

To reiterate, cyv is still quite specific to the needs of codeyard. (If you’re a codeyard participant: be patient, it’ll be up mid june). However, if you’re interested, I’ll be glad to hear from you.