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 way to override RequireJS' loader so as to use request combiners | |
* like - https://github.com/rgrove/combohandler | |
* | |
* If you have multiple dependencies, say [a, b, c], requirejs fires | |
* three requests. This modification will allow you to combine these | |
* files and make a single request to `combo?a.js&b.js&c.js` | |
* On server-side, you can use a combohandler to serve concatinated | |
* files. | |
*/ |
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 delegate = function (node, type, listener, selector) { | |
var handler = node.addEventListener (type, function (e) { | |
var t = e.target, matched = false; | |
while (!node.isSameNode (t)) { | |
if (t.webkitMatchesSelector (selector)) { | |
matched = true; | |
break; | |
} else { | |
t = t.parentNode; | |
} |
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
#!/bin/sh | |
# A pre-commit hook for js | |
# It runs jshint on js files. | |
if git rev-parse --verify HEAD >/dev/null 2>&1 | |
then | |
against=HEAD | |
else | |
# Initial commit: diff against an empty tree object | |
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 |
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 makeAdder = function (a) { | |
return function (num) { | |
return num + a; | |
} | |
}; | |
var inc = makeAdder (1); | |
// Even after makeAdder has finished execution, | |
// inc maintains "a". | |
// That's Closure. |
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
// ==UserScript== | |
// @include https://www.facebook.com/* | |
// @include https://facebook.com/* | |
// @include http://www.facebook.com/* | |
// @include http://facebook.com/* | |
// @run-at document-start | |
// ==/UserScript== | |
document.addEventListener ('DOMNodeInserted', checksearch, false); |
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
(defn hey-paren--whats-up? [] | |
(println "Nothing.. Just hanging out.") | |
) | |
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
(defn rotate [n coll] | |
(let [[f s] (split-at (mod n (count coll)) coll)] | |
(concat s f))) | |
(rotate 2 [1 2 3 4 5]) | |
;; => (3 4 5 1 2) |
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
(defn next-nums [n] | |
(filter integer? ((juxt (partial + n) (partial * n) (partial / n)) 2))) | |
(defn collect-next [coll step x] | |
(if (coll x) | |
step | |
(let [res (set (mapcat next-nums coll))] | |
(recur res (inc step) x)))) | |
(defn get-steps [initial final] |
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
(defn smallest-common-number [& seqs] | |
(letfn [;; Get max of first items of seqs | |
(max-first [seqs] | |
(apply max (map first seqs))) | |
;; Test if first elemets are equal | |
(first-equal? [seqs] | |
(apply = (map first seqs))) | |
;; Filter values less than x | |
(update-seq [x coll] | |
(if (> x (first coll)) |
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 step-reduce | |
([f coll] | |
(step-reduce f (first coll) (rest coll))) | |
([f x coll] | |
(if (seq coll) | |
(let [next-coll (rest coll) | |
next-x (f x (first coll))] | |
(cons x (lazy-seq (step-reduce f next-x next-coll)))) | |
(cons x (lazy-seq '()))))) |
NewerOlder