Thoughts of a geek

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.

Advertisements

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.
COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME
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.

14 August 2009

Things I should do

Filed under: Lists, Me — Tags: , , , , , , — qwandor @ 10:59 pm

I have been a bit slack lately about getting much done. I keep thinking of things which I should do, but mostly do not get around to doing them. In the hope of improving this I list here some things which I should do:

  • Implement mDNS abstraction layer for stereo using Avahi DBUS bindings, sort out ant script, and get stereo head to a usable state on Linux. (Or, bug Stephen to do it.)
  • Write various blog posts I have been thinking about (last.fm client, friends, childhood memories, more to life, questions).
  • Work on theQuotebook, maybe look into Facebook integration.
  • Do more baking.
  • Catch up with various people I have not seen for ages.
  • Work out what to do for a chassis for the robot I am building, add the remaining wires for the motor controller, and filter capacitors.
  • Talk more to people about conceptions of God (relationship, hearing from God, basis of faith…), and maybe blog some thoughts and questions.
  • Organise a group of people to do the Skyline Walkway some Saturday.
  • Work out what I am doing with my life, what I want to do and what God wants me to do, where I am going in the mid- to long-term, what to do next year…

Feel free to bug me about doing any of these things. Or maybe other things.

1 June 2009

Happiness

Filed under: Me — Tags: , , , , , , — qwandor @ 12:45 am

Sometimes I am happy, often I am fairly neural, and sometimes I am unhappy.

When I am happy I tend to be inspired to work on things (or start new projects), to make the effort to talk to people, and even to be somewhat sociable.

When I am unhappy I tend to be unmotivated, not do much, take long walks in the middle of the night or just sit or lie around feeling sorry for myself. I suppose I think more about myself and less about other people.

Anyway, I have given a little consideration to what tends to make me happy. One of the main things, I think, is making things which other people like and appreciate. Some examples of this are:

  • I have been doing some work lately on a robot which lorne and I want to make. Trying to get an IO expander working with a Meraki over I2C, programming a PIC to talk to the Meraki, getting parts to build H-bridges, that sort of thing. Having him appreciate how cool it is, and get excited at the little achievements along the way (I2C is working, I just needed to add pull-ups! The PIC is running fine off 3.3 V now, disabling BOREN did the trick!) helps me to keep motivated. Working on a project with smart people is fun!
  • It is nice that people are using and apparently liking theQuotebook. It took a lot of work to get it to the point where it now is, and there are still many more things to be fixed, added and improved. What I have really liked though is when friends have taken the time to try things out, think about it, say what they like and dislike, and sometimes offer suggestions. Thanks to shoeshine, Melanie, Josh, Valerie and anyone else who has made suggestions or comments.
  • I like it when I bake stuff and people like it. Be it muffins, or the steamed pudding (with custard) which I made tonight and my flatmates consumed, focaccia bread yesterday, the apple scotch I made for the pot-luck we had at my lifegroup quite a few weeks ago (though it got quite burnt; I should never have let myself be persuaded to put it into the oven).

I guess a big part of this comes from just wanting to feel appreciated, or at least acknowledged, by people about whom I care. For similar reasons I guess, I appreciate it when people make the effort to talk to me, email me, ask how I am, even spend time with me. Certainly, I tend to find that talking to people can make me happier, when I can manage it. Or when someone makes the effort to talk to me even though I am frustrated or irritated and unsociable and hard to talk to.

There is still a fair bit about what effects my mood that I do not understand though. Sometimes I am just unhappy or unmotivated for no particular reason that I can see; on the odd occasion I even find myself happy for no reason I can discern.

Oh, and I really enjoyed contradancing the weekend before last at the St. Michael’s fundraiser, once I got into it anyway. I am not sure how that fits in. Probably something to do with the combination of live music, positive social interaction and physical activity. Thanks, Stevie and Allan, for dragging me along.

Create a free website or blog at WordPress.com.