Pointer Tagging in Go

Let’s say you’re an idiot. You didn’t know about the interface{} type in Go. You didn’t know about switch foo.(type) {} in Go. Now you want to do something really fancy, like interpreting integers as floats (why would anyone do that?). Maybe you just want to circumvent the very excellent type system in Go. Or maybe you want a much faster type switching/assertion in Go. Or maybe you’re just a bit nuts.

[Read More]

etaoinshrdlucmfwypvbgkjqxz

My previous blog post must have lead many readers of mine (hello to the both of you) into thinking I had gone mad. I hadn’t. It must have been maddening, what with self-linking posts and complete and utter gibberish. This is the story of how I dreamt up an encoding for the English language.

I had been lying in bed, late last night, thinking about my own perception of time and space. I have often convinced myself that I perceive time and space rather differently than most people. Last night was one of those nights. I had an imaginary conversation with people in my mind, explaining how I perceive time and space. I gave an example: imagine a spoon falls from a table. Rather than perceive the motion of the spoon falling, I would often perceive it as a solid block between the table and the floor. The solid block would be in the shape of the trajectory of the spoon falling.

Now of course this is all mental. It’s an additional layer of processing my brain does for some odd and undocumented reason, and only under certain mental circumstances (for example, when feeling extremely relaxed). But it’s a good way of explaining to people how I very occasionally perceive time and space.

I then began to think about writing. Our writing is very much based on a deterministic pattern. If I write the rune ‘A’, I would expect the rune to only represent one alphabet (‘A’). What if, however, a rune would represent all possible representations? A good way to frame this would be to think: when you put a pen to paper, at that point an infinite possibilities of runes that could be drawn exists. As you draw more of your rune, the number of possibilities drop until you have a rune that represents one alphabet. Imagine if you will, a person who is able to see a lot of the possibilities would draw a rune that represents all those alphabets. Perhaps this clip from Fringe would help:

And as I thought about it, I too thought about ETAOIN SHRDLU. What if we could encode a rune based on its possibilities? ETAOIN SHRDLU provides a very good basis, given that it’s the frequency each letter is used in the English language. So, the question became: what if we could encode multiple letters into a rune and make a language out of it?

The thought stayed with me for the whole day and after work today, I decided to write a quick and dirty script to encode and decode into this language. To give it some extra mystique, I picked out 26 utf-8 symbols to form the basis of this encoding. Although there are 26 symbols, they do not map 1-1 to the English alphabet – as such, statistical analysis will not yield much. I’ve actually had some difficulties in writing the decoder myself!

This blog post will explain how I did it.

[Read More]

Why 1 && 2 == 2

This question was bugging me for a bit and I spent about 3 hours researching it: What is the result of the logical operation of 1 AND 2? Conversely, what is the result of the logical operation 1 OR 2?

Clearly upon first look, this doesn’t make any sense to evaluate in a vacuum. In normal English, if someone were to ask you “1 AND 2 equals?”, you’d probably reply “3”. Then the OR version of the question is asked… and then it devolves to non-sense. Formal logic, however, does provide us with some explanations. Everyone is familiar with the truth table:

P Q P AND Q P OR Q
TrueTrueTrueTrue
TrueFalseFalseTrue
FalseTrueFalseTrue
FalseFalseFalseFalse

However, True and False are boolean values. Under the principle of bivalence, there can only be two truth values: True or False (in computers, they’re encoded as 1 or 0). I’m not going to discuss the philosophy of logic, so for the rest of this blog post let’s just accept that the logical operators AND and OR (generally) operate on boolean values.

[Read More]

An Aversion To Ship

I have a confession to make. It had been slightly more than a month since I last committed any code to Fork the Cookbook. In fact, the whole team hadn’t contributed to Fork the Cookbook in about a month. Only the scant updates here and there. If you were to have a peek into what we were doing, you would think it was abandonware. Only that it wasn’t. For two weeks now, I have been actively writing code for Fork the Cookbook again. [Read More]

Programming Languages as Driving Experiences

So we were just having a chat about programming languages. I was telling my friends, coming from C/C++/Python, how wrong javascript felt, despite having worked on node.js before. PHP felt the same.. something is just… off about those languages. So we decided to compare programming languages to driving cars. Here’s how we compared them (these are the languages we know and have written in them): Programming Language Feels like... C driving a old powerful manual sports car C++ driving a newer model of a powerful sports car. [Read More]

Random Documents from CouchDB

A few days ago I tweeted this:

I was finding ways to return a random document from CouchDB. At a former project at Pressyo we had used emit(Math.random(), doc), but I wasn’t quite happy with it — mainly because I had convinced myself through a small number of experiments that I could actually predict the random numbers that were being emitted (Spidermonkey I am giving you so many ಠ_ಠ now). Anyway, the conclusion was I wanted to find a better way of returning a random document (or more) from CouchDB.

[Read More]

How Long Before 1st Accepted Answer on StackOverflow?

I had started work on a new project recently. After committing about 200 lines of code, I decided to check HN to reward myself. It was then I found Guillermo Winkler’s blog post about programming languages on StackOverflow. It was quite an interesting analysis. I read it and went back to work. But I couldn’t quite concentrate. My inner statistician was whinging. It thinks that Guillermo didn’t answer the question. And my inner statistician wasn’t satisfied. [Read More]

A Better Passenger Boarding System (BTW, Jetstar Sucks)

TL;DR: The fastest method of loading passengers onto a plane is to group passengers based on the oddness/evenness of their seat row numbers. Board passengers with odd numbered rows through one door, and passengers with even numbered rows through another door.

I went to Melbourne last weekend for GP Melbourne (don’t ask – I lost badly). But I very nearly didn’t get there. My flight was originally at 5pm, so at 2pm, I decided to do a web check-in. To my surprise, I found that Jetstar had changed my flight from 5pm to 11pm without actually telling me. I checked all my email archives, and I had not received any communiques aside from their stupid weekly sales email. I had a dinner meeting in Melbourne at 8, it was unacceptable that I leave Sydney at 11pm. So I called Jetstar, and after a frantic 40 minutes, I managed to get my flight changed to 7pm. I had still missed the meeting though.

Anyway, so I was at the airport, having had 2 hours sleep the previous night, waiting, half asleep for my flight. Then came an announcement – that there was going to be a delay in the flights. I felt slightly frustrated, but I was short of sleep and felt tired, so I didn’t bother. When it came to boarding however, I was surprised, as Jetstar had changed their boarding method. I thought about it for a while and then I tweeted about what I thought to be Jetstar’s inefficient boarding method:

Despite that, I did work on a simulation while on the flight. I fell asleep after the first few lines of code of course, but on my trip back from Melbourne, I completed the code but never actually ran it… until today. You see, I didn’t think about it for a while until yesterday and today, when I received a number of Twitter mentions. I hadn’t checked my twitter mentions earlier, and hadn’t noticed Jetstar actually replied to my tweet:

[Read More]

Appearances Matter (Ergonomically)

I’ve been writing code quite a bit lately. I used to be the kind of guy who would work on any IDE with any appearances because they didn’t matter much to me. I would code with the default IDE themes (from Visual Studio to Eclipse to Aptana). But then, something changed. I became the guy who tells everyone: appearance matters (I still have colleagues at work using the default Visual Studio theme) [Read More]

Dynamically Loading Content in Twitter Bootstrap Tabs

Achtung! This is an old post, written before Bootstrap was in 2.0. The current version of Bootstrap is 3. You probably do not want to use this. The general idea is still the same though. I highly recommend reading Jake Spurlock's book on Bootstrap and the Bootstrap documentation instead, and use the basic principles of this post to figure it out on your own.
So, today's blog will be slightly off the norm. I had been working on a project for some time, and over the weekend, we had decided to port it over to the very excellent Twitter Bootstrap from JQueryUI. With a new framework, comes new learnings. You see, in JQueryUI Tabs, you could dynamically load your tab content with this: [Read More]