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 request = require('request'); | |
var fs = require('fs'); | |
// file watches seem fuxed so I have some hacky workarounds in here | |
/** | |
* @param url (string) url to get like: "http://www.google.com" | |
* @param path (string) path to file like: "/tmp/test/myfile.js" | |
* @param callback(err, stuff) | |
*/ |
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 async = require('async'); | |
function getUserFriends(userName, next) { | |
db.users.findOne({name:userName}, foundUser); | |
function foundUser(err, user) { | |
err ? next(err) : getFriendsById(user.id, gotFriends); | |
function gotFriends(err, friends) { | |
if (err || user.type != 'power user') { |
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
// prototype chain used to create a projection of current object as original + changes | |
// the return object is always an instance of the provided object, changes form a change-set | |
// todo deal with deeply nested prototype chains | |
function seal(d) { | |
var x = _seal(d); | |
if (_.isObject(d)) { | |
_.each(d, function(v, k) { | |
if (d.hasOwnProperty(k) && _.isObject(v)) { | |
x[k] = seal(v); | |
} |
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
angular.module("dynacache", []) | |
.service("dynacache", function($http) { | |
// drop in replacement for $http | |
// currently supports "get", "post", "put", "jsonp" methods | |
// caches response body in localforage (http://mozilla.github.io/localForage/) | |
// subsequent requests immediately serve up local data | |
// whilst fetching new data from the server | |
// once ajax returns, new data replaces old by firing success handler once again | |
// expects lodash _ global to be present | |
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 jaccardIndex(s1, s2) { | |
// Jaccard index: http://en.wikipedia.org/wiki/Jaccard_index | |
// size of the intersection divided by the size of the union of the sample sets | |
s1 = _.isArray(s1) ? s1 : _.keys(s1); | |
s2 = _.isArray(s2) ? s2 : _.keys(s2); | |
return _.intersection(s1, s2).length / _.union(s1, s2).length | |
} |
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 es = require('event-stream'), | |
gulp = require('gulp'), | |
riot = require('gulp-riot'), | |
rimraf = require('gulp-rimraf'), | |
jshint = require('gulp-jshint'), | |
stylus = require('gulp-stylus'), | |
concat = require('gulp-concat'), | |
uglify = require('gulp-uglify'), | |
notify = require("gulp-notify"), | |
plumber = require('gulp-plumber'), |
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 webpack = require('webpack'), | |
path = require('path'), | |
ExtractTextPlugin = require("extract-text-webpack-plugin"), | |
isDev = process.env.NODE_ENV; | |
var config = { | |
cache: true, | |
resolve: { | |
extensions: ["", ".js", ".css", ".styl"] |
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
/** | |
* forceUpdateOnState | |
* | |
* @param state immstruct structure | |
* @returns component mixins {componentWillMount, componentWillUpdate, componentWillUnmount} | |
* | |
* the parent component should provide to the target component | |
* a map of prop names as keys for cursors and period delimited path strings | |
* on as 'cursors' property, e.g. <div cursors={{foo: 'bar.foo'}}></div> | |
* in the above example: props.foo = state.reference(['bar', 'foo']).cursor() |
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 Map(keys, values) {return new _Map(keys, values)} | |
function _Map(keys, values) {this.clear(keys, values);} | |
_Map.prototype = { | |
set: function(key, value) { | |
var i = this.indexOf(key); | |
this._keys[i] = key; | |
this._values[i] = value; | |
return i !== this._keys.length; | |
}, |
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
// a normalize function constructor for mapping from one range of numbers to another | |
// actually it is 4 ranges, one from mid to max another from min to mid for each domain | |
// so given 3 input (domainA) numbers for min, mid, max | |
// and given 3 output (domainB) numbers or arrays of any length of numbers also for min, mid, max | |
// the constructor function will return a normalize function that wil convert any number in domainA to domainB | |
// | |
// example: | |
// converting a value from -1 to 1 to a color ramp red to green | |
// with a white neutral in the middle and alpha evenly interpolated | |
// |
OlderNewer