video is best enjoyed on the TV

We recently acquired an Asus O!Play HDP-R1. This is a small box which connects to the TV and the home network so it can play video shared over the network. Since our main source of entertainment is downloaded video, we’d been looking out for something like this for a while, and this one had the right combination of features and price. It’s nice to be able to watch things while slouched in a comfy chair instead of sitting at the PC.

Like quite a few small devices these days, the box runs a version of Linux, and a site has sprung up for people looking into how to modify the firm/software running on it. I haven’t done that myself (except for a firmware update), but I have been trying out ways to feed more content to the box.

First I got it playing DVDs. It doesn’t have a DVD drive, but I can put a DVD in my PC and share it. I basically followed the instructions from this other forum but shared the disk over Samba instead of NFS. It uses ‘dvdreadfs’ so that it effectively decrypts the DVD and then shares the decrypted version. On the video box we just have to navigate into the right Samba share and play the first file listed in video_ts, and it seems to deal with the DVD menu etc. properly.

Next we have it playing YouTube video. This is possible because the recent firmware updates added support for browsing UPnP media shares. The MediaTomb media server software has the capability to share YouTube videos – but you have to build from the latest svn version for it to work. It also requires transcoding software to convert the video from flv into mpeg, which means that it probably won’t work on our file server which is a low power machine. So I built and ran MediaTomb, and changed the config to enable YouTube and point it at my YouTube user account. On the video box we browse into UPnP and YouTube appears under ‘Online Services’. There is quite a delay when opening YouTube videos though.

random compiz wallpaper

Since I have a growing number of pictures of my baby daughter, I wanted to randomly select some to use as desktop wallpaper. I put a bunch of pictures in my ‘wallpaper’ directory and wrote this script to deal with them.

#!/usr/bin/env ruby
require 'pathname'
require 'dbus'
$wallpaper_dir = Pathname '/home/edward/wallpapers'
$screensize = `xrandr | grep '*' | tr -s ' ' | cut -f 2 -d' '`.chomp!
$sized_wallpaper = $wallpaper_dir.join ".resized#{$screensize}"
$sized_wallpaper.mkpath unless $sized_wallpaper.exist?
$ do |f|
    p = f.expand_path($wallpaper_dir)
    p.file? && !$sized_wallpaper.join(p.basename).exist?
end.each do |f|
    p = f.expand_path($wallpaper_dir)
    `convert -geometry #{$screensize} #{p} #{$sized_wallpaper.join(p.basename)}`
session_bus = DBus::SessionBus.instance
compiz = session_bus.service("org.freedesktop.compiz")
hsize = compiz.object('/org/freedesktop/compiz/core/screen0/hsize')
ihsize = hsize["org.freedesktop.compiz"]
desktops = ihsize.get.first
puts desktops
pictures = ${|f| f.expand_path($sized_wallpaper)}.select{|p| p.file? }{|p| p.to_s}
puts pictures
if pictures.size > desktops
    pictures = pictures[0, desktops]
bgimg = compiz.object('/org/freedesktop/compiz/wallpaper/screen0/bg_image')
ibgimg = bgimg["org.freedesktop.compiz"]

Some notes:

  • the combination of how the ruby-dbus library and the compiz dbus interfaces work is a little clunky. I’ve started making a library to help cover up some of the weirdness here.
  • I couldn’t find a good way to test the screen size from code, so ended up with the line which calls =xrandr= and parses its output. Not very maintainable.
  • I was going to set up the script to run from cron every hour or so but it causes a noticeable pause on the desktop when Compiz actually swaps the pictures so I just run it occasionally.

next whenever

It appears from a couple of confusing arrangements recently that Americans1 who say e.g. ‘next Friday’ mean ‘Friday next week’. Whereas I, being literal-minded, interpret it as ‘counting from today (which is Monday), the next Friday is Friday this week’.

In other time-related language, people here say ‘quarter of’, and I still can’t remember if that means ‘quarter past’ or ‘quarter to’. And if I say ‘half ten’ they don’t know if I mean 9:30 or 10:30 (it’s the latter).

1 or some people around here, anyway.

bash twitter

There are probably lots of variants out there. In fact mine is largely copied from here Inspired by BLT

# a twitter client (uses .netrc for auth)
if [ "$1" == "-h" ]; then
 echo " use: $(basename $0) -h | [ tweet ]"
 echo "      -h help"
 echo "      -i install"
 echo "      no arguments gets latest updates"
function binstall {
 local sheet='<xsl:stylesheet version="1.0"
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:apply-templates select="//status"/>
<xsl:template match="status">
<xsl:value-of select="id"/><xsl:text>: &lt;</xsl:text><xsl:value-of select="user/screen_name"/><xsl:text>&gt; </xsl:text>
    <xsl:value-of select="text"/><xsl:text>\n
 if [ ! -d $confdir ]; then mkdir -p $confdir; fi
 if [ ! -e $seenfile ]; then touch $seenfile; fi
 if [ ! -e $feedstyle ]; then
   echo -e $sheet > $feedstyle
function friends { 
 local tnow=$( date --utc +%s )
 local tthen=$( date --utc --reference=$seenfile +%s )
 if [ $(( tnow - tthen < 60 )) = 1 ]; then
 local tmpfile=$( mktemp $confdir/result.XXXXXXXX )
 curl --connect-timeout 5 -s -n $1 | xsltproc $feedstyle - > $tmpfile
 local tmpu=$( mktemp ~/.bt/uniques.XXXXXXXX )
 cat $seenfile $tmpfile | sort -n | uniq -u > $tmpu
 cat $seenfile $tmpfile | sort -n | uniq > $seenfile
 cat $tmpu $tmpfile | sort -n | uniq -d | cut -d':' -f2-
 rm $tmpfile $tmpu 
 touch $seenfile
function update {
 curl -s -n -d "status=$msg" $1 &>/dev/null || echo "tweet broke"
if [ "$1" == "-i" ]; then
if [ -t 0 ]; then msg="$*"; else msg="$(cat -)"; fi
if [ "$msg" ];then


  • bash
  • curl
  • xsltproc
  • mktemp

How to
1. Copy the above script into ~/bin/bt and make it executable.
2. Write a ~/.netrc containing something like this:

login exampleuser
password examplepassword

3. run bt -i to ‘install’. This will create a ~/.bt/ directory with a stylesheet and seen status file.
4. To check your friends timeline run bt with no arguments.
5. To post a message run bt <message> or pipe into bt. (Maybe for the next enhancement I’ll check the length of the message).
6. For friends updates while you use your bash command line, put something like this in your ~/.bashrc:

random dabbling roundup

I seem to be in a phase where I play with lots of new software things without creating a whole lot in any of them.

Google App Engine is interesting due to the promise of getting massive distribution/scaling for ‘free’. I started trying to put together a Java application to try it out, but it just reminded me how I don’t mind the Java in my day job, but for spare time stuff it is pretty tedious. Fortunately I found appengine-jruby which is much more to my taste. It wraps up all the boring stuff with some simple Ruby tools and APIs.

So I tossed the Java app and started a Ruby version. Along the way I’ve been learning a bit about Sinatra haml and datamapper

Who knows if I’ll ever finish that though, since I keep finding other things I want to play with.

Google Chrome is proving impressively fast. I found a few annoying things though:

  • It draws its own window decorations so it doesn’t match other apps – there is an option to change this though.
  • Its shortcut for ‘quit’ is shift+ctrl+Q, when most apps on my desktop use ctrl+Q and I haven’t found a way to fix this.

‘Killing two birds with one stone’ I tried out Ubuntu VMBuilder to create a simple virtualized LAMP server and installed Gallery 3 Beta on it. Gallery 3 looks pretty slick with a modern AJAX UI. I currently run Gallery 2 so I’ll probably upgrade eventually, but not until version 3 supports uploading directly from F-Spot and/or Picasa.

Next up, a colleague pointed out the Google Go programming language so I want to look into that some more. It’ll probably turn out to be another solution looking for a problem, from my perspective, but it’s good to get ideas of what’s going on out there.

javascript in the shell

Different languages are good for different things. But unix shell style trumps all. An example:


function urlEncode(str){
    str=str.replace(new RegExp('\\+','g'),'%2B');
    return str.replace(new RegExp('%20','g'),'+');
if(arguments && arguments.length > 0) {
    for(var i = 0; i < arguments.length; i++) {
        r = urlEncode(arguments[i]);
} else {
    S = new BufferedReader( new InputStreamReader(System['in']) );
    s = true;
    while (s){
        s = S.readLine();
        if (s) {
            r = urlEncode(s);


  • This works because /usr/bin/js on my system runs Rhino

Health Care Debate part 1

I’ve been meaning to write comparing British and US health care for a while, but it’s not a very easy topic to get around. However it is the main subject in the news these days so it’s about time I weigh in.

The most emotive piece I’ve heard on the radio this week was from one of many ‘town hall’ meetings (I forget which). A sobbing woman says, “The president is trying to make us like Russia. I don’t want America to be Socialist!”

Of course, being me, this leaves me thinking, “but why?”. The speaker obviously thinks ‘Socialist’ is a ‘bad word’ – I don’t. (I’ll leave aside the debate over whether Russia is really socialist any more). Since the quote doesn’t give any more reasoning, I’m left to wonder what this woman is actually opposed to – she clearly feels strongly about it.

Unfortunately, to me, the opposite of socialism seems to be selfishness. Selfishness in health care seems to lead to a situation where you are fine while you remain healthy but if you are unlucky enough to get sick you’d better hope you can afford it. A lot of illness isn’t selfish, by the way – the flu is happy to spread fairly to all people, given the chance.

In practice paying for US health care is somewhere along the selfish/social scale. As companies or organisations buy group insurance plans, they form small pockets of socialness. The only reason insurance works is because it spreads the cost across a group of people, with the assumption that not everyone will suffer illness. So people who pay insurance premiums and are healthy, are necessarily subsidising the health care of people in the same group who are less healthy. That sounds like socialism to me.

Of course, the American argument is that people have freedom of choice about what insurance they buy, or don’t buy1, and that the current debate is about the government taking away that freedom. I need to think more about that, so maybe more later.

1 I live in Massachusetts, and it is mandatory for people here to have some kind of health insurance.

basement music player part 1

Having got the old computer hooked up to the network I proceeded to work on its setup. My main intention for it is to play music from the network drive, while I’m down in the basement working on my other hobbies.

I upgraded it with the latest Debian, since that is about the only Linux distribution with a supported PowerPC version now (the computer is an iMac G3). Since I am used to Ubuntu, Debian is pretty similar.

Next I wanted to cut down the number of steps I had to take to get the machine on and playing music. I created a new user called ‘music’, and set up GDM (using the ‘Login Window’ preferences entry) so that it automatically logs in as that user (after 20 seconds, so I can still log in as a normal user if necessary).

Then I set up the user so that Rhythmbox starts automatically when they log in – since I’m using LXDE, this meant finding rhythmbox.desktop and copying it under ~/.config/autostart/

So now I can press the power button, and (after a while) the music user will be logged in with Rhythmbox on screen. I still have to go and click on the network music server icon before it loads up songs though, so that will be the next thing to fix. Having searched around, I think I’m going to have to learn to write a Rhythmbox plugin to make that work how I want…


A while back, I put our old computer elizabeth on a shelf in the basement. Frustratingly, it was fairly close to our cable modem, which is connected to the home network, but there is only a single cable run up to the router which is on the first (ground) floor, and which is where it would really need to connect to, and I didn’t fancy drilling more holes in the walls and floor. But I remembered having read at some point that 10/100 ethernet only uses two of the pairs of wires in a cable, and cat 5 or 6 cable has four pairs in it. So I did some more research on the web which suggested that with the correct connectors, you could run two connections through a single cable

Since I was being cheap, I built my own connectors. I broke up a junk 10Mb router to take the sockets out of it, and cut up some spare patch cables to get short lengths with a plug on one end. By referring to this colour code diagram I wired up my connectors so I would have a ‘straight through’ path on the orange and green pairs, and a diverted path which connected the ‘external’ orange and green pairs to the brown and blue pairs in the single cable. With an hour or so of (bad) soldering I put my connectors together – and then the moment of truth – I reconnected the modem and router ends of the cable, and connected in the computer in the basement, and it all worked!

Comcast are scum

The ‘Digital Television Switchover’ took place here a couple of weeks ago. Not long after, we received this letter from Comcast[PDF 900kB]. While I suspect it doesn’t say anything that is actively illegal, I do think it could be highly misleading and is taking advantage of less well informed people1.

Q: How do I get my signal back?
A: There are several options, but the easy answer is to call Comcast.

How do you quantify ‘easy’? Comcast’s offer probably is ‘easy’ in the sense that once you request their service, they’ll send an installer over to set everything up for you. Of course RCN, Verizon, DirecTV, Dish Network or others would do the same thing, so it pays to shop around, if that’s what you want. They’ll all need to you stay at home to wait for the installer, then add some extra boxes to the outside of your house, drill holes and run cable around.

Assuming you have a TV antenna in place, I think it’s quite easy to buy a digital converter box, connect the antenna to it, and connect it to the TV.

Q: How do I get FREE Basic Cable?
A: It’s easy… sign up for Internet and/or phone (each starting at just $24.95/mo.)

So this is that special kind of ‘free’ where actually you have to pay for something. Whichever deal you choose you’re out a minimum of $10 every month to Comcast, and reading the small print you may also have to pay for equipment, installation, taxes and other fees. Don’t forget, it’s only ‘free’ for the first year. Do you expect to watch TV for longer than a year?

Compare this to a digital converter box. You can request a converter box coupon which gives you $40 off the price. The boxes are selling for around $40 – $60, so your maximum outlay will be about $20 (plus sales tax), with no ongoing cost. If you were previously watching broadcast TV, you can use the same antenna.

Should you take up Comcast’s offer?
I don’t intend to. I don’t think it gains you anything other than another monthly bill. If you just want to get broadcast TV back, a converter box is a cheaper option. If you really want cable, look around at all the possibilities.

1 Though my impression of US culture is that there is more of an expectation for people to inform themselves to avoid being taken advantage of.