On Macs

mac-miniI had to use a Mac today at a client office. As far as I could tell, it was a 2009 Mac mini running Snow Leopard on a widescreen. It had a standard Apple mouse and keyboard. Disclosure: I’m not anti-Apple. I am pro-good-computing, so any sensible, usable system is fine by me. I frequently toy with the idea of buying a Mac mini, and I’m aware that a lot of devs use them.

My task was to log onto an FTP server, download some files, and modify and reupload an .htaccess file.

  • First, I downloaded Transmit using Safari. This is easy enough, except that Safari doesn’t maximize? You press the green button on the window, and it just centers itself and gets a little bit bigger. How do you maximize?
  • Additionally, when typing in addresses (or editing text anywhere) there are no Home or End keys. That’s fine, for simplicities sake, but anyone who writes prose or code on a PC uses those a lot. I try Ctrl+Arrows, Alt, Cmd… nothing does what I need. In fact, Cmd+Right inserts a capital ‘C’. Obviously. Now, if the Mac intelligentsia would like to argue that I’m just Doing It Wrong™, I’d like to point out that if it’s inconsistently applied, it doesn’t exist. It doesn’t matter. This stuff is OS level in Windows, Linux… even QNX on my Playbook!

Anyway, I opened Transmit. I realize this is the application’s problem, but the visual cues for how to do stuff are not clear. There are random plusses and stars where you don’t want them, to favourite and save things. At some point, I think I pressed Cmd+T on the offchance it would open Terminal, and it re-based me and pretended that a subdirectory was my root directory, and cleared the navigation breadcrumb so I couldn’t get back to website root. Whatever, I just restarted it.

So I’ve downloaded the stuff. I open Finder and navigate to the file… Oop! I instantly recognise that the file is hidden because it has a leading dot (and that’s how hidden files work on UNIX) so I pop into the easily-found ‘folder view options’ dialogue. Weird, there’s no tickbox for displaying hidden files, and I can’t see any other relevant settings pages.

That’s ok, I’ll do it in Bash (this should be a clue that something is wrong with the GUI). I figure out from something I heard once, and the visual cue, that the magnifier in the top right is Spotlight. Why does the Mac mouse move so sluggishly at low velocities? It’s difficult to target small buttons compared to IBM equipment and Windows/Linux. At this point, I wish I knew the keyboard shortcut for Spotlight.

I type ‘Term’ and hit enter – this works as I intuit, and the Terminal opens

$cd Documents/ftp
$ls -a -l

Oh good, I can see the file now. To try and discover the default plaintext editor, I put a few combinations in spotlight: ‘note’, ‘text’, ‘edit’, ‘pad’. I find ‘textedit’, so, in the console:

$textedit .htaccess
"No such thing as 'textedit', or words to that effect"

Ok whatever, I guess it doesn’t execute from /usr/bin or something. Fingers crossed OSX ships with vi

$vi .htaccess

Yay! The file opens in the primitive editor. Well done Apple for sticking with the old stalwarts of software (it was released in 1976). Using my novice vi proficiency from a half-term spent writing C on Linux, I edit the file, save and exit (that’s ZZ with no colon)

I re-upload the IP whitelist and all is well. Great, good. That whole experience was a huge pain in the rear, to be honest.

Back at the office, I realised how blindingly fast I can use Windows. Most of that is familiarity, knowing shortcuts, and customization. I open Notepad++ by hitting [Win+R np Enter]. I open Explorer with [Win+E]. Still, I feel like using a Mac is so slow. It’s partly the mouse driver’s fault, and mine for not knowing the shortcuts for Spotlight, opening Finder… I remember now I could have Cmd+Tabbed between windows, as picking them off that dock thing takes forever.

Also, I really enjoy the multitouch hierarchy on Lion (and Mavericks, I guess). 4 fingers for OS level, 3 fingers for application level, 2 for meta-document, and 1 finger for document. That’s brilliant; it’s just a different way of thinking. But I’m pretty sure I’d have the same sucky gripes if there was no touchpad. This OS is made for multitouch and it doesn’t work without it.

I eagerly await your commentary.


Introducing Coded for Windows Phone 8

Sometimes you want to edit a code snippet on your phone.

On Windows Phone, there wasn’t an app capable of letting you get a file made on another device, edit it in a code-friendly environment, and then put the file back where you got it from.

That’s why I made Coded!

Give it a try :)

Coded Editor Screen

Main Screen

This is my first app for Windows Phone, but I took a long time polishing it to make it as usable and smart as possible. There are some text editors for WP, but they lack two things:

Sync screen

Sync screen and menu

A “fixed-width” (or “monospace”) font. Examples are Courier New, Consolas, and DejaVu Mono. Every character in these fonts is the same width, which means that columns line up, making code more readable. It also means that tabs are always the same size, and a predictable number of spaces will equal a tab.

Secondly, the ability to import and export files to a web location is key. It’s no good being able to write a file if you then can’t do anything with it. Coded has SkyDrive integration to let you upload/download files from a ‘Coded’ folder in the root of your SkyDrive. In the future, this path might be configurable.

If many people download Coded, I would like to add more features and configuration. If you have Windows Phone 8, and you feel like it might be useful to you, I hope you try it!

Understanding protocols by designing one

This is an article I originally added to our tutor group wiki to help one mature student understand network protocols. This guide does not include any programming.


A protocol is an agreed way of communicating, but it is less like a translation service and more like a language. I think the best way to learn this may be imagining that you have to invent a protocol.

Imagine you’re making a social game where players can move left or right on a 2D landscape, and also chat to each other.

As we know, there is a client part and a server part to networking (usually). In computer networking, protocols are defined in terms of packets; their IDs, and their payloads. When developing the protocol specification, you decide that there are the following data that need to be transmitted:

  • Move
    • Left
    • Right
  • Chat
  • Login
  • Logout

So you want to define a language that transmits this data efficiently. Notice that all of these basic activities require some parameters:

  • Login: Username? Password? Spawn location?
  • Logout: Quit/error?
  • Move: Left/right?
  • Chat: Message?

Now, when you want to do one of these things, the client need not transmit the name of the action to the server, because it would be overkill. There are only a limited number of options for what it is possible to do.

Transmitting “Move” or “Logout” requires n bytes where n is the string length, and the length is unpredictable for the recipient (“Move” is 4 letters, “Logout” is 6) unless you “Length-prefix” it (send a byte straight before to tell the server the length).

So, we create a protocol for shorthand sending and receiving of these messages. Let’s look at an example client protocol:

PacketID Meaning Parameters
00 Login Username (length prefixed string); Password (length prefixed string); Spawn location (byte)
255* Logout Quitting? (boolean)
01 Chat Message (length prefixed string)
02 Move Left? (boolean)**

*It’s convention for 255 (hexadecimal ‘ff’) to be logout – this is the highest value a byte can hold.

**This is the smallest way of transmitting this data. Your direction can be one of two values, so why transmit it as anything larger than 0/1? In this example, 1 = left, 0 = right.

Example client data transmission:

(N.b. I’ve put the numbers in binary to give an accurate representation of space savings and wasted length; an empty byte is 00000000 – spaces are added here for readability and would not be transmitted)

00000000 00000111SteGriff00001000password00000001
00000001 00001000Hi guys!
00000010 1
11111111 0

Above: A player logs in, says “Hi guys!” to the other players, moves left one step, and then his game client crashes without him quitting properly via the ingame menu.

The protocol refers to the fact that the server is developed to “understand” all of these signals, they are a pre-agreed format of communication.

How does one side know that a packet has finished?

Because it’s contents and their length are regulated. This is the one of the reasons for a protocol. When the server gets an 02 it says, “Look, it’s a chat packet! That means now I know what to expect: a number, then I read that number of bytes for the guy’s message. Then I’m done with this chat packet, and I can wait for the next packet from my other clients :)”

Let’s look at the server

One problem might be apparent, and that is that if the server just re-transmits all these “move” signals, every client is going to be VERY BUSY trying to keep track of where things are on the screen, and if a move packet is lost, players will appear in different places on different screens and none of them may be accurate.

Therefore, the server has a different transmission protocol, which the clients are programmed to process. Example:

PacketID Meaning Parameters
00 Login response Accepted? (boolean)
255 Kick Reason (length prefixed string)
01 Chat User (lps) Message (lps)
02 Location User (lps) Location (byte)

When a user attempts to log in, the server validates their password, and throws back 1 if they may proceed, or if they may not, a 0 and a severed connection.

The counterpart to quit is kick. The server owner might decide that a player is being inappropriate and send them a packet like:

11111111 00010100No swearing, please.

This is purely informational, the client doesn’t accept its fate and close itself down – the server subsequently drops the connection to that client.

When the server receives a chat packet, it sends a packet to every player with the speaker’s name* and a message.

00000001 00000111SteGriff00001000Hi guys!

*This is a bad way of doing it. Ideally, when a new user logs in, the server should tell everyone to add a player to their register, with a UserID associated to a PlayerName. You’d reserve a packet ID for this. This means that instead of broadcasting the name “SteGriff” everytime, you can just send binary 244 (assuming I’m the 244th player). This optimises repeated 8 byte transmissions to just 1 byte. Then every client says “oh yeah, player 244 is SteGriff; he must be talking.”

The solution to our move problem

So what about the player ‘ghosts’ in higgledy-piggledy places?

The server should’t pass on the change in location – rather, the players’ actual, absolute locations in the game world. So, if user ‘Tommy’ moved to space 131 in our game world — the last thing he sent was a packet meaning “move right” — the server updates the location it has on record for him, and tells everyone:

00000010 00000101Tommy10000011

…”Tommy is now at location 131″. Every client receives this, and draws him in that position. Because they were updated on his previous positional moves as well, hopefully they just see him making smooth progress. However, if they lost a packet, he will seemingly ‘jump’ across the screen, but at least he’s in the right place!

Wrapping up

Other protocols for more serious applications work very similarly. HTTP has a series of codes like 200 (OK), 403 (You’re not authorised to look at this), and 501 (It’s not you, it’s me). You might like to check out http://httpstatus.es/.

If you’ve started working with VB or C#, check out the packet libraries built into the .Net framework; they make it easy, like this method which automatically prefixes your strings with their length before writing them to the stream: BinaryWriter.Write()

Conclusion and sources

Hope this was useful and maybe even exciting. If you want to go ahead and write your own networking program now then I’ve done more than enough, but at the very least I hope it answered some of your questions.

I’m currently a professional web and software developer, but most of this information and the way it was presented was based on my experience with the Minecraft Classic protocol, which you may be interested to peruse.

Specialised services and the ambient workspace

Screenshot of a Windows Live Space

Somebody’s Windows Live Space (not mine)

Abstract: I think that our contemporary web services are doing fewer things, and doing them better, and our platforms are consolidating more information, more usefully.

The rise of the central service

Years ago I had a Windows Live Space. This was a weird blogging service slash Myspace clone, and an all-round fumbled gambit into the hastily developing world of social networking, by the ever-lovable Microsoft. Thing is, not all of my friends were on Windows Live, despite it being their first choice for email and chatting. This bugged me. Some kids had LJ, some had Xanga, and the lion’s share were on Myspace, of course. I thought, “I don’t want to sign up for all these different things and manage a million accounts, there should be some way that they can all be consolidated.”

Or, more accurately, “Everyone should decide to use the service I’m using.”

Then there was Facebook. It had photos that were taggable and statuses and chat and these new app things and games and best of all, everyone you knew was on it, something that happened practically overnight.

The fall of the central service

Now I’m going to make the bold claim that this utopian vision of togetherness is backwards, and that we are abandoning it without realising. Facebook has the world’s largest collection of photogtraphs, but more and more of the photos posted in timelines are coming from other services such as Instagram. Facebook has recently tweaked interface prompts to increase engagement, and — anecdotally — I have seen a lot of friends joining and engaging with twitter, and hearing that they log into Facebook but don’t create as much content as before. That’s interesting, and that’s bad for Facebook.

I’d posit two reasons for this:

  1. Specialised services are better at what they do (see Unix Principle)
  2. The devices we’re running these things on are getting better at giving us information ambiently.

Ambient workspaces

Let’s leave point 1 for the moment, and look at point 2, because I made a graphic. Click to enlarge.

Diagram showing traditional dekstop versus ambient workspace

Even if we’re not all using KDE or Windows 8 (yet), maybe you have a sidebar application for Twitter. Maybe eBay integrates into your mobile phone’s messaging system so you can see new bids alongside your SMSs and emails at a glance.

I strongly believe that this is a paradigm we are working towards, because the fewer clicks or keypresses you need to get to your subject of interest, the better. Why should we waste screen estate on wallpaper and icons, when the icon itself tell you what you need to know?

I’ve overlooked and glazed over a lot of points, but start a discussion in the comments if the fancy takes you.

New Programming Regime

I’m currently in the frame of mind where I want to program games. Often, I flit in and out of this mindset, but this time there’s a genuine plan.

Inspired by Petri Purho, other Indie developers like Cactus and Increpare, and – strangely – Intel, I have decided:

  • Games will be produced on a tick-tock basis.
  • On a tick, a new game will be made.
  • On a tock, an old game will be improved.
  • The cycle will take some regulated length of time.

Currently, I’m working on Slimetanks, which has recently suffered a few huge setbacks which are making me sad. I had to move the number of Slimes you have from a simple counter into an inventory entity, which means re-writing a lot of subs.

The next game will be me bringing up to grade something I started a long time ago. Teaser to the right.

In blog news, I had over 40 views per day just after my post on BASS. This is strange, and I’m trying to scope out why that happened. My most popular post is the Pokémon cards one.

See you soon, tubes.


OK, so I’m working quite hard with the newly named ‘slimetanks’, getting it polished and making it fun in some way. In the interim, like I promised, here is the full version of WorldGen, now called:



A game where colourful ascii blocks lie between you and some zombies.

  • Tutorial
  • Never-ending game mode
  • Sandbox mode

For pictures, see the linked trackback.

For download: craftscii version 0.11

Slimes soon!

1 hour game

At 9pm I decided to make a game in an hour. I already had a design, but spent 5 minutes smoothing it out on paper first.

It’s a console-based game called Slime Ranch, and is inspired by Victorian fish farming methods. I didn’t finish it, but I did get one piece of core gameplay done. The game flows as follows:

  • You are a “slime rancher”.
  • Slimes must be caught in jars as they fall from the roof of a nearby cave.
  • Slimes are then put in tanks, with algae food to make them multiply faster.
  • Slimes can be sold for money.
  • Money is used to buy dyes, which add value to a slime tank and their offspring, etc.

The piece I got done was the slime cave. You are shown a number on the screen, and must press “C” to catch the slime after that number of seconds. If you’re right to within rounding thresholds, you catch the slime. You get 5 tries before leaving the cave with your “winnings”.

There isn’t much to see, but I’ll probably finish the game by tomorrow. Exciting!


Scenario: My friend Ben and I need to exchange links to web resources on a regular basis.

Problem: I do not have Facebook. Ben does not have Twitter. Ben does not use email. Lastly, Ben does not have a rich-web capable phone with which to receive links via SMS. As you can see, this is mostly his fault.

Solution: Ben And Ste’s Social, or BASS.

While it now has 3 users — and should more accurately be called BLASS — my latest PHP experiment remains a minimalist text-and-links sharing site. It has hardcoded user data, meaning you only need to enter a password in order to post. That is obviously ‘fail’ in several ways, but it is also super secure. It has its problems, but at the moment it does the job perfectly under the load expected.

I learnt to use flock() instead of the time consuming process of restoring from backups, and a major revision is underway which will queue and batch-manage messages rather than allowing each client to modify the master log.

The tagline, and even the name of the service (“Bass”) can be changed by any of the priveleged users in their Config options at any time, which adds fun. Messages stack in a way which I am beginning to realise is what is generally acknowledged as “backwards”. I will fix that.

Bass will also have support for an embedded HTML document for each user which gives them tabbed access to their favourite websites search facilities. It automagically recognises links, even those which lack protocol prefix.

BASS is private and has no signup system.

OK. Good. I’m glad we had this chat.

A little toy

After that angsty interlude, I now return you to scheduled programming. heh. “That’s the joke”.

The following is a 2D, text mode crossover of a ‘little’ game called Minecraft and a littler game called Paradise Fort, by Hempuli. It started off only as a map generator, which I hacked together with revolting code in about an hour, based on the wisdom of Petri Purho to “build the toy first” and make it into a game later.

Flush with success at having a working build, I set about rewriting it in beautified object-oriented code, so that I could add a moving player and enemies. Enough words; here are some pictures of what I have so far:

World Generator generatingThis one isn’t very exciting. The generator makes worlds until it has one with the desired amount of water, wood, and stone blocks. This is very fast. This more colourful picture is the world into which you’re propelled. It has land, some of which is below the water table. It has trees of various shapes and sizes, a cave, and a lake. You are the @ sign, as is convention in ASCII games, and can walk around this world with the ‘m’ and ‘n’ keys. I’ll take me to the other side of the lake:

A World Generator World

World Generator zoomed in

We can then dig and change the landscape with the wasd keys.

Not yet implemented is building with Shift+wasd. Digging in World GeneratorEventually, the game will be pretty much Minecraft, but more “stay in base” and a little faster-paced. Each level will have an objective, such as escaping the screen via the left, right, top or bottom, gathering x number of a certain block, fending off x enemies, etc.

This necessitates enemies, which will likely take one step to every couple of yours.

Materials will be valued as they are in MC: Wood will be required in order to gather stone, which will be necessary to gather the as-yet-unadded iron. This progression also represents sequentially better weapons. Also like Minecraft, I plan an infinitely long sandbox level.

I’m writing it in VB out of ease. It will be releasable quite soon, and if I never work on it again, I’ll put it out in its current form, for the laughs.

Godspeed netizens!

More PHP Fun

2 PHP-solvable problems presented themselves to me this week, both, as it happens, on Minecraft Forums. I imagine that just happens to correlate to the amount of time I spend there.

In the first case, I wanted to be pretentious about making a tally chart. This was because in just ONE topic (albeit a very controversial one) it had been necessary for the mods to ban a total of 6 people. That needed tallying. There was a sense of urgency to getting my post out, and as such I ended up just making an ASCII rendition. The problem remained, and eventually, tally chart generator happened.

I want to make very, very simple web apps which take minimal input (not a whole form) and give minimum output (not a glossy translucent .png) because I think that kind of thing is cool. The novelty of this sort of programming hasn’t worn off.

As such, the next thing to emerge was an image resizer. Despite the wealth of code snippets out there to do this, I decided to write from scratch using the PHP docs. The problem came around when, in a Pixel Art thread, a contributor excused his tiny image because the ImageShack variety had failed him. It works with all .pngs but I plan adding non-animated .gif support.

The image resizer doesn’t have a nice introduction text like the tally, but is documented in the thread to which I linked above.


That is all of my PHP productivity for this week.