skip to main bit
a man slumped on his desk, from 'The Sleep of Reason Produces
      Monsters'

Oblomovka

Currently:

Archive for the ‘Hacks’ Category

2009-03-24

An Army of Adas

I gave up picking just one woman in tech who has inspired me over the years. I certainly knew that I couldn’t list them all. Here’s a roughly chronological list, which breaks down at the end when I realise that there could be no end.

I worked a Saturday job as a teenager at an IBM dealership when I was around thirteen. The first professional programmer I’d ever met worked there. She was incredibly smart and calm, and I remember being very impressed that you could actually make a living wage coding, instead of having to hide away in your bedroom hacking up ZX Spectrum platform games until somebody mystically gave you a Jaguar.

To save time, I will now skip a little arbitrarily (hello, Verity Stob!) across a few decades.

Out of my entire generation of Net-inspired London geeks in the Nineties, Pouneh Mortazavi was the only with enough initiative to do what everybody else dreamed of: she upped sticks to San Francisco alone. First she worked at Wired, holding together their databases; thereafter she started the Flaming Lotus Girls. She was always like some George Washington of a self-collected militia, marshalling and deploying technology and resources, cajolling and inspiring.

My ex-wife, Quinn Norton, has a aircraft-carrier full of skills and virtues, but if I had to pick a technological trait I admire most in her, it would be her ability to see its historical context, as well as extropolate it into the far future (and also her Perl coding style, which is the weirdest damn thing I ever did see).

Leslie Harpold simultaneously drove up the standards of web design, usability, and common human decency online. She’s still missed.

Annalee Newitz and I worked at EFF, and shared a career in writing 1000 word pieces on 1000 year topics, before she finally ran off to join the io9 intergalactic circus and exploration unit. She’s the embodiment to me of the one of the sublime joys of technology: jumping into the deep-end with just a laptop and a head filled with implications, and asking smart questions until you know as much as the expert will admit.

Cindy Cohn, legal director, and Shari Steele, executive director, of the EFF: I simply can’t list how much you owe those two people — but free crypto, and a censorship-free US Internet is probably a good start.

Suw Charman-Anderson, the creator of Ada Lovelace Day deserves a place on this list just for that, but she’s takes her place here because of her work binding technology and civil liberties together as the co-founder of the Open Rights Group.

I suspect Valerie Aurora will be on many people’s Ada Lovelace Day lists. A kernel hacker who can write, and whose writing can make me laugh out loud or smack my head in revelation.

Liz Henry wields technology as it should be: a fire to protect what’s right, and a blast of fresh air to winnow out what’s wrong. I’ve never seen any quite so able to pounce on new tech and bring it swiftly to bear on a societal problem, as well as explain its uses to those who might otherwise be bypassed by this revolution.

Becky Hogge was ORG’s second executive director, and another forger of ideas. Astoundingly good at herding other geeks, tech wonks, and MPs into spaces where they could all understand each other.

I get far too much attention for doing one single lousy talk about “life hacking”, whereas Gina Trapani deseves all of the credit for turning a dumb idea into a a brilliant, long-lived work of real usefulness — and for cranking out the code.

On the same note, butshesagirl’s Getting Things Done application, Tracks, got me through some tough times. I admire anyone whose managed to keep an open source project on course, but I was particularly impressed by bsag’s skills. I watched and I hope learned.

And now no time to talk about the community chops of Cait Hurley, Rachel Chalmers’ piercing analysis, Rebecca Mackinnon’s work at connecting the world, Sara Winge’s genius at O’Reilly, Anno Mitchell’s sardonic Web 2.0 charisma, Strata Chalup’s sysadmin and southbay knowledge, Kass Schmitt sailor and LISPer, Silona Bonewald’s politech savvy, Sumana Harihareswara’s geek-management hybridism, Ana Marie Cox’s snark, Cherie Matrix’s cultural vortex, Elly Millican’s web aesthetic, Wendy Grossman’s sceptical optimism, Desiree Miloshevic’s globe-trotting ICANNoclasm, the piercing tech analysis of Susan Crawford (now working at the Whitehouse!), Sarah Deutsch, Kim Plowright, Paula Le Dieu, Charlie Jane Anders, Violet Berlin, Biella Coleman, Alice Taylor, Sophie Wilson who designed my entire teenage life…

These people make the world my daughter, Ada, lives in. I’m honored she has such shoulders to climb.

This was posted as part of the Ada Lovelace Day project; if you’d like to read more, I enjoyed Liz and butshesagirl’s entries, spent a long time thinking about this sad and all too typical story, and saved the story of En-hedu-Ana, mapper of the stars, for Ada’s next storytime:

The true woman who possesses exceeding wisdom,

She consults [employs] a tablet of lapis lazuli

She gives advice to all lands…

She measures off the heavens,

She places the measuring-cords on the earth.

2008-11-02

actual android hacking

Just to show that “disappointing” in my previous posts isn’t some euphemism for “die, impure heathens!”, I’ve been continuing to hack on my G1. Honestly, even if it is an impure love, I’m loving both the phone itself and the application environment. Its integration with the Eclipse IDE even managed to draw me away from Vim. You see how its corruption burns into my soul?

Anyway, for your delectation for Hello, World style programming, and also because Liz wanted it, here’s an Android application I threw together that displays an arrow that (should) always point north (it’s not very accurate, but what do you expect from a $200 compass?) (Source etc for Android Compass.)

Things I like about the SDK: it’s well-documented, and when it isn’t, you have all the source to read. I can’t overemphasise how much of a relief this is. I haven’t coded in Java in literally decades, but with enough code examples I got into the swing (ha, ancient java funny) of it fairly quickly, and also I suspect picked up bits of the Android house style.

The community is a little big fractured — I sense there was a lot of early excitement when the first SDK came out, but a lot of those developers wandered off leaving too many ghost sites). Still, there is now a lot of Android hacking going on in public, and the IRC channel remains very informative (when I wandered off into implementing something with SurfaceView instead of just plain View and then wondered why my onDraw method didn’t work, they quickly put me to rights: you don’t use onDraw with SurfaceView, and you probably don’t need SurfaceView to begin with.)

The tools to interact with the phone seem very mature to my have-not-worked-with-embedded-systems-for-a-decade eyes. I found logs where I wanted to find them (in the IDE, and by typing adb logcat). I didn’t get the sense that Linux was a stepsister to the Windows and MacOS dev environment (and I hope that they do okay by comparison also). The emulator is a godsend, and well-integrated: when I didn’t have the phone plugged in, my code ran in the emulator. When I did, it ran on my phone. Things worked first time. I had fun, and had something to show off on my phone in an evening.

(Two gotchas that I hit when trying to produce this blog entry. I installed the java6-sun packages to run Eclipse and the SDK tools, but you have to actually select it to run rather than the openjdk on my Intrepid Ubuntu setup. Use sudo update-alternatives --config java to pick between the two. Eclipse actually ran fine under the openjdk, but Android’s ddms program complained a little about a GNOME Accessibility Bridge until I switched.

If you don’t want to use Sun’s Java, commenting out the single line assistive_technologies=org.GNOME.Accessibility.JavaBridge in /etc/java-6-openjdk/accessibility.properties also lets you run ddms.

And when you’re signing your Android package (using these Germanic instructions), it turns out that you should sign the apk file in your bin directory, not the one that Eclipse handily offers to export for you. Thanks to toediggety for that obscure bug. You see? Fun!

2008-10-11

python class Culture:

Every Friday at EFF, we have a Python class, where anyone in the org (and a few friends from outside) join up to learn a little Python, talk about coding and share what they’ve learnt. There’s a good mix of seasoned python hackers, coders who don’t know much python, casual programmers, and people for whom this is their first experience of programming.

The part i enjoy the most (apart from congratulating myself for reaching a level of maturity that means I don’t go I KNOW I KNOW whenever i know the answer) is the material that isn’t about the technicalities of programming, but of the culture. We often discuss, for instance, about the most aesthetically pleasing way of writing code. Watching smart coders attempt to verbalise those instincts is fascinating, especially when the instincts begin to spread through the group.

To give an example, we’ve been coding up a Python version of Conway’s Game of Life. We all spent a fair bit of time discussing that niggling problem with counting up how many neighbours a cell has. Do you do it “manually”:

neighbours = cell(x-1, y-1) + cell(x, y-1) + cell(x+1, y-1) \
+ cell(x-1, y) + cell(x+1, y-1)  \
+ cell(x-1, y+1) + cell(x, y+1) + cell(x+1, y+1)

or iteratively:

for xi in [-1,0,1]:
  for yi in [-1,0,1]:
      if (xi or yi):
           neighbour = neighbout + cell(x+xi, y+yi)

I think most coders would end up doing the first, but they would feel a bit dirty doing it, just as I always feel a bit dirty when I have x and y as attributes, instead of being able to treat them as different aspects of the same thing. It’s the right instinct to try and generalise, and it was fun seeing starter programmers expressing their mild discomfort.

After we’d got Life to work, Seth rewarded us by showing Golly, which is a great cross-platform Life simulator with many pre-programmed patterns. I really had no idea that they’d managed to code up a Turing machine in Life, let alone patterns that emulate a universal machine, running a program that runs the Game of Life.

2008-09-01

django incoming!

I’ve spent today hacking with Django (well, to be accurate, I’ve been hacking on Django intermittently with eating pancakes, playing with kids in the park, and watching the whole Sarah Palin gossip trainwreck ricochet across the Internet: I honestly now have no idea what the hell is going to happen in this election).

I’ve been tracking Django since forever, but held off from doing anything too serious with it until 1.0. I’ve got a work project that fits the bill quite nicely, and I figured that a few days before 1.0’s September 2nd estimated deadline would be good enough to start hacking.

It’s been fascinating working under a codebase that is under heavy but stable development as you work. I hit bugs that I’d find in the bugtracker, filed just a few days ago, and then find them fixed while I slept. I’d also have occasional disconnects where something I’d been using in Django a few months ago had been completely reworked (mostly the admin feature), and I’d have to scramble a little to work out what had changed, and what had remained the same.

Overall, though, I’ve been really enjoying it. The changes that were made, like being able to subclass database models, seem esoteric but end up being really useful (I am uncomfortable with idea of refactoring a database schema, but it’s made much more sense to me now I can fiddle with inheritance instead of bang my head against SQL). The documentation remains first class, and has kept up with all the changes. I’m not far enough through the project to give you a realistic summary of how good a fit it is for my use, but so far, it’s been fun, at least — and it’s definitely good enough for 1.0 status.

2008-08-29

the most useful simple script i have

Lee’s comment that mentions having a folder for items you’re about to delete reminds me of probably the script that has most contributed to sanity in my filing system. It’s pig simple, albeit a bit scary to write and enact. All it does is delete everything in a given folder that’s over a week old.

I’ve had bad experience with handing “delete file” powers to an automatic script before, so I’ll disclaim any warranty (“TO THE EXTENT PERMITTED BY APPLICABLE LAW” as the GPL shouts), but it’s pretty straightforward, and works for me: I have it in a cronjob. The tmp folder it cleans up is my default save folder on Firefox, and where I generally download everything. If I want to save anything longer than a week, I find it a place in the rest of my filing system. It’s sort of like having a cleaner come around every week: occasionally you go “Garr! Where’s that coffee-stained, have torn copy of last month’s New Yorker! I was going to eventually get around to reading that!”, but mostly your cruft just silently disappears without you noticing a thing.

You’ll need to replace /home/danny/tmp with your own dumping ground. If you run it like this:

% clean_folder -d

It’ll tell you what it’s planning to delete. Run it without the -d and it really will delete those things, blam.

#!/usr/bin/python
##
# clean_folder  --  clean up temporary folders
##
# Deletes everything under a folder which hasn't been modified
# in a week. Deletes directories that are empty, too.
###

import os, sys, time

if (len(sys.argv) == 2) and (sys.argv[1] == '-d'):
    dryrun = True
else:
    dryrun = False

tmpdir = '/home/danny/tmp'
daysback = 7
cutofftime  = time.time() - (60 * 60 * 24 * daysback) 

for d in os.walk(tmpdir, topdown=False):
    (dirpath, dirnames, filenames) = d
    for f in filenames:
        thisfile = os.path.join(dirpath, f)
        if (os.lstat(thisfile).st_mtime < cutofftime):
            try:
                if dryrun:
                    print "I would delete:", thisfile
                else:
                    os.remove(thisfile)
            except OSError, (errno, strerror):
                print "%s: OSError(%s): %s" % (d, errno, strerror)

    for d in dirnames:
        thisdir = os.path.join(dirpath, d)
        if not os.listdir(thisdir):
            try:
                if dryrun:
                    print "I would delete:", thisfile
                else:
                    os.rmdir(thisdir)
            except OSError, (errno, strerror):
                if (errno != 66):
                    print "%s: OSError(%s): %s" % (d, errno, strerror)

2008-08-04

pomp; patry; gconf-watcher

Second Circuit Judge Pierre Leval once said that the best way to know you have a mind is to change it, and I have tried to live by that wisdom… There are positions I have taken in the past I no longer hold, and some that I continue to hold. I have tried to be honest with myself: if you are not genuinely honest with yourself, you can’t learn, and if you worry about what others think of you, you will be living their version of your life and not yours.

William Patry

I didn’t know of Bill Patry before he started blogging, but once he did, I started seeing his name everywhere. Mainly on huge multi-volume collections of hardback legal tomes, titled “PATRY ON COPYRIGHT”. He’s given up blogging because people would insist on quoting his blogging opinions as though they were an official pronouncement of his new employers, Google. Also, the current state of copyright law (and he actually contributed to drafting a chunk of it when he worked for Congress in the Nineties) depressed him too much.

Fortunately, I am never depressed by copyright, and I am confident you will never confuse my pronouncements here with any of my employers, because I have a little box down there that says so. So we are stuck with each other.

Today is column day, which means I have to save my most potentious stuff for one of said employers instead of you. It also means that I have been procrastinating all over the Net. Patry’s mum told him you must learn something new every day: today I learnt that the best way to poo-poo a fusion project is to say “Feh, you’ll never fix the Bremsstrahlung” (and the best way to help is to start a fusor in your home town). I read the best defence ever of a children’s book that has gay marriage in it, and added another Hari Seldon-style modern psychohistory attempt to my list. I also learnt that other far more esteemed columnists look exactly as bad as me on column day.

But if you wanted to know that stuff, you would have Googled for it. What you want to know is this: if I’m using GNOME, and I’m futzing about with my preferences, how can I easily note them down so that I can recreate what I’ve done when I accidentally delete my home directory (again)?

#!/usr/bin/env python
###
# Print out changes to the environment
###

import gtk, gconf

def key_to_tool(entry):
    v = entry.value
    try:
        return 'gconftool --set %s "%s" -t %s' % (entry.key, v.to_string(), v.type.value_nick)
    except:
        return "# Couldn't understand setting %s" % entry.key

def key_changed_callback(client, cnxn_id, entry, other):
	print key_to_tool(entry)

client = gconf.client_get_default()
client.add_dir('/',
                gconf.CLIENT_PRELOAD_NONE)

client.notify_add('/', key_changed_callback, 1)

gtk.main()

That’s what you were Googling for, my friend. Run this code in the background as you merrily click on Gnome options in most programs, and it’ll spit out a set of commands that if you run will recreate your clicking. Useful for finding where the hell Gnome is hiding certain preferences, or what exactly certain programs are changing behind your back. You’ll need to install python-gtk in Ubuntu and Debian. And probably a bunch of gotchas that I have pigheadedly ignored and which you will find in the comments below from smarter, friendlier people than me.

2008-07-29

rag and bone scripts: switchto

So I feel a bit bad because I have two half-written long thoughtful posts, but this evening was games night at the EFF’s hollowed-out mountain headquarters, and after a bit too much Settlers of Cataan, beer, Rock Band, and beer, I strangely cannot be bothered to finish those entries. I will just repeat for the record that you have not seen rules lawyering until you have seen EFF’s litigation team play AD&D. I still admire Quinn for daring to DM them.

Anyway, instead, let me fob you off with a couple of tiny hacks I use pretty frequently on my Linux desktop.

They all gank their usefulness from wmctrl, which is a fantastic command line utility for almost any Linux desktop, and lets you control windows and focus from the command line. You can install it from that webpage, or just do apt-get install wmctrl on Debian/Ubuntu.

#!/bin/sh
###
# Switch to a screen or do something
###
if ! wmctrl -a $1; then $2; fi

I save the above script as ’switchto’, and use it in GNOME’s keyboard shortcuts like this:

gconftool --set /apps/metacity/keybinding_commands/command_1 'switchto "Mozilla Firefox" "firefox"' -t string
gconftool --set /apps/metacity/global_keybindings/run_command_1 "<Alt>" -t string

That should set some options in the standard GNOME editor to run
switchto "Mozilla Firefox" "firefox"
whenever you hit Alt-F. It works with metacity and compiz, which is probably what you’re running with GNOME. Other desktops will have other ways to create keyboard shortcuts — I seem to remember that KDE’s one rocks.

Now, whenever I hit Alt-F on my keyboard, my desktop will switch focus to the first window it finds with “Mozilla Firefox” in its name. If it can’t find one (ie I’m not yet running Firefox), it starts it up for me. One key press gives me a Firefox window, either way. Here’s another one:

gconftool --set /apps/metacity/keybinding_commands/command_2 'switchto  `zenity --entry`' -t string
gconftool --set /apps/metacity/global_keybindings/run_command_2 "<Alt>slash" -t string

This is the poor man’s QuickSilver — it pops up a box, and switches your focus to a window that matches the text you type into it. It needs a program called Zenity which comes by default on most GNOME desktops.

Actually, I don’t actually use the second of those that much, but I do have a bunch of scripts like the first, setting up command keys to always switch to certain programs like the Terminal (try switchto "termi"), or IRC or Kontact. Your fingers quickly learn the motion, and finding your key applications even in a mass of desktops becomes instinctive.

I’ve always felt that that was the real power of QuickSilver as a window finder — Alt-Tab never lets you learn a consistent muscle memory to switch to a particular program, so you’re constantly derailing your thought by peering at icons to navigate around. I’d also encourage you to play around with wmctrl on the command line — you may be able to think of other desktop tricks that you can turn into simple keypresses.

                                                                                                                                                                                                                                                                                                           

petit disclaimer:
My employer has enough opinions of its own, without having to have mine too.