Skip to content

Instantly share code, notes, and snippets.

View alexlawrence's full-sized avatar
🕶️

Alex Lawrence alexlawrence

🕶️
View GitHub Profile
makeFunctionWithMiddleware = (originalFunction) ->
_allFunctions = [originalFunction]
middleWearableFunction = ->
_allFunctions[0].apply null, arguments
middleWearableFunction.use = ([criteria]..., middleware) ->
nextFunction = _allFunctions[0]
decoratedMiddleWare = (args...) ->
if criteria and not criteria.apply(null, args)
nextFunction.apply null, args
else
makeFunctionWithMiddleware = (originalFunction) ->
_allFunctions = [originalFunction]
decoratedFunction = ->
_allFunctions[0].apply null, arguments
decoratedFunction.use = (middleware) ->
nextFunction = _allFunctions[_allFunctions.length - 1]
_allFunctions.unshift (args...) -> middleware.apply null, args.concat nextFunction
decoratedFunction
someFunction = (a, b) ->
@alexlawrence
alexlawrence / overloaded.js
Last active January 1, 2016 04:49
Function overloading.
var overloaded = function() {
var functions = Array.prototype.slice.call(arguments, 0);
return function() {
try {
var functionToInvoke = functions.filter(function(x) {
return x.length == arguments.length;
})[0];
functionToInvoke.apply(this, arguments);
}
@alexlawrence
alexlawrence / String.format.js
Last active December 15, 2015 22:09
String.format like in C#
String.format = function(f) {
return Array.prototype.slice.call(arguments,1).reduce(function(o,v,i){return o.replace('{'+i+'}',v);},f);
}

Node.js for Raspberry Pi

This is a very old gist - it may not work nor be correct anymore. Use everything at your own risk. See http://n8.io/cross-compiling-nodejs-v0.8/ for something slightly more up-to-date.

OpenSSL has been problematic in the past, use --without-ssl first to determine if it's a problem with node or OpenSSL.

Pre-built binaries