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).
Posted in General | No Comments »
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.
Tags: dom, javascript, stupid
Posted in General | No Comments »
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.
Tags: hack, python, unicode
Posted in General | No Comments »
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.
Tags: django, select_related, stupid
Posted in General | 3 Comments »
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?
Tags: stupid
Posted in General | 2 Comments »
April 19th, 2009
When decoding, for instance, a variable-bitrate MP3, gstreamer reported durations are, to say the least, estimates. I’ve tried to get a better result in a few ways. First off, some files yield a duration tag, but even if you’re lucky and it is there, there are no guaranties about precision. After that I tried seeking to the end (GST_SEEK_END) of the stream and querying the position, which gstreamer didn’t like. Finally, routing the audio into a fakesink, waiting for the end of stream and then querying for the position gives the right result. It’s not the prettiest method, but it works.
This is a Python script that prints the duration of a media to stdout.
Tags: duration, gstreamer, hack, python
Posted in Computer Science | No Comments »
March 24th, 2009
is ugly, but
is nice! The solution: prefix \uparrow with \mathopen.
Tags: hack, LaTeX
Posted in General | No Comments »
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.
Tags: fosdem
Posted in General | 2 Comments »
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?
Tags: arbitrary
Posted in General | No Comments »
January 1st, 2009
Assign 1 to True and 0 to False. Now the minimum corresponds to “and” and maximum to “or”. If you give it a bit more though, less or equal to corresponds to implication. This is a lot more general than this specific case. Add .5 for a third value (eg. NULL) and it still yields natural results.
We can recognize the behaviour of minima and maxima in a lot of other things. Take for instance set inclusion as order with intersection as minimum and union as maximum. Actually, the link between general order and set inclusion is frequently made to then propose that “intersection of two set of cases” and “logical and” do look a lot alike.
This is just the tip of the huge iceberg. Order appears everywhere! Everywhere in Math. Everywhere in CS. And its just recognizing simple order I’ve demonstrated. Other useful concepts in order theory that I didn’t even touch are Galois Connections and formal concept analysis.
Oh, another example of an order are integers with bitwise or and bitwise and. It is left as an exercise to the reader when one integer is greater than another.
Interested? Buy an Introduction to Lattices and Order.
Tags: math, order
Posted in Maths | No Comments »
January 1st, 2009
Tags: ++
Posted in General | No Comments »
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).
Posted in General | No Comments »
December 21st, 2008
A Hashtable algorithm is a specific algorithm to implement key-value pair datastructure with efficient by-key look-ups using hashing of the keys. A hashtable contains a list of buckets. In a simple implementation, the i-th bucket, contains the key-value pairs in a list of which the key has a hash that is i modulo the amount of buckets. The hash-table would increase the amount of buckets if any bucket contains more than a fixed amount of pairs. This results in a constant-time look-up, but an insertion might invoke a expensive rebuild.
There are a few variations on Hash Tables. I’d like to share a really smart one: the Cuckoo Hashtable.
The Cuckoo hashtable expects two different hash-functions for the keys. Instead of storing a list of pairs in each bucket, the Cuckoo Hash table stores a single pair in each bucket. When inserting a pair, it is inserted in one of the two possible locations. If it happens to be occupied, the old pair is replaced. Then the replaced pair is inserted at its other possible location, potentially kicking out another pair. This step is repeated, until there is no displaced pair or a loop is detected. When a loop is detected, the hash-functions can be changed, if the buckets are for the most part empty -or- when the table is almost full, the amount of buckets can be increased. It can be shown that an insertion has a amortized constant time. (The buckets can be resized in-place, and each entry is repositioned as if it was displaced by another.)
Tags: algorithm, cuckoo, hash
Posted in Computer Science | No Comments »
November 26th, 2008
…and didn’t want to loose it if my control servers got shut down, I’d let every orphaned zombie randomly connect to hosts in a given IP range, and challenge them to give a preimage of a hardcoded hash. [ detail: add a salt to prevent replay attacks ]. With a sufficiently safe casu quo large range, it also might be helpfull to allow zombies to forward still orphan zombies.
Tags: botnet, hash, network
Posted in Computer Science | 4 Comments »
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.
Posted in General | No Comments »
September 19th, 2008
Tags: vim
Posted in General | No Comments »
August 31st, 2008
Yesterday we turned 20. I’ll miss that one.
Posted in General | No Comments »
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.
Tags: vacancy, wacken
Posted in General | No Comments »
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.
Tags: apple, iPhone, wifi
Posted in General | No Comments »
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)
Tags: apple, iPhone, iTunes, t-mobile
Posted in General | 2 Comments »