Archive for June, 2009

src parade: marginalia

Tuesday, June 9th, 2009

I recently centralized and tallied up my personal source repository: something like 100kloc and about 80 directories.  This represents around a decade of evenings and weekends spent writing code, in everything from C to Haskell, in environments from my low-level Unix home to PalmOS.  The most recent stuff is arduino and processing, but it also includes OCaml-gtk and a bit of Objective C (written on OS X 10.0).  The common themes through all this diversity?  It’s all hastily written, poorly documented, and nigh-unreleasable code.

That said, my friend Kragen caught wind of this and suggested I release it all.  While I won’t release everything (some of it is still very nascent and/or mostly vapor), I will be working my way through, giving some things Makefiles and READMEs before kicking them out the door.

Tonight is the first installment of this src parade.  It’s actually something I released years ago, which has fallen into a bit of disrepair, but was still pretty cool: Marginalia.  Marginalia was a firefox extension that allowed you to annotate webpages in-place, and see the annotations others had left behind.  Its plugin description was “Collaborative annotation for FireFox,” which pretty well fits.

Viewing an annotation placed with marginalia

Viewing an annotation placed with marginalia

Why did I build this in the first place?

It was meant to allow the disruptiveness of the web to become even more pervasive.  Imagine if citizen journalists could leave links to alternate coverage of stories on CNN.com, or add links to previous statements by politicians to their latest contradictory interview.  It predates youtube; nowadays, it would definitely allow embedding youtube clips for this.

What did I learn in building it?

Javascript is hard.  No, really, it is.  If you want to build something like this, performance matters, and it’s non-trivial to get correct.

HTML/DOM is hard.  It was never intended to do things like this, and you really have to bend over backwards to make it happen.

Don’t give up so soon.  Marginalia was pretty freaking awesome, if I do say so myself.  I didn’t push hard enough for others to adopt it, and I let it die too early and too easily.  It could have been a big deal, but I didn’t care enough to keep at it.  In my defense, I was in the second to last semester of undergrad, which was pretty intense.  I was working 20-30 hours a week and had two majors, so it was either hack on this or spend time with my girlfriend.  (I got to play with marginalia on the clock, but only so far as it didn’t interfere with keeping the lights on.)

Where does it stand today?

Marginalia fell to the wayside at some point.  Most significantly, it needs retouching to work with the latest firefox/gecko.  It currently doesn’t install, but I’m pretty sure it’s more than just updating the compatibility ranges.  If you’re interested in the problem, I’d suggest looking at newer web annotation systems  Wikipedia has a good list at [[Web annotation]].  The hardest technical problem you’ll face is actually kind of silly: figuring out where to attach the note based on the user’s click.  Have a look at how marginalia does it to see one solution; I’m sure there are others which are just as good.  (Hint: marginalia bundles a pure-javascript SHA-1 implementation)

You’ll find more text and a download at the Marginalia homepage.  The source is part of the download, though it doesn’t look like it.  XPI is, like JAR, a strange way to say ZIP.  That is: you can download the XPI file (right-click, save as), then unzip it (you might need to rename it to be a .ZIP file).  The guts of things are in chrome/marginalia/content/marginalia.js

Would I do it again?

Probably not, actually.  This is mostly because others are solving the problem, but also a little bit because solving the problem is incredibly tedious.  Having written a handful of little firefox extensions, I now have zero urge to build on that platform any more.  I still love the idea of marginalia, but I would prefer to leave implementing it to someone else.

oscremoted

Sunday, June 7th, 2009

My iPhone is gradually becoming a universal remote control, and I love it.  This is the first part of that: how to hook a generic GUI-creation tool on the iPhone up to run arbitrary commands on my Linux box.

One of the peacetime dividends of Perceptron is an awareness of OSC.  OSC is Open Sound Control, a standard for sending, well, sound controls over the network.  If you’re familiar with MIDI, it’s basically MIDI over the network, but with twice the resolution.  Technically, they seem to have made lots of really good design decisions, and it’s been around long enough to have mature tools around it.

Basically, OSC allows you to have volume sliders, arbitrary buttons (play, pause, turn on lights, etc), knobs: just about anything you could use to control music can be put into OSC.  This is great, because it allows a designer to abstract out the interface from their application, and just plug in different physical widgets to implement “volume slider 1″ or “play drum B.”  Or, just as easily, hook those up to software, so they can have a GUI to interface to humans, or pure software control, with a software robot hitting virtual buttons.

While poking around one day, I thought to myself, “Wait, someone has to have done an OSC GUI for the iPhone!”  And, sure enough, they had: OSCRemote.  It’s great fun to play with: you can add little sliders, move buttons around, and even use the accelerometers.  It’s a delight, especially if you’re used to creating GUIs in code.

However, at the end of the day, I’m still a command-line Unix guy.  How do I bridge that gap?  With a control daemon, of course!  There’s a nice C library that implements OSC (liblo) using callbacks; add a trivial config file parser and an exec() implementation, and voila: I can now run set unix commands by hitting buttons on my iPhone.  It’s incredibly configurable and general, while staying pretty straightforward.  Now I can start and stop music, jump tracks, and nudge volume up and down from anywhere in my apartment, using just my phone.

You can get the code for this at oscremoted (creative name, eh?).  It needs to get a proper homepage on my domain; until then, it’s just a tarball with a freshmeat page.  I’m curious if anyone has ideas for refinements or improvements; comment if you do!

My first foray into optics

Saturday, June 6th, 2009
My first epoxy lens and its image at focus

My first epoxy lens and its image at focus

I’ve long been reading telescope maker porn for a while now (I’ve read A Manual for Amateur Telescope Makers twice while commuting), but I have never found the time or place to get down to grinding my own mirrors. I found a few tutorials for grinding coke bottle lenses online over the years, but never got around to that, either.

A couple weekends ago, I did my first experiment with fiberglass. It went pretty okay (read: terrible), but left me with this great little puck of epoxy. Every since, I’ve been wanting to make a lens out of it.

Today, I did. It needs some figuring, and is still quite hazy, but it was surprisingly easy to quickly throw together.  The technique was incredibly cheap and straightforward: first, grind it against 100 grit sandpaper laid on a tabletop to shape.  Then, begin the polishing with a progression of 320, 600, and 1500 grit sandpaper laid on top of a folded rag.  Finally, go after the surfaces with metal polish.  This leaves them a little hazy, but I believe it might be that I wasn’t thorough enough with the intervening sandpapers, so there are still pocks/scratches in the surface.  My loupes are at noisebridge, so I can’t quite tell (and it feels awfully smooth to the touch after the 320).

The technique is still being refined, but it has a lot of promise for banging out toy lenses or custom optical assemblies for art pieces.