Thoughts of a geek

25 May 2019

Fairy light controller

Filed under: Computers, Electronics — Tags: , , , , , — qwandor @ 12:34 pm

One of my housemates has a lot of fairy lights. Most of them were battery powered, each by a little pack of 3 AA batteries, which seemed somewhat wasteful. They are great for parties, but turning them all on and off individually is kind of a pain too, so I wanted to make them mains powered, and controlled from Google Home. And as I mentioned in a previous post, I’ve been playing with ESP8266s recently, so I built a controller based on the D1 mini board.

The first version I prototyped with a dual H-bridge board I had sitting around, using each half-H separately so it could control 4 strings of fairy lights, just twisting some wires around the battery terminals. It was a bit messy though:

First prototype, fairy light controller V1

So next I made a somewhat neater version on some stripboard, using a dual H-bridge chip I had sitting around, but with a pair of screw terminals per output rather than just a single ground connection to make it easier to use. I also added some header sockets that could be used to put a resistor in series with the output easily. This meant that rather than being quite so hacky with wires twisted around the battery terminals I could cut the battery box off entirely, unsolder the resistor from there and put it into the socket on my board, and then just connect the wires from the lights themselves to the screw terminals. This made things a bit neater:

Fairy light controller V2, H-bridge chip on stripboard

I also happened to have a bunch of power darlington transistors sitting around, so I made an open-collector output version with them. This let me add the option of using a separate power supply for driving higher voltage loads, rather than just using the same 5V USB power supply as the D1 mini. It was also a bit smaller. (The white terminal block on the left is the power supply input, and the jumper next to it connects it to the 5V from the USB power supply instead.)

Fairy light controller V3, open-collector outputs and an optional separate power supply.

This worked well and was certainly an improvement, but stripboard is still a bit messy, so I decided to make a proper PCB for it. I also found a handy chip with 7 darlington drivers, so I used that. 4 channels still seemed enough so I hooked 3 pairs up together in parallel for higher current capacity. I designed the board on EasyEDA (link at the end if you want to order some for yourself) and ordered 10 copies from JLPCB in China (PCB prototyping services are amazingly cheap these days!) along with the parts, and a few weeks later they showed up.

Fairy light controller V4, all soldered up neatly.

It was indeed neater, so I think this will be the final version. It works well, controlling the fairy lights in the living room.

On the software side, I was able to share a bunch of common code (for the web admin interface and so on) with my previous smart button project. For integration with Google Assistant and Google Home I went via Sinric, which provides a server that the board can connect to, and then can connect to the Google Smart Home API. It’s still a wee bit of a hack at the moment unfortunately, as the Sinric Google Home integration isn’t properly launched so you can only use it in developer testing mode, but other than that it works well. You can track the status of the Sinric launch on GitHub.

If you’d like to make one for yourself, you can find the schematic and PCB design here on EasyEDA ready to print, and the source code and setup instructions here on Gitlab. (See the ‘Smart switch’ / qSwitch section.) And there are a few more photos here. Let me know how you get on!

[edit] Oh, and if I know you / you live in London, I have 9 spare boards and most of the parts available, so if you’d like one let me know. You’ll just have to get your own D1 mini and terminal blocks. Happy to help get it working too.

24 December 2018

Smart homes and ESP8266s

Filed under: Computers, Electronics — Tags: , , , — qwandor @ 11:42 pm

I’ve recently been playing with a bunch of smart home stuff, based around the Google Home ecosystem. I have a Google Home, Google Home Hub and JBL Link View in various rooms, a Chromecast and Chromecast Audio, a Nest thermostat, a bunch of cheap smart light bulbs, and some Sonoff switches for the ceiling lights. It’s pretty cool: I can control the lights and music all around the house by voice, from the smart displays, or from my phone.

But there are a few things missing. As cool as voice control is, sometimes I just want to press a button and have it run some preset action, like turning all the living room lights off late at night when I’m heading up to bed (without waking up my housemates), or turning on all the fairy lights for a party (when the background noise is too loud for voice control to work reliably, and it’s a bit awkward anyway).

Happily, AliExpress has lots of ESP8266 dev boards from as little as £1.70. The ESP8266 is a little microcontroller with a WiFi stack and fairly low power requirements that makes creating WiFi-attached gadgets pretty easy. It can be programmed (among other options) in C++ with with the Arduino libraries. For a nicer development than the standard Arduino IDE I used PlatformIO, which adds a proper IDE and dependency management.

My first approach was a stand-alone button. This can be battery powered, and stays in a low-power standby state (or entirely off, with a little extra support circuitry) until it is reset, at which point it starts up, connects to WiFi, sends a command, and goes back into standby (or powers down). This works well, though I didn’t get as far as finding a nice way to package it up. Without making custom hardware it’s a little bulky, with the battery and everything.

An ESP8266 dev board connected to a Li-ion battery.
An ESP8266 dev board connected to a rechargable battery.

So I tried a different approach. The Sonoff RF Bridge is widely available on AliExpress and elsewhere for under £10. It contains an ESP8285 (basically the same as the ESP8266 but with built-in flash) and a 433MHz remote transmitter and receiver controlled by a separate microcontroller, connected over the serial port with a documented protocol. With the stock firmware it can clone your existing remotes to control whatever devices you may have controlled by 433 MHz remotes, which was not very useful to me. However, the firmware can easily be replaced by simply opening the case (4 screws) and soldering on a 4 pin serial header to the labelled row of holes on the PCB. AliExpress also has lots of nice wall-mounted 433MHz RF buttons that look like normal light switches and can last a long time on a small battery.

With that in mind, I built some replacement firmware for the Sonoff RF Bridge, that lets you pair it with many such buttons, and associate each one with a different command to send. This works really well! I have the RF bridge sitting plugged into USB power somewhere out of the way, connected to my WiFi, and waiting for signals from the buttons I now have mounted around the house to send commands.

A Sonoff RF Bridge connected to USB power.
My RF Bridge glowing happily in the corner.

What I haven’t mentioned so far is how I send commands. Google Home doesn’t yet have a proper API to connect buttons like this, but what there is an API for is sending Google Assistant commands from other devices. These can be either voice or text; of course in this case I went with text. So when one of the buttons is pressed, I can send an arbitrary Google Assistant command, like “turn off the living room lights”. It takes a couple of seconds to respond, but otherwise works pretty well.

If you’d like to try either of the above, you can get the source code here, along with some more documentation of how to set it up. Once you’ve flashed it onto your device there’s a web interface which should make it easy to connect to your WiFi, authenticate your Google account and set up whatever commands you want.

If you do try it, please let me know if it’s useful! Or if you have any trouble getting it working or find any bugs, let me know too.

Next up (and in the same repository above, if you can’t wait), how I control lots of fairy lights. Until then, have fun, and Merry Christmas!

4 October 2014

Geotagging photos with Google Location History

Filed under: Computers — Tags: , , , — qwandor @ 12:14 pm

When I take photos on my Nexus 5, it automatically geotags them, which is great. However, when I am on holiday, I often use a proper camera with a bigger sensor and lens as it can produce better results. The disadvantage of this is that it does not have a GPS so cannot geotag the photos I take. Fortunately, I have Google Location History enabled on my phone, which records my location periodically. I use digiKam to manage my photos, which has a feature to correlate photos with a GPS track by timestamp. Here is how I use this to geotag my photos:

  1. Enable location reporting and location history on phone. In Android this is under Settings→Location→Google Location Reporting.
  2. Ensure camera clock is correct.
  3. Take photos.
  4. Go to the Google Location history web interface, select the relevant days, and click Export to KML.
  5. Convert the KML file to GPX with this GPS Visualizer tool. Unfortunately the converter has a bug: the KML file has a timezone of UTC-7:00 for all timestamps, but the converter ignores this and treats them all as UTC. We will have to compensate for this in the next step…
  6. Select the relevant photos in digiKam, and click Image→Geo-location from the menu. Load the GPX file you downloaded in the previous step. To compensate for the bug mentioned above, you will need to set the camera time zone option to 7 hours ahead of the actual timezone your camera was set to. So if you were taking photos in UTC+2:00, then set it to UTC+9:00.
  7. Click Correlate. Check that your photo geo-locations look correct. If they look wrong, ensure that you got the timezone right. If they look right but some are missing, try enabling the Interpolate option.
  8. Apply and Close. Done!

4 October 2010

More requests

Filed under: Computers, Electronics, Me, music, thequotebook — Tags: , , , , , — qwandor @ 2:34 am

Continuing on from my last post, here are some more topics people requested me to write about.

xyzzy and Craig both want me to write about working at Google. Hmm. Well it is a fairly good place to work. We get free breakfast, lunch and dinner in the office, Monday–Friday, plus there are microkitchens around the place with snacks and drinks. The food is pretty good too. Typically at lunch in the main cafeteria there will be 2 or 3 choices of meat (at various times we have had roast duck, roast beef or lamb, lamb cutlets, beef steak, various kinds of sausages, sausages wrapped in bacon, chicken, turkey, I think there was even kangaroo steak one time), some choice of fish or other seafood, vegetarian dishes, roast and/or boiled potatoes, rice, a range of cooked vegetables, various salads, sushi, a couple of flavours of soup, bread of various sorts, crackers and cheeses, a hot pudding, cakes or cupcakes or other cold desserts, fruit, and a range of drinks. There is a machine to squeeze oranges into juice which is fun to watch. There is not nearly so much selection for dinner unfortunately, and not so many people stay for it. Breakfast is pretty good though. If you happen to be in London, come for lunch! We get to have up to two social guests to eat at the office each month.

Food aside, the work has been fairly decent. It does take a while to get used to all the systems and technologies, as Google have a lot of internally-developed tools and systems that nobody else uses, and have had to put a lot of work into making everything scale bigger than pretty much anyone else. Writing a web application that could cope with being used by everyone on the Internet, many simultaneously, from all over the world, does pose some challenges over just designing something for a few hundred people. I still have a lot to learn. Unfortunately nothing I have worked on so far has been launched yet, and it is unlikely that any substantial part of it will be launched publicly until sometime next year.

Working at a global company with tens of thousands of employees is certainly rather different to working at a small place with between 10 and 20. The ratio of actual developers to support roles (legal, HR, recruitment, management, sales, facilities, and probably many others that I do not even know about) seems to be quite a bit lower. I am not too sure what differences can be attributed to differences between England and NZ as I have only worked at the one company over here. I guess there are more big companies over here though, being a bigger country. I do find that there is not so much chance to chat with my colleagues about anything outside work, though that may be at least partly due to the fact that I knew about half of the guys at Innaworks already before I started working there, though university and Interface.

As for what skills I use from my studies, the data structures, algorithms and complexity stuff was certainly important in passing the interviews and getting the job, though so far at least it has not been all that important day to day.

I think that answers most of Craig’s questions. xyzzy also wanted to know about “some project you’ve embarked upon in your spare time! your take on what really matters in life!”. Unfortunately I have not been working on any terribly exciting projects in my spare time since I moved here. I did just recently order a Bus Pirate, in the hopes of hooking some sort of I2C devices up to my computer and having a play. That has not yet arrived yet though. It is also not clear whether there are proper drivers for it to let it work with the usual Linux I2C infrastructure, or just userland stuff.

I have made a number of updates to theQuotebook in the last month or so, most notably finally getting the new style ready to launch. I am working on a new feature to allow quotes to be added by email, and Twitter support may also follow if I can work out a good way to design it and find a suitable Twitter username that is not already taken.

I also did some work on a web-based client for Fridge a while ago. It is implemented using GWT, and talks directly to the XML-RPC API that the other clients use, so it supports all the same features, including Interfridge. You can try it out if you have an account on the Memphis fridge or any peered fridge.

So what really matters in life? Probably not Slayer. God, I think, though I am not sure quite how. People seem to be fairly important. I wish I got to spend more time interacting with people constructively, perhaps sociably as well. Finding good community and good friends is hard. Knowledge is also important I think. Do more maths, people. And some science if you like.

Before I stop for the now, Richard asked me (twice!) to write about Slayer, so I guess I should do that. Richard seems to be a little bit obsessed with Slayer, though I am sure he would assure you it is purely in an ironic way. I am afraid I do not now much at all about them, so I will be looking up what I can. informs me that Slayer are “a thrash metal band from US, formed in 1981 … credited as one of the ‘Big Four’ thrash metal bands, along with Metallica, Anthrax, and Megadeth”. They seem to choose deliberately controversial topics for their songs, which is not uncommon among such bands. I am pretty sure Metallica are better. Perhaps you can tell us more, Richard?

I think that will do for today. Next up: books, culture and language if I can think of anything to write about them, and probably not a vat of hot chocolate.

18 February 2010

Your fare is Mifare

Filed under: Computers, University — Tags: , , , , , — qwandor @ 9:22 pm

Or rather, your student ID.

I recently bought a Snapper Feeder to have a play with, as I had heard that they were supported by libnfc under all the major operating systems and could talk to a variety of contactless smartcards. I tried any cards I could get my hands on, and other than the Snapper card itself I found that our building access cards were not compatible (using a different frequency, perhaps?) but the Vic student ID cards were recognised. Furthermore, it turns out that these ID cards are MIFARE Classic 4k cards.

Now, this is interesting because encryption scheme used by the Mifare Classic was broken and research published explaining the vulnerabilities as early as 2007, and this is even acknowledged by the manufacturer. Anyway, being the curious sort I am, I went about trying to see what I could see about the Vic student ID cards. I have not yet been able to replicate the card-only crack to recover the keys, but I have had a bit of a look at how the cards are formatted.

Firstly, a bit of background. The Mifare Classic 4k has 40 sectors, each of which has 2 48-bit encryption keys (called A and B) and 12 configuration bits which control which of the keys allow read and write access to the sector’s data and configuration. Each sector is broken down into a number of 16 byte blocks. The first 32 sectors have 4 such blocks (64 bytes total), while the last 8 sectors each have 16 blocks (256 bytes per sector). The last block of each sector is called the sector trailer and contains the encryption keys and configuration bits previously mentioned. Note that the configuration and keys for each sector is independent of all the other sectors. Reading from and writing to the card is done on a block by block basis. Accessing a block is a two step process. First you must authenticate to the sector with either the A or the B key, then you can read or write one of the blocks in that sector.

With this in mind, here is what I have found so far about Vic’s student ID cards. I used the micmd tool, which provides a fairly simple interface to access Mifare Classic cards using libnfc, and a few other bits and pieces. Authentication to all sectors except sector 15 worked using FFFFFFFFFFFF (a common default key) as either key A or key B. However, despite the successful authentication, I was only able to read the blocks of sector 0. (Admittedly I did not try all of the other sectors, but all that I did try failed to read.) This may indicate that these sectors are configured to not to be accessible by either key, as a way of permanently disabling them, or it may be a problem with my reader. The reason I suspect my reader is that it would often lock up after certain operations, not responding at all until I unplugged it and plugged it back in again. I am not sure what is causing this; if anyone has any ideas do say.

Sector 15 appears to be using a proper key, and is probably where the real data of the card is stored.

Sector 0, the one sector I did manage to successfully read, does not appear to hold much of interest. On one card, with a UID of D4 EE 01 6E, the four blocks were

0: D4EE016E55980200648E565165603905
1: 800F0000000000000000000000000000
2: 00000000000000000000000000001248
3: 000000000000787788C1000000000000

Block 0 of sector 0 apparently holds read-only data set by the manufacturer, so is not that exciting. It appears that the first 4 bytes are the UID of the card. The 5th byte also seems to vary between cards (on the 3 cards I tried the values were 0x55, 0x5F and 0x61). The remaining 11 bytes of block 0 were the same on all 3 cards I tried. Blocks 1, 2 and 3 (the trailer block) were also the same on all 3 cards, which suggests that they are unlikely to be interesting.

I did attempt to use the nested authentication attach (I believe) as implemented by mfoc and MFCUK to recover the keys for sector 15, but for some reason both implementations failed, possibly due to the reader ceasing to respond part-way through as mentioned above. Any suggestions on how to get past this are welcomed.

Does anyone have any other interesting smartcards?

4 November 2009

Rubgy, a safe technical topic, and baking

Filed under: Computers, Me, Recipes — Tags: , , , , , , — qwandor @ 10:33 pm

Continuing on from my last post taking suggestions from Twitter, today I will be blogging about topics suggested by people on Facebook.

Allan Chesswas: Rugby

Here in New Zealand, and elsewhere I hear, some people like to run around a field jumping on each other and chasing an oddly-shaped ball. This activity seems to be more popular among boys than girls. Many other people like to watch them do so. Several of my flatmates are in the latter set, and one in the former. I have never seen the attraction of either activity. The running around does at least provide decent exercise, but at significant risk of injury. Watching seems even more pointless, and frequently people do so (via television) instead of partaking in more interesting and productive pastimes such as good conversation, programming, baking, listening to music or even reading. This can be something of a frustration.

Donald Gordon: Safe technical topics which no one will be offended by.

Well. Most of my ‘recreational’ programming of late has been on Fridge. Fridge is a co-operative honesty system for snackfood which originated in Memphis. The Memphis Fridge is something of an open secret, used by graduate students and their friends. The basic idea is that certain people buy pre-packaged food and drink in bulk. Everyone who uses fridge has an prepay account which they can put money into by putting cash in a drawer and crediting their account, and then they can use this balance to buy the food and drink. The software keeps track of users, money, the various items stocked, markups to make up for lost or damaged stock, various statistics, and so on.

I have made a few minor contributions to the Fridge software in the past (such as adding a QIF export feature to allow users to import their transaction history into their personal accounting software), but my substantial work on it now began with interfridge. Interfridge was an idea that I and others had some time ago, last year I think, to allow users on one fridge to use that account on another fridge. This was motivated by the fact that both Memphis and Innaworks (where I currently work) run the Fridge software, and several of us use both fridges from time to time. The idea of interfridge was that I could visit Memphis, login to their fridge with my Innaworks fridge account, and purchase items from Memphis just like any Memphis user.

At some point Donald wrote some notes on his ideas of how interfridge should be designed. I finally got around to implementing this (the server side in PHP as part of fridgeweb, the client side integrated into the Java fridge client) using a protocol on top of HTTP. After much discussion with lorne, Chris Andreae and Stephen Nelson and several iterations changing the protocol to fix potential security holes pointed out, we came up with the interfridge protocol that is now in use between Memphis and Innaworks.

However, we realised along the way that fridge really could do with being improved in other respects. Currently, the Java client talks directly to a PostgreSQL database which holds all the user, stock and transaction data. This means that the client must include the database password, which is really not a good thing to be giving out to all and sundry. A much better design would be to have a trusted fridge server which talks to the database, and then have the client perform all operations via the server. With an appropriately-designed protocol, this means that the client need not be trusted, and so anyone can write their own client to use with the fridge. I have thus begun to design and implement a fridge protocol based on the interfridge protocol (it can do everything the interfridge protocol can do and more, so will replace it when it is done). For this I scrapped the custom RPC protocol which I had been implementing for myself on top of HTTP, and went with XMLRPC to take care of all the details of procedure calls, encoding and decoding in a standard way. There are various implementation of XMLRPC available for many programming languages. I should note that the documentation linked above does not include all of the API currently implemented in the code, though it will eventually. I am currently still in the middle of designing it, implementing and documenting it at the same time.

As it currently stands, the fridge server has methods to login, check a user’s balance, transfer an amount to a local or remote (i.e. interfridge) user, make a purchase at the local fridge (I still have not yet decided the best way to handle interfridge purchases in the new scheme), list the current stock, and list other fridges with which the fridge is peered. I am writing a client library and simple command-line client in Ruby to test this as I go. The command-line client implements all the features just mentioned. I have not yet done much on the Java client, but that will come at some point. lorne has just started work on an iPhone client, which should be cool.

Felix Shi: You can always blog about cooking weird and wonderful dishes 😀

Weird and wonderful? Not sure about that. I made a batch of muesli and a chocolate cake on Sunday, as I mentioned. The weekend before I baked two batches of muffins (apple and sultana for the Skyline walk on Saturday, banana chocolate chip or something for a picnic on Labour Day with gringer, ja and xyzzy).

I am afraid my cooking of late has not been terribly interesting. Suggestions are welcomed, as are visitors interested in consuming baking. As always.

Fixing VMware mouse grab bug on Ubuntu Karmic

Filed under: Computers — Tags: , , , — qwandor @ 9:23 am

I just upgraded my work machine from Ubuntu 9.04 (Jaunty) to 9.10 (Karmic) and came across a couple of problems with VMware Player (version 2.5.3 build-185404). It seemed wise to document the fixes I found here so that other people experiencing the same problems might find these solutions when they Google for it.

The first was an error when it tried to launch my VM complaining that the virtualisation extensions of my CPU were already in use, saying “The virtualization capability of your processor is already in use. Disable any other running hypervisors before running VMware Player.” and then a number of other errors. This was fixed by removing the KVM kernel modules:
$ rmmod kvm_intel kvm

The second problem was that the VMware window would lose its mouse capture whenever I moved the mouse pointer outside the top-left of the VM screen (apparently a 640×480 region), unless I had a mouse button held down. This made it impossible to actually use the VM. This was eventually fixed by adding the following line to /etc/vmware/bootstrap:
This forces VMware Player to use its own version of the GTK library rather than the Ubuntu one, which apparently avoids the mouse grab bug.

8 September 2009

An idea for songfighting

Filed under: Computers, music — Tags: , , , , , — qwandor @ 11:14 pm

I was walking to work yesterday, and I had an idea.

Perhaps you have heard of SONG FIGHT. If not, the idea is fairly simple: each week, a song title is given. Competitors then have a week to write the words and music for a song fitting that title, record it, and submit it. Anyone can then download the songs, listen to them and vote for which they think are best. I guess the main point is to motivate musicians to write more songs, to improve their skills and whatnot.

Anyway, my idea is to automate the process. I want to write some software that, given a title, can produce a half-plausible sounding song matching it. The first step would be to generate the lyrics, which I guess could be handled by an approach based on Markov chains trained on a range of existing song lyrics, probably combined with some sort of syllable and rhyming dictionaries to produce lines with some sort of rhythmic structure. Hmm, perhaps the rhythm should be generated first and then the lyrics made to fit it. The title would be included in one of the lines, probably near the beginning or end, or even several times in the chorus.

Next (or perhaps first), it would be necessary to generate some sort of plausible tune for the verse and chorus, and any other bits in-between (bridge? intro? instrumental bit in the middle?). I am not sure how to approach this, perhaps there is some literature on the subject. Maybe more Markov chains, or some sort of recombination of existing tunes, or some other method. I could really do with some advice from musicians here: how do you put together a tune that actually sounds tuneful, rather than just a list of random notes?

I assume that once the basic melody is generated, generating a passable accompaniment would be relatively straightforward, though again I will need to talk to some musicians.

Once the music and lyrics are sorted, along with an arrangement for the song, producing the final product would be a matter of running the lyrics and melody through Festival’s singing mode (as I have played with before), synthesise a few instruments and some drums for the rest of it, and mix it all together, ready to submit. Simple?

Anyway, reactions? Does this sound plausible? Has it all been done before? Can you offer any advice, especially for the musical side of it?

17 August 2009

An interesting tale of filehandles

Filed under: Computers — Tags: , , , , , , , , , , — qwandor @ 10:25 pm

I just found an interesting bug, so I thought it might be worthwhile to share it with these intertubes to prevent other people from making the same mistake.

I was just transferring some more music onto my iPhone with Amarok while at the same time listening to music. I wanted to listen to a particular track (from a Moby album I bought recently), so stopped and switched to that, but Amarok would not play it and complained about the sound device being busy. This seemed rather odd as it had just been playing fine until I tried to change tracks. Wanting to get to the bottom of this, I checked who had what open:

andrew@rata:~$ sudo lsof /dev/snd/*
lsof: WARNING: can't stat() fuse.sshfs file system /media/iphone
Output information may be incomplete.
timidity 4162 root 6u CHR 116,1 4973 /dev/snd/seq
kmix 4511 andrew 10u CHR 116,0 5260 /dev/snd/controlC0
ssh 5605 andrew 16u CHR 116,0 5260 /dev/snd/controlC0
ssh 5605 andrew 33r CHR 116,33 4954 /dev/snd/timer
ssh 5605 andrew 39u CHR 116,16 5236 /dev/snd/pcmC0D0p
ssh 5605 andrew 41u CHR 116,0 5260 /dev/snd/controlC0
sshfs 5609 andrew 16u CHR 116,0 5260 /dev/snd/controlC0
sshfs 5609 andrew 33r CHR 116,33 4954 /dev/snd/timer
sshfs 5609 andrew 39u CHR 116,16 5236 /dev/snd/pcmC0D0p
sshfs 5609 andrew 41u CHR 116,0 5260 /dev/snd/controlC0

I should point out at this point that the way I get Amarok to sync music to my (jailbroken) iPhone is to FUSE-mount the iPhone via SFTP over the network, so that is why SSH was running. But on with the story.

SSH had my sound device open‽ What? That seemed very odd. I wondered whether perhaps there was some new SSH feature I had not heard about to forward sound over the network connection (as it can do for GUI applications using X11), but there I could find no mention of such a feature in the manpage or via Google, nor any possible reason why it might want to open a sound device. I asked lorne, and he was equally confused, but suggested a few things to check.

After a bit of poking around I discovered that I could not replicate this behaviour by mounting the filesystem myself, only when Amarok did it. This prompted a realisation of what must be happening: when Amarok launches sshfs to mount the iPhone filesystem, it presumably does a fork and exec to start the new process. But when you do this, the new process inherits all the open file handles of the parent process. Amarok of course had the sound device open to play the music I was listening to originally, so sshfs and subsequently ssh ended up with the same device file open. Amarok must then have closed it and tried to reopen it when I switched tracks, and this failed because the other processes it had launched still had it open. Of course.

So, lesson of the day: when you fork, remember to close any excess files before you exec. Especially if they are device files or other special files.

I should probably file a bug report for Amarok, but I am not sure that I can be bothered.

30 July 2009

Juvenile humour

Filed under: Computers, Humourous, Lists — Tags: , , , , — qwandor @ 9:32 pm

It turns out that if you take the title of a book and append the phrase “in your pants”, the resulting title is often more amusing than the original. Here I present you some examples:

About the Size of it: The Common Sense Approach to Measuring Things in Your Pants
The Adventures of Huckleberry Finn in Your Pants
All About Worship: Insights & Perspectives on Worship in Your Pants
Being Human in Your Pants
Calculus: A New Horizon in Your Pants
Computer Networking: A Top-down Approach Featuring the Internet in Your Pants
Computer Organization and Design: The Hardware/Software Interface in Your Pants
Coping with Controversy in Your Pants
The Diamond Age: Or, a Young Lady’s Illustrated Primer in Your Pants
Dick Smith’s Fun Way into Electronics in Your Pants
God’s Undertaker: Has Science Buried God in Your Pants?
The Snow in Your Pants

For some automated humour, I have just written a little script that will transform the titles of your books most recently added to LibraryThing in similar manner. Take a look at what it does for my books, or try it on your or your friend’s collection.

Oh, and on the topic of pants, if you have not read Star Wars pants quotes, perhaps you will be amused to do so. I cannot find the original site that I remember from years ago, but they are still funny. The premise is to take a line from Star Wars and replace one word with the word ‘pants’, thus improving the line.

Well, it is said that small things amuse small minds.

Older Posts »

Blog at