Andrew Maddison

Flowerchild.

Codemanship TDD Master Class - Fizz and Indeed Buzz.

I just got back from attending a budget friendly TDD Masterclass weekend course run by Jason Gorman of Codemanship, and I’m duly enthused and encouraged about the whole TDD thing. Specifically, I’m now happy that I can do exercises and KATAs test first and actually learn something.

So I set myself the challenge of completing FizzBuzz TDD on the tube between Waterloo and Woodside park, about 40 minutes. I failed. Dismally.

In fairness most of my failure was because hordes of tourists meant by the time I got a seat I only managed to get one test passing by the time I had to get off. It took me three stations just to boot the laptop and open visual studio.

Anyway, when I got home I tried again and I’ve just finished FizzBuzz, hopefully remembering some of the 13 good habits of TDD Jason’s been trying to drum into us. It took me about 55 minutes (including adding an “empty test method” snippet into Visual Studio). Longer than I was expecting, but never mind.

Just for context, hacking out a console app FizzBuzz in C# last week took me 6 minutes from a cold start (not running visual studio), and that included getting confused and trying to use the modulus operator back to front.

Another little suggestion I’m going to try to take on board is to be realistic in the short term. I’m not going to use this at work any time soon, but I’ll try and use it on my pet projects at home from now on and to do the odd exercise regularly to keep getting the hang of it. Of course the road to hell is paved with good intentions, which is why I’m writing this post to expose myself to public ridicude when if I don’t try very hard.

Anyway, a big thank you to Jason for organising a great course.

Now, how do I write a blog post without sounding like my Father putting on his telephone voice?
comments

Syntax Highlighting Code in Subtext

Quick post-it post:

The syntax highlighting in my last post came from: http://www.manoli.net/csharpformat/ it works nice and easily, although you do have to include some CSS on the page (no great hardship).

(found via this blog post from Phil Haack http://haacked.com/archive/2004/06/16/code-to-html-syntax-highlighting.aspx)

Again, there’s probably a better way, and I need to figure how to stop long lines from overflowing their container, but that’s a problem for another day.

Edit: Fixed it, I simply added “overflow: auto;” to the CSS for the pre tags. it’s a little irritating in IE7 or below, but fine in all the proper browsers I tested.
comments

Base 64 Encoding an Image to Pass Across a Web Service

I’m writing a little app which will need to submit (amongst other things) an image to a server. The server exposes web services (SOAP for the moment), and because I couldn’t think of any other way to pass a whole image file in, I tried base 64 encoding it, as it turns out it was really simple to get an example working.

In the source application, I simply loaded the image as a byte array, and encoded it.

byte[] imageBytes = File.ReadAllBytes(@"c:\someExistingImage.jpg");
string b64image = Convert.ToBase64String(imageBytes, Base64FormattingOptions.None);

Then I simply passed that string as an argument on a method in my web service. At the other end I was able to do the revese with equally little fuss:

[WebMethod]
public void SubmitImage(string base64EncodedImage)
{
    byte[] rawImage = Convert.FromBase64String(base64EncodedImage);
    File.WriteAllBytes(@"c:\someNewFilename.jpg", rawImage);
}

Worked first time! On the real thing the image is actually going to be stored in a DB in the short term, and only retrieved later, but this proved that the base 64 bit worked.

I assume that there might be a better way of solving this problem (submitting an image to a remote server from code), possibly by using http post, but this seemed easier.
comments

First!

I assume I can delete this later when it becomes embarrasing?
comments