Skip to content

Instantly share code, notes, and snippets.

View lennym's full-sized avatar

Leonard Martin lennym

View GitHub Profile
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
});
[
{
"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) {
@lennym
lennym / logger.js
Created November 25, 2014 11:28
Logging with Winston
var winston = require('winston');
var config = require('./config');
var logger = new winston.Logger({
transports: [
new winston.transports.Console({ colorize: true }),
new winston.transports.File({ filename: config['app-log'], json: false })
],
exceptionHandlers: [
@lennym
lennym / test.js
Last active August 29, 2015 14:10
// example test script for module with http.get
// uses sinon, chai and mocha.
var Module = require('./my-module-that-does-http');
var http = require('http');
describe('Module', function () {
beforeEach(function () {
@lennym
lennym / json-linter.js
Created December 8, 2014 14:53
json-linter.js
var fs = require('fs'),
path =require('path');
var dir = process.argv[2];
if (!dir) {
console.error('Folder path must be defined.');
console.log('Usage: node json-linter.js /path/to/test');
process.exit(1);
}
@lennym
lennym / hack.js
Created December 11, 2014 15:09
HTTPS
var https = require('https');
var getLatestCoreVersion = function(major, cb) {
var json = '';
var req = https.get({
host: 'api.github.com',
path: '/repos/mozu/core-theme/releases',
headers: {
'User-Agent': 'thmaa',
'content-length': 0,
},
@lennym
lennym / gist:8dcd3ceafd30b9305be0
Created February 25, 2015 14:16
package json snippet
...
"karma": "0.12.24",
"karma-browserify": "0.2.1",
"karma-chai": "0.1.0",
"karma-chrome-launcher": "0.1.5",
"karma-firefox-launcher": "0.1.3",
"karma-mocha": "0.1.9",
"karma-phantomjs-launcher": "0.1.4",
"karma-sinon-chai": "0.2.0",
...
@lennym
lennym / test.js
Created April 9, 2015 15:51
Example middleware test
var middleware = require('./my-middleware')
describe('middleware', function () {
var req, res;
beforeEach(function () {
req = {
session: { username: 'lennym' }
},
res = {}