This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(tcpspy). | |
-export([start/3, stop/1, start_spy/3, listener/3, handler/2]). | |
start(Port, ServerHost, ServerPort) -> | |
spawn(?MODULE, start_spy, [Port, ServerHost, ServerPort]). | |
stop(Spy) -> | |
exit(Spy, shutdown), | |
ok. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
I've seen this happen more than once. The data structure changes | |
its implementation, and suddenly some other code that you forgot | |
to update fails silently. | |
Here, Constants used to have "TYPE" instead of "STATE". We | |
updated it, but forgot to update the user of thing. | |
*/ | |
// thing.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function h(type, props, children) { | |
children = children || [] | |
return { | |
type, | |
props: props || {}, | |
children: Array.isArray(children) ? children : [children] | |
} | |
} | |
function createElement(node) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const assert = require('assert') | |
const api = () => 'SOME_RETURN_FROM_API' | |
const call = (fn, ...args) => ({type: 'call', fn, args}) | |
const update = thing => ({type: 'update', thing}) | |
function * mySaga () { | |
const foo = yield call(api, 1, 2) | |
yield update(foo) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// require() some stuff from npm (like you were using browserify) | |
// and then hit Run Code to run it on the right | |
const daggy = require('daggy') | |
const {Just, Nothing} = require('data.maybe') | |
const RemoteData = daggy.taggedSum({ | |
NotAsked: [], | |
Loading: [], | |
Failure: ['error'], | |
Success: ['items'], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// require() some stuff from npm (like you were using browserify) | |
// and then hit Run Code to run it on the right | |
var xhr = require('xhr'); | |
var container = document.querySelector('.time-line'); | |
var books = []; | |
var earliestDate = Infinity; | |
function int (date) { | |
return Number(new Date(date))/(24*60*60*1000); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function addSuper (subFn, superFn) { | |
return function () { | |
var self = this, | |
args = arguments; | |
this._super = function () { | |
return superFn.apply(self, args); | |
}; | |
return subFn.apply(self, args); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* I couldn't find a super simple example of how to run Karma, PhantomJs, with | |
* Jasmine tests via npm, so eventually I decided to create my own. Maybe | |
* someone will find it useful. | |
* | |
* | |
* Installation (using npm): | |
* | |
* npm install -g karma-cli | |
* npm install -g karma --save-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//+ fn -> [a] | |
var getParameterNames = (function () { | |
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg, | |
ARGUMENT_NAMES = /([^\s,]+)/g; | |
return function (fn) { | |
var fnStr = fn.toString().replace(STRIP_COMMENTS, ''), | |
names = fnStr.slice(fnStr.indexOf('(')+1, fnStr.indexOf(')')).match(ARGUMENT_NAMES); | |
return names || []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var log = console.log.bind(console); | |
// Core component (not curried). | |
// compose(g, f) === function (x) { return g(f(x)); } | |
// Takes any number of functions as arguments | |
// from underscore.js | |
function compose (/* fn1, fn2, ... */) { | |
var funcs = arguments; | |
return function() { | |
var args = arguments; |