jQuery Checkbox Replacement
Posted by: Steve Johnstone in Web Development on February 3rd, 2010
Ordinary checkboxes on the web are a bit boring. I’ve seen a few replacement scripts, but I thought that it would be pretty easy to write my own.
function replaceCheckbox(name, on, off) { $(name+':not(.checkbox-replaced)').each(function (){ var image = ($(this).is(':checked') ? on : off); var imageElement = $('<img style="cursor:pointer;" src="'+image +'" onclick="$(this).next().click();"/>'); $(this).before(imageElement).hide() .addClass('checkbox-replaced'); imageElement.click(function (){ $(this).attr('src',(this.src.indexOf(off) > 0 ? on : off)); }); }); }
It seems to do the job fairly nicely, so I’m quite happy. Â It does require the use of jQuery. To use it simply go:
replaceCheckbox('input[type=checkbox]:visible','check_on.png','check_off.png');
De-serializing RSS XML
Posted by: Steve Johnstone in Work on February 1st, 2010
In our project at work we had a need for an RSS reader in c# and, through the power of Google, I managed to find quite a neat way of deserializing the RSS XML.
Basically all I needed to do, was save an example feed to a file on my hard disk. Then, using the Visual Studio Command Prompt and then run the command:
>xsd rss.xml
which generated several xsd files. Then I ran:
>xsd /c rss.xsd rss_app1.xsd rss_app2.xsd rss_app3.xsd
which generated the required c# class file (If you don’t add the other files, you may get the message “Error: Error generating classes for schema ‘rss’”). After copying the class file into my project, I was able to de-serialize the stream by writing:
      Â
using (Stream stream = WebRequest.Create(url).GetResponse().GetResponseStream())
{
StreamReader reader = new StreamReader(stream);
//string response = reader.ReadToEnd();
XmlSerializer serializer = new XmlSerializer(typeof(RDF));
feed = (RDF) serializer.Deserialize(stream);
}
As a certain meerkat would say, simples!
November Games
Posted by: Steve Johnstone in Home on November 28th, 2009

Dragon Age
The first was Dragon Age, which I grabbed as soon as it came out. I’m a massive fan of CRPGs, and I’ve enjoyed all of Bioware’s previous games so this was an automatic purchase. So far I’ve found it highly entertaining, and I think I’ve sunk about 50 hours into the thing.
Next comes Modern Warfare 2, which is hugely popular. I’ve heard that approximatly 2% of people in England now own a copy, which is insane. The single player game is all about the set pieces for me, so the fact that the plot makes absolutly no sense didn’t detract from the overall experience. I wish it had been longer, like the majority of people that play the campaign, but I think it’s well padded by the special ops missions. The multiplayer very close to the original, which means it’s very addictive and entertaining, and I can never get enough of the sounds of bullets hitting flesh and the ding of experience after each kill.
Thirdly I bought Assassin’s Creed 2. The original game was fun but flawed, due to some very repetative missions. This time Ubisoft have gone closer to the GTA way of doing things, which makes the storyline feel a lot more fluid. The addition of a town which you can sink your money into is a bit gimiky, but enjoyable. The movement is still a bit clunky, and I find that I throw myself in the wrong direction with startiling regularity.
All in all it’s been quite an enjoyable month of gaming.
Rule the World Game
Posted by: Steve Johnstone in XNA on November 17th, 2009
I’ve been making an XNA game for a while. It’s a clone of the board game Risk, and I’m making it it using my own game engine which I’m building at the same time. The current working title is “Rule the World”. My aim is to have a sellable game and something with which I can base future games on. So far it’s going pretty well, and can actually be played from start to end, although only using a single controller. Here’s a little bit of a sneak peek:
Risk Game Demo 1 from Steve Johnstone on Vimeo.
I’m using the Interpolation code from Nick Gravlyn’s blog, although I’ve heavily modified it in order to use it with Vectors and Colours. The menu is hand written and was a bit of a bugger to write, but I’m really happy with how it turned out. The shader is also hand written from scratch, as is the input manager. My next task is to add some loading screens, and make it all look a bit prettier.
I’m eventually planning on releasing this onto the XBox Live Indie Games, so I’m going to try and make the whole thing as slick as possible. Wish me luck!
New Canon Powershot g10
Posted by: Steve Johnstone in Photography on October 9th, 2009
Just recently I had a spontanious need for new gadgets in my life, and went out and bought a Canon Powershot g10. My other camera is a Canon 350D, which is absolutly lovely, but a bit hard to lug around everywhere I go. The main reason for buying a new camera, was that the best camera is always the one you have on you. The g10 is certainly alot more compact, but still feels substantial. I’ve started taking it everywhere I go, and snapping away as I get used to it. I like quite alot of the images that I’ve taken already. The only problem I have with the camera so far is that it’s a bit noisy. I’ve got a feeling that it’s mostly my fault for taking photos at night though. You can see my photos at my Flickr account.
C# Lambda Expressions
Posted by: Steve Johnstone in XNA on October 2nd, 2009
I’ve found the Lambda expressions in C# quite hard to wrap my head around. Fortunatly for me, Nick Gravelyn has written a lovely concise explanation of them. The examples are all based on writing XNA based games, but they’re pretty simple to follow without knowing the XNA library. Nick is a Microsoft MVP for DirectX and XNA, and I heartily recommend reading his blog to learn a bit more about C#, even if you don’t develop games.
Where Did My Event Go?
Posted by: Steve Johnstone in Web Development on September 16th, 2009
For the past day I’ve been struggling with a bit of Javascript. Like most problems involving browsers, it worked perfectly in Firefox (Whoo!) but died a horrible and confusing death in Internet Explorer (Boo!).
The code was using jQuery to clone a selection of rows in a table and append them to the same table. This worked fine, but one of the rows had an autocompleting field, which refused to work the second time someone did a search. This only applied to the duplicated rows, and only on the second search. The first time worked perfectly, no matter how many rows had been duplicated.
The culpret turned out to be a div that was wrapped around the added rows, in order to manipulate the new rows as one jQuery object. It turns out that if the DOM is not perfectly formed in IE, any future manipulation of the DOM will result in events being stripped.
Death to the Pocket PC
Posted by: Steve Johnstone in Home on August 12th, 2009
At work half my time is spent struggling with bloody Pocket PC development. I go on holiday and this is what the tourist office give me as my virtual tour guide. ARGH! And, as can be expected, it didn’t work. Rubbish.
New iPhone
Posted by: Steve Johnstone in Home on July 26th, 2009
I’ve just got a new iPhone, and I must say that it’s definately full of win. I’m writing this post from the bus, which is a very nice thing to be able to do. Mad finger typing skills.
Increase JavaScript Responsiveness with setTimeout
Posted by: Steve Johnstone in Web Development on March 19th, 2009
My current project requires moving an item from one list to another, and then verifying the contents of the second list against the database. In order to do this, I used the jQuery append function, and then called another function which executed a getJSON request.
Because the speed of the request was so slow, it ended up delaying the move of the item. This made the UI feel unresponsive. In order to fix this, I changed the call to the function to a setTimeout with a delay of 0. This meant that the UI could go on and do what it wanted to, while the JSON request went off and did it’s thing.