Lenny Domnitser’s

⇙ Jump to content


This is a static archive of the domnit.org blog,
which Lenny Domnitser wrote between 2006 and 2009.

Did U2 Use Beer Bottles as Bells on “I Will Follow”?

According to a professor of mine, the glassy glockenspiel-like sound on “I Will Follow” is actually beer bottles filled to various levels with liquid. Intrigued, I searched for documentation of this, but couldn’t find any. None of the live clips I watched on YouTube have bells, and the music video doesn’t show the instrument. Supporting the bottles as bells hypothesis are the falling bottle sounds at 2:10.

Haha, I Lied (Python Photomosiac Edition)

When I said that I would release a Python photomosaic library and tool, I didn’t know that MoPy existed. It’s basically a feature-complete version of my code. Hell, MoPy was even one of the names I considered for my version. I’d have done the command line interface somewhat differently, but I totally lost motivation to fix up and release what’s essentially the same software.

I already did the good part, which was to explain the algorithm. Sorry, no code—use MoPy!

wget from Firefox

I use wget for big downloads because of its simplicity and reliability. Coupled with screen, it will keep working through a Firefox crash or even an X windows crash. I got tired of copying and pasting URLs into a terminal, so I wrote some glue code to make it work in two (or one) clicks.

First, save this tiny helper script to your computer and make it executable. Mine is named ~/bin/x-wget-url. This is for GNOME, so if you’re using KDE, Mac OS X, or something else, you’ll have to modify it. You can also make a similar batch script for Windows.

cd ~/Desktop
gnome-terminal --hide-menubar --title=wget -x screen wget -i $1

Next, open this setup link in Firefox. Firefox will ask you what to do with the file. Select “Open with”, browse to the script, check “Do this automatically”, and press OK.

Now that Firefox knows how to open wget as a helper, you can start rewriting links by prepending data:application/x-wget-url, to them. The easiest way is the wget next bookmarklet, available at my bookmarklets page. Usage: 1. click wget next. 2. click a link. That’s it.

Greasemonkey can also be used to automatically rewrite some links. I wrote a small script to download Revision3 videos with wget. Similar scripts can be written trivially.

Maybe when Firefox is more mature this won’t be necessary, but for now this setup makes the robust wget as convenient as downloading directly in the browser.

Going Through Old (and Newish) Notes

Tomboy make it really easy to take notes, but that means they build up, so here’s a few that I’m cleaning out. All of the code ones are in Python.

Note Notes on the note

Austerely simple


Pick one word.

def no_cache(app):
    def new_app(environ, start_response):
        def new_start_response(status, headers):
            start_response(status, headers + [('Cache-Control', 'no-cache')])
        return app(environ, new_start_response)
    return new_app

WSGI middleware to prevent caching

Python switch

def switch(expr1, rules, *args, **kwargs):
    '''Somewhat like switch in C


        switch('spam', {
            'eggs': func1,
            'spam': func2,
            97: func3
            switch.default: func4
        }, 4, 7, foo='bar')

        results in the call func2(4, 7, foo='bar')

    for expr2 in rules:
        if expr1 == expr2 or callable(expr2) and expr2(expr1):
            func = rules[expr2]
        func = rules[switch.default] # may raise KeyError. OK
    return func(*args, **kwargs)

switch.default = object()

White Gold

1 Goldschlager
3 Vodka
8 Milk
Optionally, 1 tsp. sugar per shot of vodka

Milk-based drinks aren’t very good, but I like the name I invented for this.

Crush whitespace

crush_whitespace = functools.partial(re.compile(r'\\s+').sub, (' ',))

WFNP/Minstrel Boy

At 17 minutes and 49 seconds, Minstrel Boy is hardly a quote-unquote radio song. That's why, in the spirit of college radio, I am requesting this mellow, yet epic closing track of the sophomore album from Joe Strummer and the Mescaleros, 2001's Global a Go-Go.

Usually reserved for an intimate hour listening through the whole album, Minstrel Boy is also appropriate at this hour, to lull New Paltz students to their peaceful beds, happy to be alive.

I called my friend's college radio show to request the least radio friendly song possible. He made me stick to a script.

Tiny Python Facebook library

As promised,


It needs Python and simplejson. Here’s how you use it:

>>> import tinyface
>>> app = tinyface.App('...', '...')
>>> session = app.rpc('auth.getSession', auth_token='...')
>>> app.rpc('users.getInfo', uids='8112822',
[{u'first_name': u'Lenny', u'uid': 8112822}]
>>> my_events = app.fql('''select name from event
                where eid in (select eid from event_member
                where uid = 8112822)''',

It just provides two methods, rpc and fql. The latter is a shortcut for FQL. However, all Facebook API calls, including FQL, can be made through rpc, which takes the method name and any parameters. method, api_key, v, call_id, format, and sig are put in automatically by the code, so the caller has to provide any parameters besides those.

Simple, huh? It’s BSD-licensed. You can use it as a module or just drop it into a script.

Facebook Friend Mosaic

I made an application that makes a photo mosaic from Facebook pictures. It uses your friends’ profile pictures as tiles, and the picture formed is your profile picture. Here’s an example:

(example mosaic)

Unfortunately, the app uses too many resources to feasibly release it to the public on my shared server. It works today, just behind a password wall. If you want to use it and I know you, just email me.

So what good is this private use only app? Well, some open source software is coming out of it:

  1. I didn’t need the big Python Facebook library, so I made a tiny one that’s suitable for just dropping in to your code. That’s coming later today. (It’s available now if you know where to look.)
  2. The mosaic code will probably be released next week. I must first make it more generic, and make some human interface, since it won’t be connected to the Facebook app anymore.

Making mosaics turned out to be quite simple. After building an index of tile images and their average colors, the big image is scanned section by section, and the closest-matching tile is pasted over that section. The only interesting question is what closest-matching means, given an average color for the section we are looking at and for each possible tile.

To compare two colors ((R1, G1, B1), (R2, G2, B2)) for closeness, I use the formula (R1R2)2 + (G1G2)2 + (B1B2)2.* Each channel difference is squared because it makes the number positive, and punishes bigger differences in a single channel, so a color which decently matches in all channels will be considered better than a color which matches very well in one channel but poorly in another. Lower numbers mean a better match, with 0 as the best, and 3·0xFF2 as the worst.

This formula was the first thing I tried, and it gave good results, so I didn’t mess with it.

* This mathematical notation is readable without having to think about it much, but the Python is more elegant. sum(difference ** 2 for difference in (channel[0] - channel[1] for channel in zip(rgb1, rgb2))) expresses the same formula if RGB is used, but it also works on any number of channels, so it can be used as-is with any color mode.

Capgun Coup Marketing Machine

Capgun Coup is the best new band, according to Jamie Presnall from Tilly and the Wall. They’re Conor Oberst’s current favorite, too. Well, Jamie and Conor are friends, and Tilly and the Wall and Capgun Coup are both signed to Conor’s label, so I decided not to take their word for it.

Indeed, the cross-promotional marketing mumbo-jumbo was full of lies. Where the bio says they “are not the most well-versed students of rock music,” I find traditional rock elements, especially on My Tears Cure Cancer, one of the 3 pre-release songs from their upcoming album, Brought to you by Nebraskafish. And it rocks so well.

So, while I’d normally be repulsed such an impertinent media push, I’ve already bought into Team Love Records, which puts out some of my favorite music, and these guys are good enough that I’ll listen and pass them on to you.

I look forward to the record.


Via Kottke, here’s a sweet moon time-lapse, from APOD. I like the way the thumbnail looks in my Firefox tab, like a cooler “page loading” icon. I have an idea.…

The Busy moon user stylesheet displays the phases of the moon while you wait for a web page to finish loading, and can be installed in either Stylish, Greasemonkey, or userChrome.css. To see what this looks like, just open a couple Firefox tabs and view the image. See the tiny version of the big picture swirling in the tab bar? That’s what every page will look like while it’s loading.

Hey, while the topic is user s___s, I have like a million Greasemonkey user scripts that I never write up on the blog, so check ‘em out.