Skip to content

Instantly share code, notes, and snippets.

View lennym's full-sized avatar

Leonard Martin lennym

View GitHub Profile
route: function (route) {
if (typeof this[route] === 'function') {
// pass on any remaining arguments to route method
var args = [].slice.call(arguments, 1);
this[route].apply(this, args);
} else {
// some kind of error handling
}
}
@lennym
lennym / gist:3945437
Created October 24, 2012 10:48
Spying on bound methods
describe('A hypothetical situation', function () {
var View = Backbone.View.extend({
initialize: function () {
this.model = new Backbone.Model;
this.model.on('change', this.render, this);
}
}), instance;
beforeEach(function () {
@lennym
lennym / gist:3953769
Created October 25, 2012 16:17
Run test pre-commit hooks
git stash -q --keep-index
if phantomjs ; then
echo "Running Jasmine unit tests"
if [ "$DEBUG" = "true" ] ; then
phantomjs src/test/phantom.runner.js src/test/index.html 8080 true
else
phantomjs src/test/phantom.runner.js src/test/index.html 8080 false
fi
RESULT=$?
else
@lennym
lennym / app.js
Last active December 16, 2015 05:49
var router = require('router.js');
app.route = function (path, map) {
['get', 'post', 'put', 'delete'].forEach(function (method) {
if (typeof map[method] !== 'undefined') {
app[method](path, map[method]);
}
});
}
@lennym
lennym / gist:8686578
Created January 29, 2014 12:03
Ractive.JS ideas
var user = {
name: 'Mike',
points: 1
};
var ractive1 = new Ractive({
el: 'container',
template: '#template',
data: user
});
var Checkout = function Checkout(inventory) {
inventory = inventory || [];
this.basket = {};
this.inventory = {};
inventory.forEach(function (product) {
this.inventory[product.code] = new Product(product);
}.bind(this));
@lennym
lennym / gist:9410401
Last active August 29, 2015 13:57 — forked from tombooth/gist:9410376
var vm = require('vm');
function checkArr(arr) {
return arr instanceof Array;
}
var context = vm.createContext({
checkArr: checkArr,
console: console
});
@lennym
lennym / index.js
Created March 25, 2014 13:21
Programmatic/dynamic Mocha test construction
var Mocha = require('mocha'),
expect = require('chai').expect;
var mocha = new Mocha({
reporter: 'spec'
});
var dashboards = Mocha.Suite.create(mocha.suite, 'dashboards');
var subsuite = Mocha.Suite.create(dashboards, 'something');
[
{
"userName": "alphagov",
"repo": "datainsight-frontend"
},
{
"userName": "alphagov",
"repo": "fourth-wall"
},
{
/**
Usage: `node domains.js --file <inputfile.csv>
**/
var fs = require('fs');
var argh = require('argh').argv;
var _ = require('underscore');
var input = argh.file;
fs.readFile(input, function (err, filedata) {