This file contains hidden or 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 '[clojure.zip :as z]) | |
| ; make a tree using vectors | |
| (def data [1 [2 3]]) ; | |
| data ; => [1 [2 3]] | |
| ; make a zipped version | |
| (def dz (z/vector-zip data)) | |
| dz ; => [[1 [2 3]] nil] (nil for where the cursor data will be; but we haven't traversed anywhere) |
This file contains hidden or 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 unnamed = function(){ | |
| var fns = [].slice.call(arguments); | |
| return function(){ | |
| var args = [].slice.call(arguments); | |
| return fns.map(function(fn){ return fn.apply(null, args) }) | |
| } | |
| } |
This file contains hidden or 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
| /* | |
| turns a binary function into a variadic function via reduction | |
| */ | |
| var reducify = function(fn){ | |
| return function(){ | |
| var args = [].slice.call(arguments) | |
| return args.reduce(fn) | |
| } |
This file contains hidden or 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 bundle = function(){ | |
| var fns = [].slice.call(arguments) | |
| return function(){ | |
| var args = [].slice.call(arguments) | |
| fns.forEach(function(fn){ fn.apply(null, args) }) | |
| } | |
| } | |
| var f1 = function(a, b){ console.log(a + b) } |
This file contains hidden or 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.prototype.curry = function () { | |
| var slice = Array.prototype.slice, | |
| args = slice.apply(arguments), | |
| that = this; | |
| return function _curried() { | |
| var fn = Function.prototype.bind.apply(that, args.concat(slice.apply(arguments))); | |
| fn.prototype = that.prototype; | |
| if ( this instanceof _curried ) return new fn(); | |
| else return fn(); |
This file contains hidden or 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 deepClone(o) { | |
| return (typeof o !== 'object' || o === null) ? o | |
| : (o instanceof Array) ? o.map(deepClone) | |
| : Object.keys(o).reduce(function (result, key) { | |
| result[key] = deepClone(o[key]) | |
| return result | |
| }, Object.create(Object.getPrototypeOf(o))) } |
This file contains hidden or 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 dotGet = function(o, propStr){ | |
| var getProp = function(o, name){ | |
| return ( typeof o == 'object' && o != null && name in o ) ? o[name]: undefined | |
| } | |
| return propStr.split('.').reduce(getProp, o) | |
| } | |
| // tests | |
| var o = { x: { y: { z: 'test', bar: null } } } |
This file contains hidden or 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
| /* | |
| LucidJS is a lib with a .emitter constructor function (one that doesn't require the new keyword; what i | |
| tend to call informal constructor functions). It provides an object with the normal pub/sub methods; .on, | |
| .off and .trigger | |
| */ | |
| var player = _.extend({ | |
| x: 0 | |
| , y: 0 | |
| , move: function(x, y){ |
This file contains hidden or 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 attachEvent(el, action, callback){ | |
| if (el.addEventListener) { | |
| el.addEventListener(action, callback, false); | |
| } else if (el.attachEvent) { | |
| el.attachEvent('on' + action, (function (ele) { return callback; })(el) ); | |
| } | |
| } | |
| inputKeyup: function (courseType){//event that's triggered on the input keyups | |
| var currentRequest; | |
| return function (e){ |