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.
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 |
|---|---|---|---|
| True | True | True | True |
| True | False | False | True |
| False | True | False | True |
| False | False | False | False |
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
Programming Languages as Driving Experiences
Random Documents from CouchDB
A few days ago I tweeted this:
I started the night trying to get couchdb to return a random document. I found myself writing a mersenne twister instead
— Chewxy (@chewxy) November 13, 2012
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.
How Long Before 1st Accepted Answer on StackOverflow?
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:
This method of boarding the flight is inefficient. Off the top of my head I can think oof at least 1 better way. #jetstar
— Chewxy (@chewxy) March 30, 2012
If I werent so sleepy I'd work out the math to show that this method of boarding can be improved. #jetstar #fail
— Chewxy (@chewxy) March 30, 2012
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]@chewxy Sorry to hear boarding is a bit slow. Please send details of your method to our Customer Care Team: http://t.co/yNEdKbmS We'd (cont)
— Jetstar Airways (@JetstarAirways) March 30, 2012