Skip to content

Instantly share code, notes, and snippets.

View mlrawlings's full-sized avatar

Michael Rawlings mlrawlings

View GitHub Profile
@mlrawlings
mlrawlings / gist:3093003
Created July 11, 2012 20:14
SS Catch-all
// Log uncaught exceptions
process.on('uncaughtException', function(err) {
console.log(err.message.red);
if(err.stack) console.log(err.stack.split("\n").splice(1).join("\n"))
});
@mlrawlings
mlrawlings / gist:3093247
Created July 11, 2012 20:42
SS LiveReload onChange
onChange = (path, event) ->
takeAction = (action) ->
if (Date.now() - lastRun[action]) > 1000 # Reload browser max once per second
console.log('✎'.green, consoleMessage[action].grey)
ss.publish.all('__ss:' + action)
lastRun[action] = Date.now()
action = if pathlib.extname(path) in cssExtensions then 'updateCSS' else 'reload'
if event is 'added' or event is 'changed'
fs.readFile path, (err, data) ->
if data.toString() != '' then takeAction(action)
@mlrawlings
mlrawlings / gist:3136120
Created July 18, 2012 13:08
HTML insert before tag (strings)
insertBeforeTag = (html, tag, toInsert) ->
pos = html.indexOf(tag);
return html if pos != -1
return html.slice(0, pos) + toInsert + html.slice(pos)
@mlrawlings
mlrawlings / ensureDirectoryExists.js
Last active December 14, 2015 02:59
Ensure that a directory exists (and create it if it doesn't)
function ensureDirectoryExists( path, fn ) {
fs.exists( path, function( exists ) {
if( exists ) {
fn();
} else {
var parent = path.replace( /(\/|\\)[^\/\\]+$/, '' );
ensureDirectoryExists( parent, function() {
fs.mkdir( path, fn );
});
}
var mongoose = require('mongoose')
, Schema = mongoose.Schema
, ObjectId = mongoose.SchemaTypes.ObjectId
module.exports = function(schema, options) {
var options = options || {}
, historySchemaDefinition = {}
, historySchema
, HistoryArchive
var ballots = [
[ ['A'], ['B', 'C'], ['D'], ['E', 'F', 'G', 'H', 'I', 'J'], ['K'] ],
[ ['A', 'B'], ],
[ ['A', 'B'], ['D'], ],
[ ['A', 'B'], ],
[ ['A', 'B'], ],
[ ['D'], ['B'], ],
[ ['D', 'A'], ['C'], ],
[ ['C', 'D'], ['B'], ],
[ ['C', 'D', 'A'], ],
@mlrawlings
mlrawlings / reserved.js
Created June 18, 2016 23:23
reserved js keywords
module.exports = [
// Existing Keywords
"break",
"case",
"catch",
"class",
"const",
"continue",
"debugger",
"default",
@mlrawlings
mlrawlings / index.js
Last active July 13, 2016 19:10
requirebin sketch
// Welcome! require() some modules from npm (like you were using browserify)
// and then hit Run Code to run your code on the right side.
// Modules get downloaded from browserify-cdn and bundled in your browser.
var htmlStream = getHTMLStream()
var targetEl = document.querySelector('#target')
renderStream(htmlStream, targetEl)
/// RENDER STREAM ///
@mlrawlings
mlrawlings / index.js
Created September 19, 2016 22:39
requirebin sketch
// Welcome! require() some modules from npm (like you were using browserify)
// and then hit Run Code to run your code on the right side.
// Modules get downloaded from browserify-cdn and bundled in your browser.
var htmlStream = getHTMLStream()
var targetEl = document.querySelector('#target')
renderStream(htmlStream, targetEl)
/// RENDER STREAM ///
@mlrawlings
mlrawlings / index.js
Created September 19, 2016 22:39
requirebin sketch
// Welcome! require() some modules from npm (like you were using browserify)
// and then hit Run Code to run your code on the right side.
// Modules get downloaded from browserify-cdn and bundled in your browser.
var htmlStream = getHTMLStream()
var targetEl = document.querySelector('#target')
renderStream(htmlStream, targetEl)
/// RENDER STREAM ///