Isle of Tune

Isle of Tune is a music sequencer where roadside elements are your instruments, roads are your tracks and cars represent the position of the track.

Low beat loop

Be sure to check out the top 50 islands, especially the Beat It island

Building strings in Ruby

The most common way of building strings in Ruby is to use the spade operator (<<) to modify an existing string by appending other strings to the end of it. The spade operator is preferred over += since the latter will create a new object every time it's called.

In some situations, though, I prefer a different method of building strings.

Let's say we want to build a URI that will carry out an advanced search on Wikipedia. The ingredients that we have are the hostname, the base URI and the parameters for the query string.

host     = "en.wikipedia.org"
base_uri = "/w/index.php"
parameters   = {
  "title"    => "Special:Search",
  "redirs"   => "1",
  "search"   => "Ruby",
  "ns0"      => "1",
  "advanced" => "1",
  "fulltext" => "Advanced+search",
}

How do we go about building the query string itself?

One way would be to iterate through each of the elements in our parameters hash and append each one to a string, separating the key and the value with an '=' character and separating each pair with an ampersand.

Let's write a querystring method to do that:

def querystring(p)
  query_string = ""

  p.each do |key, value|
    query_string << "#{key}=#{value}&"
  end

  query_string
end

That gives the following output:

querystring(parameters)
# => "ns0=1&title=Special:Search&redirs=1&advanced=1&fulltext=Advanced+search&search=Ruby&"

There are a few problems with this code though.

  • We have to initialise an empty string.
  • We have to mention the string at the end of the method, since without it params would be returned.
  • We get a trailing ampersand in our query string.

We could work around that last problem, but that would make this method more complex. If you're familiar with functional programming, or even the functional elements of Ruby, then a cleaner solution will probably seem obvious.

Enumerable's collect method accepts a block as a parameter and then goes through every element, running that block against each element, then returning a new Array. We can make use of collect to turn our params Hash into an Array where each element looks like "key=value".

parameters.collect do |key, value|
  "#{key}=#{value}"
end
# => ["ns0=1", "title=Special:Search", "redirs=1", "advanced=1", "fulltext=Advanced+search", "search=Ruby"]

Now that we've got an Array that looks like this we can make use of Array's join method to create a string containing each element in the Array separated by an ampersand:

parameters.collect do |key, value|
  "#{key}=#{value}"
end.join "&"
# => "ns0=1&title=Special:Search&redirs=1&advanced=1&fulltext=Advanced+search&search=Ruby"

We can change our querystring method to make use of this technique:

def querystring(p)
  p.collect do |key, value|
    "#{key}=#{value}"
  end.join "&"
end

querystring(parameters)
# => "ns0=1&title=Special:Search&redirs=1&advanced=1&fulltext=Advanced+search&search=Ruby"

Now we've addressed all the problems raised before:

  • There's no need to initialise an empty string
  • We don't have to force the string to be returned since Array#join returns the string we want.
  • We lose that trailing ampersand without having to add any conditions to our code.

Understanding Pac-Man Ghost Behavior

The first article on GameInternals is about how the ghosts in Pac-Man make decisions about where to go next. I've known that each ghost has its own algorithm for some time, but this article was really interesting.

This promises to be a fascinating site.

(Via Hacker News)

Cadence & Slang – a book about interaction design

Cadence & Slang

I like the look of this book on interaction design by Nick Disabato.

Photo copyright him.

Spacelog – stories from the transcripts of early space exploration

Apollo 11 logo

Spacelog is a project which aims to take the original transcripts from space flights and turn them into stories. It's well designed and the photography used on the site is excellent.

I especially like that you can link to specific sections of a transcript.

The difference between UK and US Mac keyboards

When I visited New York a couple of years ago I bought a wired keyboard for my Mac, not realising there would be any significant difference between UK and US keyboards.

As it turns out I actually prefer the US keyboard.

My friend Mike was asking me about the differences between the two keyboards so I decided I would demonstrate with the following picture:

UK (top) and US (bottom) keyboards

The UK keyboard is on the top and the US keyboard is on the bottom. The UK keyboard is wireless, so that's why the keys are squished together in places.

To get the meaningless differences out of the way first: Since my region is set to 'UK' the 2 and 3 keys (highlighted in yellow) behave the same no matter which keyboard I use. I don't recall ever using the extra key on the UK keyboard, highlighted in orange.

The biggest difference for me is the location of the backtick key, shown in pink. ⌘ + ` is the key combination to switch between windows within the same app. On the UK keyboard this key is too close to the shift key, and means left shift is tiny. On the US keyboard it is in an ideal location, above the tab key.

Lastly is the return key. On the UK keyboard the key is vertical while on the US keyboard it is horizontal. Since my fingers move left to right much more than they move up and down having a vertical return key is like building a runway that is wide instead of long.

Guild Wars Profession Icons

A few years ago I was heavily involved in the Guild Wars Wiki, and before that I had been involved in the unofficial GuildWiki (now a Wikia site).

Among the many things that I contributed to both projects was a set of icons for each profession in the game designed using the Tango icon guidelines.

Guild Wars profession icons

Here's the original SVG.

Piknik fullscreen colour picker

Beautifully executed fullscreen colour picker.

Horizontal mouse location controls the hue, vertical controls the saturation, and scroll wheel (if you have one) controls the luminosity.

1,024 Tweets

Today marks my 1,024th tweet! That's 210 tweets for people that aren't constantly thinking in 2n.

A bit of analysis. My first tweet was on the 18th of March 2007:

Visiting my parents on Mother's Day

Since then I've made approximately 0.79 tweets per day, but I took a long break after it became obvious that I didn't know what Twitter was about, and since the 5th of April 2008 I've made about 1.08 tweets per day.

I've done some basic analysis of the language I've used.

It turns out I've used the word 'I' about 364 times and the word 'you' only about 167 times. I've said 'thanks' 42 times.

I use emoticons a lot. I've used ':)' 139 times, ':D' 94 times, ';)' 51 times, ':P' 40 times and, unfortunately, ':(' 25 times.

The proper noun that I have used the most is the word 'work' 41 times, followed by 'today', 'awesome', 'twitter' and 'nice'.

The ten people that I've mentioned the most, and the amount of times I've mentioned them are:

The first four names aren't too surprising, although I didn't realise I'd mentioned @bexor quite so much.

@mr_urf and @keavy are fairly recent additions to my timeline so I was pleasantly surprised to see them so high up on this list.

One person I expected to be in the top 10 but wasn't was @Daily_Madness. I shall have to remedy that.

Browsing through old tweets I came across some retweets that I was particularly fond of.

On Jeff Atwood and github:

@pjhyett: the more @codinghorror badmouths github the more people signup and realize he's doing open source wrong. keep it up!

On the iPad:

@mikos: When they're invented, will everyone refuse to buy a hoverboard because they don't have a camera?

On version control:

@millerdl: when your last commit message is "fuck", you know something's gone wrong...

To those of you on my timeline, thanks for making Twitter a more interesting place. See you again after 2,048 tweets! :)

Final Fantasy: The 4 Heroes of Light is super cute

Sixteen class designs from Final Fantasy: The 4 Heroes of Light