ServiceStack “Hello World” with tests

I’ve been digging into ServiceStack lately as it seems like a nicely architected framework for building serviced-based applications.

The main thing I like about it is it’s simplicity and focus on performance. Also there are loads of example projects and great documentation.

I had some questions on testing, so I made a little reference project might be useful.
It’s a small “Hello World” style app that demos a simple web-hosted service with sample tests.

Sublime Text 2, rbenv, osx and the build command

I’ve recently started using rbenv on OSX and was having some trouble getting the cmd+b build command in Sublime Text 2 working.

Specifically, it seemed that the wrong ruby version was being used. This caused my require ” statements to fail since it couldnt find the gems I thought I had installed.

To get things working, simply edit Ruby.sublime-build (Browse Packages -> Ruby) and update the “cmd” value to point to ~/.rbenv/shims/ruby

	// These are the old commands
	//"cmd": ["ruby", "$file"], 
	//"cmd": ["/usr/local/bin/ruby", "$file"],
	"cmd": ["/Users/kiwidev/.rbenv/shims/ruby", "$file"],	
	"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
	"selector": "source.ruby"

What I look for in project style technical tests for Developer interviews.

I primarily do contract software development so interviews are pretty common for me.

I’ve seen a huge variety of ways people perform technical testing, ranging from multi-choice questions (terrible) to simple chats on what you’ve done.

Over the last few months I’ve had the opportunity to be on the other side of the fence and actually interview developers. This was really exciting because I could put into practice some of the things I thought would make for a good technical test.

By far my favourite tests have been project style ones. You give a candidate a short project spec and let them go to town and use what they needed to get it done.

We sent the test out to anyone that applied. This acts as a good candidate filter.

In the test I created, I asked them to create a console application which implements a Design Pattern to shift some text files around.

From these types of tests, you can infer a variety of things about developer which provides an insight into how they could perform in a real world scenario.

I found the following information:

  • Ability to use computers.
    eg: not being able to send a copy of the test to us in some way is a fail. Yes this has happened more than once.
  • Ability to read the instructions.
  • Do they use the design pattern (State Pattern) I asked them to implement. <- !!! Very few people actually did this
  • How they comment the code. If at all
  • Ability to find stuff. ie, use google. This is hugely important.
    If they don’t what the pattern I asked them to implement is, did they look it up?
    Can they find a third party library to perform certain tasks?
  • Did they implement the entire thing?
    At the bottom of the instructions it says you only need to implement 2 of the 5 states.
    This is the Van Halen brown m&m’s test.
    Yes you could consider this almost like a trick question. I don’t mind if they implement the whole thing but I do look for some comments mentioning they recognized this request.
  • Does the code work?
  • The WTF level of the code.
  • Can they pull the code from bitbucket? It’s not a fail if they ask for instructions but it is really simple to figure out. This provides insight into their ability to figure things out.
  • Do they write good comments? Comments should be concise and describe what is trying to be done as opposed to stating each step of the code (that’s what code is for!!)
  • Can they write code? I look out for things like deep copying of objects
  • Is their code pretty? Good developers write beautiful code. If they have, they probably have read at least 1 of two books that I consider kind of mandatory: Code Complete or maybe Beautiful Code
  • Project structure. Has the solution been laid out nicely?
  • What excuses they make in the email they send to us.
  • Do they ask us questions to help clarify the project. This is a good thing and it shows that communication and understanding is important and also that they aren’t afraid of asking questions.
  • Cleverness. Can they find the example code that is hidden somewhere in plain sight?

Node.js, express, mongoose.js and modules

I found node.js modules (exports) a little confusing at first.

So, here’s a small example using node.js with mongoose and modules to represent something closer to a real world project structure.

app.js references auctions.js which is basically the controller logic.

auctions.js references ./models/auction.js which holds the model and schema.


var express = require('express');
var mongoose = require('mongoose');

var app = module.exports = express.createServer();


app.configure(function () {

app.get('/', function (req, res) {
    res.send('hello world');

// auctions api
var auctions = require('./auctions.js');
app.get('/auctions', auctions.list);'/auctions/create', auctions.create);



// load up the model
var Auction = require('./models/auction.js');

exports.create = function (req, res) {
    // replace data assigments with something like
    // {comments: req.body.comments}
    new Auction({
        iso_currency_symbol: 'GBP',
        comments: 'second auction'

    res.send('hello, this is response text');

exports.list = function (req, res) {
    Auction.find(function (err, auctions) {


var mongoose = require('mongoose'),
    Schema = mongoose.Schema,
    ObjectId = Schema.ObjectId;

var auction_schema = new Schema({
    iso_currency_symbol: String,
    created_date: { type: Date, default: },
    started_date: { type: Date },
    owner_id: ObjectId,
    comments: String

module.exports = mongoose.model('Auction', auction_schema);

Note: I’m not a node.js expert so if there is a better way to do this, lemme know 🙂

ASP.Net MVC3 ajax form loading that preserves unobtrusive validation AND has custom json validation

Well, this is a mouthful to describe.

Here’s an example concept I came up with during the early ASP.Net MVC 3 days.

I wanted to be able to use the unobtrusive client side model validation forms in a partial view but load them via jquery ajax calls.

In addition, I had some quite complex server side validation that needed to be done.
The catch? Those complex server side calls HAD to always be server side AND they should not cause the form to reload. So, Custom Validators didn’t seem to work the way I wanted (bear in mind that the information on on mvc3 was pretty light).

The form gets hijaxed to preserve the unobtrusive validation.
If the form’s model is invalid it returns the original form partial html.
If the form’s model is valid, we return a JsonResponseViewModel json object.
This object can have a status of “Ok” or “Error”.
If “Error”, then a list of JsonResponseErrors exists. We parse and display those on the client.
If “Ok” then just we are all good 🙂

There’s probably a better way to do this but I thought I should just share this with the world anyways.

The example solution:
ASP.Net MVC3 ajax based client side notification of server server side validation.
Also shows you how to load a standard MVC3 unobtrusive form via ajax and keep the MVC model validation for both server and client side.

Grab it here

Coffeescript, Sass and Less Visual Studio extension

The kind folks over at Mindscape have released a nice Visual Studio extension for Coffeescript, Sass and Less which gives it syntax highlighting, intellisense and code collapsing.

Read more about it here or simply go straight to the download page

If you haven’t tried Coffeescript yet, I recommend giving it a shot. It’s a lovely language that feels like it’s based on ruby/python and cross compiles into Javascript.