This is as days pass by, by Stuart Langridge

Helvetireader in Mozilla Prism

Jon Hicks has just released Helvetireader, a lovely minimalist theme for Google Reader. He's implemented it as a GreaseMonkey script which pulls in the CSS file direct from helvetireader.com, which is a cool touch. He also notes that "the Helvetireader user script is ideal for using with Fluid.app to create a standalone application". It is, of course, also ideal for using with Mozilla Prism for those of us not on a Mac (or those on a Mac who prefer Prism to Fluid). Grab helvetireader.webapp for all the well-styled-Google-Reader-in-its-own-window you'll ever need. (Those of you of a technical bent: all I did was add a webapp.css saying @import url(http://www.helvetireader.com/css/helvetireader.css); to greader.webapp, so you could do that yourself and add any extra customisation you want to that file.)

14 minutes 12 seconds of fame to go

Me on Top Gear

What I've got open

Rather a lot, I find myself having to save a file somewhere temporary like my desktop just in order that I can immediately upload it to some website, or attach it to an email, or something similar. It's irritating. I have to explicitly save it; I have to think up a name for it; then I have to switch to my mail client or my web browser and browse back to the file I've just saved and choose it by name to upload/attach it; then I have to browse to it again in the file manager and delete it. Now, there's lots of talk about draggable icons for files and so forth, so I can just drag the save icon out of, say, the Gimp directly into the browser. The ROX apps do this; Risc OS did it too. That's a nice long-term goal, but it requires touching every app in the universe, and it's hard. I had a thought about a workaround. It'd be quite cool to have a folder called "Open Documents" which, when opened, showed an icon for each document available in each application. Then, when you pick a "file" from this "folder", it tells the relevant application "save it as some random temporary name" and then attaches/uploads some random temporary name. So you don't ever have to manually do the save/delete thing. I only really strictly need this for the Gimp, to be honest; I don't upload textual files, I cut-and-paste them. So, a rather crufty approach:
  1. Download gimpdbusapi.py and put it in $HOME/.gimp-2.6/plug-ins/ and mark it executable. It's a Gimp extension which makes two functions available over D-Bus: image_list and save_as. (This could be the starter for making all Gimp functions available over D-Bus, with a __getattr__ hook, the gimp.pdb object, and a bit of introspection.)
  2. Download gimpfs.py, a Fuse filesystem in Python, which talks to the Gimp extension via D-Bus to get the list of currently open images in the Gimp (even if they haven't been saved).
  3. Create an empty folder ($HOME/Open?) and python gimpfs.py $HOME/Open to mount the view of Gimp open documents on that folder.
There might be better ways to do this, with gvfs and so on, and it would be way better if it didn't have to use tempfiles, and so forth, but this is a proof of concept. What would need to happen to have all Gnome apps' currently open documents automatically appear in a folder ready for choosing?

behave!

After watching @darrenf (a) tell an awful lot of people to behave on Twitter and (b) have to manually type it in every time, thus providing wear and tear on his hands which mean that he can't fix bugs instead of me, I present: behave.user.js, a Greasemonkey script to tell people to behave on Twitter. Just hover over a name and click the ! to tell that person to behave. Winner.

Pause torrents while I'm using the computer

I use the Transmission BitTorrent client, and it's pretty cool. However, it's irritating when it eats my bandwidth while I'm trying to do stuff. So, one obvious hack would be to disable it when the screensaver is off (i.e., I'm using the computer) and enable it only when the screensaver is on (i.e., I'm in bed). Fortunately, Transmission has an API (which you have to enable by turning on the web interface in Preferences) and you can watch the Gnome screensaver for changes. So, a quick Python script later, and throw that Python script and Transmission itself into your session Startup Programs to make them run whenever you log in, and Bob's your uncle. the script:
#!/usr/bin/env python
import dbus, urllib
from dbus.mainloop.glib import DBusGMainLoop

START_TORRENTS = "http://localhost:9091/transmission/rpc?method=torrent-start"
STOP_TORRENTS = "http://localhost:9091/transmission/rpc?method=torrent-stop"

DBusGMainLoop(set_as_default=True)
sess=dbus.SessionBus()
def sig(screensaverActive):
  if screensaverActive:
    data = urllib.urlopen(START_TORRENTS).read()
  else:
    data = urllib.urlopen(STOP_TORRENTS).read()

sess.add_signal_receiver(sig, 'ActiveChanged','org.gnome.ScreenSaver')
import gobject
loop = gobject.MainLoop()
loop.run()

Trying to understand YUI 3

I've been looking at YUI 3, because I ought to know about it and I currently don't. I used YUI 2 for a few things and found myself perpetually frustrated with the documentation and the general feel of it, but I figured that maybe that was just me. (Disclosure: I'm a jQuery guy. Use it for everything. So I'm biased, right out of the gate.) Anyway, my frustration with the YUI documentation doesn't seem to have been alleviated in version 3. This is a case study in how someone new to the YUI 3 library sees the documentation. (Well, it's really a set of stream-of-consciousness rants, because that's the best way I can think of getting my sense of confusion and discombobulation across.) The underlying problem I always had with the YUI 2 documentation was that the examples show how to do one specific thing but don't explain why to do it that specific way, and don't seem very generalisable to do other similar things. So they're hard to learn from. The reference manual, on the other hand, is useless. It gives you a textbox and says "Start typing to find a property/method/event/config". If you already know what you're looking for, if you know which function you want to use but can't remember the order of the parameters that you need to pass to it, then that's fine. It's a dictionary. But you can't learn a language from a dictionary, and you can't learn the YUI from the reference manual. I hardly ever find myself thinking "I need to use the YUI.Get.script function but I can't remember the name of the parameters". Instead, I find myself thinking "I want to execute a JSON-P script; how do I do it?" Now, the jQuery documentation has a similar problem, to some extent, but critically it shows you all the functions in a list, so I can look through them and work out which is likely to be the one I want. The YUI does not. The jQuery docs also have inline executable examples with each function, so I can see working code and test it. The YUI reference manual does not. But I shouldn't start with the reference manual. The YUI docs specifically say to , so I did so. The very first example is showing how to attach an event handler to a node. Fine as far as it goes (and I like the idea that you get passed a full-on event object to your function whether you're in a browser that supports that or not), but...the code in the example just drifts in space. It's not wrapped in an onDOMContentLoaded or anything. (I admit it's the first example, which means you don't want to load people down with infrastructure just so they can write a click function.) So, since there's a working example in the page, I looked in the source myself, and we get
YUI({combine: true, timeout: 10000}).use("node",
function(Y) {
 ... code from the example...
});
Ah, OK, so that's onDOMContentLoaded, is it? a new YUI function. I'm sure it'll be explained later. Moving on, the next example explains onAvailable, onContentReady, and event:ready -- three different "is the thing ready for me to use" load events. (All of which make sense at different times, and are potentially useful.) That's all good, but...the previous example, even after I'd looked in the code, didn't use any of them! How did that work? Ah, a feeling of doom creeps over me. More disclosure: I really, really don't like the Yahoo practice of putting your JS inline at the bottom of the page. I think it means that my JS isn't separated out into different files where it's easy to edit, it makes refactoring the page hard because you have to care exactly where your script elements are and be careful if you move HTML elements around, and it's a lot easier to teach people to make their JS unobtrusive if you can offer the rule "Put all your JavaScript in separate files and don't have any anywhere in your HTML". I know there are good reasons why Yahoo do it, and I accept those reasons. If I build a site which gets as many hits as they do then I'll test both ways and the extra three milliseconds you get from having the JS in-page without DOMContentLoaded may make a big difference. For most of the stuff I write, though, I don't like it and try to not use it. So, the first example was obviously reliant on that (because it's not hooking any load event at all), but didn't say so. Moving on, the next example I read, about nodes, does the same thing. As far as I can tell, nothing anywhere in these examples has said "make sure you put this example code after the things it's referring to". If you don't do that (say, if you put it in the head because that's where you've been taught that JavaScript should go) then it plain won't work, and you won't know why. (Maybe I missed the 72-point red writing which says this? I hope I did.) Next example I read (event delegation, a thing I like very much): doesn't show why the clicked items turn green (obviously CSS, and indeed it doesn't take long to find the link in the source), but also...when I click on one of the items and it turns green, there's a subtle animation effect to it, as if the green colour expands out from the centre of the item. It's quite a nice effect. I can't for the life of me find what's doing it, though. (Doesn't do it in Midori, a webkit browser, so maybe it's Firefox?) I spent ten minutes trying to work out why clicking on an item sets a class ("yui-pass") on that item and then alters text in all non-yui-pass items, rather than just using e.target. Of course, the reason is that a second click on a different item should set that second item to green and not unset the first green item. Fine and dandy: a note about that in the example would have helped, though. Yes, the examples are there to demonstrate YUI, not to explain how to produce a specific effect, but...what people want is a specific effect. Explaining how it works would help with that. Explaining the YUI parts of an example but not putting them in the context of the rest of the code is like explaining how to build a house with a two-hour lecture on bricks without ever mentioning that you need mortar to stick them together. "The rest of the code" here is a couple of lines, but the example would make much more sense if it was all explained. Once I'd got this far, I started thinking, hm, hasn't changed, still the docs are written for someone who isn't me and I don't get them. So I started dotting around picking and choosing bits to look at rather than going through step-by-step. One of the features I like most about jQuery is that I can call a JSON-P script and still specify my callback function inline, rather than having to separate it out and give it a name and pass that name as callback=myCallback to the JSON-P script. (It gets given a name under-the-covers by jQuery, of course, so that the callback does have something to call, but I don't have to think about it. I like inline functions.) It's be useful to me if YUI 3 could do that, so I thought I'd have a look to see if it's possible. I don't think it is, but...I can't tell. The docs don't seem to mention the idea of loading scripts that call a callback function at all. Instead, I think you're supposed to use YUI.Get.script and read the JSON out of the nodes array that you get passed. Perhaps. Here we come back to my problem with the YUI docs: I know what I want to do, but not how to do it, and there's no way to answer my question. If there isn't an example dealing with it, I am out of luck. Someone tell me how I ought to be reading the documentation. Maybe I'm missing something. But it does rather feel to me like the docs are reference material: they're there for people who already understand YUI. The examples are incomplete -- focusing on just the part you're trying to show is understandable, but if the example won't work without the other parts then you have to show the other parts too! If your example only works if it's wrapped with YUI().use("node"), function(Y) { ... }) then you have to show that. If it only works if it's wrapped in DOMContentLoaded, or if it's placed at the bottom of the page in a script element, then you have to say that. Yes, it's a ballache to have to explain how events work and how loading works and not get to any real concrete examples until chapter 3 or 4 of your documentation. But people need to know that stuff or your examples will not work when someone uses them without knowing the context.

MythTV alarm clock

This morning my alarm clock didn't go off, and I didn't make it to work. That's gotta be fixed. Since this weekend I got a whizzy new MythTV setup around my house, that seems like the ideal thing to wake me up. However, MythTV plugins are written in C++, and I don't do C++ because I'm a Python guy. So, something of a hack. It is possible to add a menu item to MythTV which runs an external program. So, thought I, that'd be one way to do it, and indeed it works. You create a new "menu theme" which launches an external program by name. The Myth menu theme development guide explains how. Then, write a small program to accept user input to set an alarm (I used pygame, which seems more in keeping with the MythTV approach than Gtk), and pow, Bob's your uncle. Actually, I used pygame primarily because I needed the MythTV keys to navigate around the little alarm-setting program. I've got some weird keys bound to do navigation in MythTV (2, 4, 6, 8 for up, left, right, down) and I've got no idea how you can make the 6 key mean "go to the next field" like Tab does in a Gtk application. In pygame that's easy, so I did it that way; at some point in the future it should also allow me to theme the app so it looks like your MythTV theme, but I didn't get around to that. The way it actually creates alarms is by putting them in your crontab, which is easy and satisfying and what cron is for. Anyway, code in Subversion at http://svn.kryogenix.org/svn/mythtv-alarm-clock/ if you want to have a play. I suspect the MythTV people would be horrified by this approach. A few of them tried to convince me that I should learn C++ because it's not that hard...

When the meme comes around

blah blah blah meme blah blah blah fifth sentence on page 56 of nearest book blah blah blah. "Thorn, that's beautiful!" Not much of a sentence. On the other hand, the book is The Complete One-Volume Edition of Bone, the graphic novel. Memo to self: do not search the internet for "bone" again in a hurry. Page 56 is about as far as I've got with the book so far. It's pretty heavy going, what with it being 1400 pages and all. I was lent it by Tim when I issued a cry for help for not having books. (All my books got packed up when I assumed I'd be moving house in short order...and then the economy swirled down the toilet and no-one's buying houses. So I have a big house that I rattle around in on my own, and no books. Tim delivered me a box full just to keep me going after I was reduced to reading the back of tomato ketchup bottles just to stay sane. And then the first thing I read from his delivered collection was the incredibly cheery Maus.) Has anyone else read this Bone thing? If you have, did you enjoy it? If you didn't, did you keep reading anyway? I feel guilty if I abandon a book. Something about erudition. But if I didn't read then I'd have to read Twitter all day instead and I'd go out of my mind. (Yeah, yeah, go outside and enjoy the sunshine. Whatever.) Did you know that Wikipedia does ISBN searches? Oh, you did. OK.

It's a purple world

All the maps you see of the US election results are sharply divided into blue states and red states. It occurred to me that since "a state goes for Obama" sometimes means "by nine votes", that it might be interesting to see a sort of representative map. So, the purple map of US election results: The whole country's pretty similar in colour, innit? I suppose this is what Obama was talking about with the "I'll be your president too" stuff... (map from wikimedia (svg), election results from Google, map as SVG, script to generate map)

This website belongs to Stuart Langridge. Contact details are available. Don't eat yellow snow. Valid HTML5, at least in theory, except for the bits that aren't because I'm that futuristic that I'm ahead of the spec, oh yes. HTML5 help from Bruce Lawson, among others. Fonts from the superb FontSquirrel. End.