Syntax Highlighting in WordPress

June 19th, 2008

I’ve stepped away from the Haxe snake game for a couple days because I was frustrated with the way the code showed up in WordPress. A little digging and I found WP-Syntax. So far so good. It does everything I expect it to with no hassle. I had to turn off the visual editor in WordPress but that is a small price to pay to be able to display code properly. If you display any code snippets on your WordPress blog I highly recommend WP-Syntax.

You’re Doing It Wrong: Automating Documentation

June 18th, 2008

I recently came across the article Automation for the people: Pushbutton documentation at IBM developerWorks. Let me start out by saying I am a fan of automation and that automating the creation of source code documentation, user documentation, and build diagrams is fine in my book. What annoyed me was the automated creation of UML and entity-relationship diagrams. Scratch that, it wasn’t the automated creation of them, because that can have its uses, it was the implication that the creation of these diagrams was tangential to development and so we should just write the code and generate the docs.

UML and entity-relationship diagrams help us develop code. If you find that they need to be changed at the implementation stage then you should go back (as painful as it may seem) and fix the problem at the design stage. In the long run you’ll be much better off. I can hear people complaining already in that I am not following my own advice and following good design practices for the snake game, and they are right. However there is a difference in that the snake game is just something I’m doing to explore Haxe. So I want the flexibility to change the design as I learn the language and its features. If this were a serious project you bet I would be following good process.

Flash Game Development with Haxe: A Simple Snake Game

June 17th, 2008

I’ve been meaning to pick up the language haxe and I’ve also been meaning to do some flash game development as well. Two birds, one stone and all that jazz means that over the course of the next week I’ll put together a simple flash snake game using haxe. Nothing fancy here, just me exploring flash game development in haxe and sharing my experience as well as explaining my code. You can download the code to this article here. Let’s get started then.

My goal for this first day is just to move a square around based on key presses. In InputManager.hx you’ll find a simple input manager. Skipping past all the key code defines you’ll find this:

private var key_bindings : IntHash<Dynamic>;
public function new()
    key_bindings = new IntHash<Dynamic>();

What is going on here is a hash table mapping Int keys to variables of Dynamic type. Dynamic can be basically anything in Haxe and in this case we are storing functions and the Int keys are keycodess.

public function bind(key : Int, func : Dynamic)
    key_bindings.set(key, func);

The bind function simply binds a keycode to a function.

public function handleInput()
	for(key in key_bindings.keys())
		if(key > 1000)
			if(flash.Key.isDown(key-1000) && flash.Key.isDown(SPCL_KEY_Shift))

The meat of the InputManager class the handleInput function iterates over our keys and if the key is down it calls the corresponding function we bound to that key. Flash doesn’t distinguish between upper and lower case presses so I got around that by adding a constant (1000) to the key code for those which require the shift key to be down and can detect those key presses separately.

The main class in SnakeGame.hx is pretty simple so I’ll only cover the one interest bit there:

var binder = function(obj, arg){ return function(){ obj(arg); } };
_input = new InputManager();
_input.bind(InputManager.SPCL_KEY_LeftArrow, binder(_snake.move_left, 10));
_input.bind(InputManager.SPCL_KEY_RightArrow, binder(_snake.move_right, 10));
_input.bind(InputManager.SPCL_KEY_UpArrow, binder(_snake.move_up, 10));
_input.bind(InputManager.SPCL_KEY_DownArrow, binder(_snake.move_down, 10));

Some of you may be scratching your heads at that bit of code. What is going on is this: we create a variable binder which is a function taking two arguments (an object method and an argument). Binder itself returns a function which calls the object method (or any function) with the argument provided. In doing so we can take a method like move_left in the snake class which takes an Int argument and pass it in to the InputManager as a function which takes no arguments. Simply put when we press the left arrow the InputManager calls a function whose body contains _snake.move_left(10). That’s it. Tune in next time when I give this baby a tail.

Here’s the result (click on it to activate):


June 13th, 2008

Content is king! At least we are told (and I believe). I’m going to put it to the test. For the next 30 days I will be updating this blog once a day during weekdays and once during the weekends. I won’t be doing any promotion beyond what I am doing now. This currently consists of placing a link to my blog in my signature on forums. As you can see I am the king of promotions. If content is truly king then I should see more visitors. Originally I wanted to see 700 visitors a day (which is about 100x current) but then I thought to myself “700 a day is a goal for people who suck.” New goal: 1000 visitors a day. With that new goals I’m also giving myself the enormous budget of $100 to promote the site: I am the king of promotions.

While I will be happy with more visitors that is not the only metric by which I will judge success. Just by the virtue of there being more pages I will get more traffic but what I want to see happen is that the following ratio increase:

(number of visitors / number of entries) / month

I’m calling this blog entry efficiency. Currently my blog entry efficiency is 7.94. I want to see that increase tenfold over the next 30 days. In the end I will write up the results and what I feel I learned from the experience. Welcome to the blog-entry-efficiency-30-day-challenge-o-rama.

Windows XP PowerToys: Open Command Window Here

October 29th, 2007

I discussed previously how to add an entry to the Windows context menu that would allow you to open a Cygwin bash shell with the current working directory set to the directory you clicked on. Someone commented on that entry that they have a similar entry for the Windows command prompt. I do as well (although it sees very little use compared to the Cygwin entry) and for those who work in Windows this is something of which they should be aware.

The tools is creatively titled “Open Command Window Here” and is one of the PowerToys for Windows XP from Microsoft. There are a lot of neat little tools in the PowerToys which probably should have been part of Windows XP from the beginning (in particular Tweak UI). If you’re working in Windows check out the PowerToys as they can make your life a little simpler.