Skip to content

Instantly share code, notes, and snippets.

@benf86
benf86 / BaseModel.js
Created August 23, 2016 09:55
Semi-complete example of a base model with some helper methods
'use strict';
const _ = require('lodash');
var BaseModel = function BaseModel () {};
/* Model creator function
* params: new model properties
* ops: function that modifies/checks/validates/... params
@benf86
benf86 / stateMachineExample.js
Last active August 26, 2016 17:30
A very simple example of a state machine
'use strict';
/**
* Adds state machine functionalities to targetObject.
*
* @param {object} targetObject The target object
* @param {object} states The states in the form of { statePropertyName: [ { from: 'state1', to: 'state2', reversible: true || false } ] }
* @param {string} log Property name to which to log the state changes (leave undefined/null for no logging)
* @return {object} The Target object with added SM methods and properties
*/
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDOQB8ol3TlUvVJC+CaIAK0C6/ogpouId8Iy3nLwLimfg+dymVV91fYoW5gHBq7FuPkgQJfotipMPfYy7qI9BpQylAZegopt0nQX7LJCjTCUI5zDs3caUKPkfFDt2QhoLJqLe1uSon7q8pn18tkTOO6j6+YzkX9nwXCeg3ZMyuXb8+uyvmiKmNjTm0lnGFj7t/Ql1iiW5fh8qPnr6q0eNj4bhIK2xo5vjO3XYlM4SwHI0Zyp/krjhcvmbBM5p0piw8cVVlPDrfwCWYWbxKSUBgqVrKTv2oMO//RfxyLKgecJYJt3WG63g2dIoiXmaz1BKokhNTYiLPs4aTRTAIxn36r benjamin@ferreira.si
@benf86
benf86 / installCoverage.sh
Last active August 23, 2016 19:32
Script to setup mocha + istanbul testing and code coverage, and serving the results in a browser
#!/bin/bash
sudo npm install --save-dev concurrently istanbul lite-server mocha watch npm-add-script
sudo chown `whoami`:`whoami` package.json
sudo chown -R `whoami`:`whoami` node_modules
node_modules/npm-add-script/cmd.js -k coverage -v "node_modules/concurrently/src/main.js -r -k \"node_modules/lite-server/bin/lite-server\" \"npm run coverage:watch\""
node_modules/npm-add-script/cmd.js -k coverage:watch -v "node_modules/watch/cli.js \"node_modules/istanbul/lib/cli.js cover --dir .coverage --print detail _mocha -- --recursive tests\" ./*/"

Keybase proof

I hereby claim:

  • I am benf86 on github.
  • I am benf86 (https://keybase.io/benf86) on keybase.
  • I have a public key whose fingerprint is 2707 3E71 6D1B AA91 5EAF 8E93 5BAC D07F B4AC E425

To claim this, I am signing this object: