Skip to content

Instantly share code, notes, and snippets.


Bradley Braithwaite bbraithwaite

View GitHub Profile
bbraithwaite / server.js
Created Jan 26, 2015
Node JS web server code that serves a single static file.
View server.js
var fs = require('fs'),
http = require('http');
http.createServer(function (req, res) {
fs.readFile("index.html", "binary", function(err, file) {
if(err) {
res.writeHead(500, {"Content-Type": "text/plain"});
res.write(err + "\n");
bbraithwaite /
Created Jan 11, 2014
TDD Kata from in MD format so that I can easily download it for referencing when I'm practising.

#String Calculator Instructions

  1. Create a simple String calculator with a method int Add(string numbers)
    • The method can take 0, 1 or 2 numbers, and will return their sum (for an empty string it will return 0) for example “” or “1” or “1,2”
    • Start with the simplest test case of an empty string and move to 1 and two numbers
    • Remember to solve things as simply as possible so that you force yourself to write tests you did not think about
    • Remember to refactor after each passing test
  2. Allow the Add method to handle an unknown amount of numbers
  3. Allow the Add method to handle new lines between numbers (instead of commas).
    • the following input is ok: “1\n2,3” (will equal 6)
bbraithwaite / utils.js
Created Jan 15, 2014
Some test object extensions for a blog post.
View utils.js
exports.utils = function () {
if ( typeof String.prototype.startsWith != 'function' ) {
String.prototype.startsWith = function( str ) {
return this.substring( 0, str.length ) === str;
if ( typeof Object.prototype.sum != 'function' ) {
bbraithwaite / createPromiseSpy.js
Created Jul 1, 2015
Utility function for working with promises in angular tests.
View createPromiseSpy.js
var createPromiseSpy = function(obj, name, method, $q) {
var createdSpy = jasmine.createSpy(name, obj);
var returnObj = {};
var promise = {};
if (typeof(method) === 'string') {
var deferred = $q.defer();
spyOn(createdSpy, method).and.returnValue(deferred.promise);
promise[method] = deferred;
You can’t perform that action at this time.