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 numbers = [1,2,3]; | |
for (var i = 0, n = numbers.length; i<n; i++) { | |
var num = numbers[i]; | |
setTimeout(function() { | |
console.log(num); | |
}, 0); | |
} |
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
class Array | |
def to_hash(&block) | |
Hash[*self.map {|x| | |
[x, block.call(x)] | |
}.flatten(1)] | |
end | |
end | |
[1,2,3].to_hash {|x| | |
10*x |
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
column <FILENAME> -ts, |
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
; Make a regex behave like a function | |
; Inspired by: http://blog.klipse.tech/clojure/2016/04/07/ifn.html | |
(extend-type js/RegExp | |
IFn | |
(-invoke ([this s] (re-find this s)))) | |
(#"clojure" "clojurescript") | |
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
find . | xargs grep -wl ugly | xargs sed -i .bak 's/\<ugly\>/nice/g' |
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 namesOfArgs(fn) { | |
var STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/gm, | |
FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m, | |
FN_ARG_SPLIT = /,/, | |
fnText = fn.toString().replace(STRIP_COMMENTS, ''), | |
argDecl = fnText.match(FN_ARGS); | |
return argDecl[1].split(FN_ARG_SPLIT) | |
} |
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
;;First rule of macros: Don't write a macro if you a function can do the job! | |
(defn assoc-it[obj & more] | |
(let [path (vec (drop-last 1 more)) | |
val (last more)] | |
(assoc-in obj path val))) | |
(assoc-it {:a {:b 6}} :a :b 5 ) ;; {:a {:b 5}} | |
(defn get-it[obj & path] |
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
; given a string, determine whether it is a concatenation of english words | |
; string of digits only is considered an english word | |
; assume that strings are lower cased | |
; empty string: don't care | |
(defn word? [w] | |
(or (re-matches #"[0-9]" w) | |
(contains? #{"go" "hi" "my" "cat" "is" "nice" "mymy" "mymymy"} w))) |
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
(ns viebel.gist-368d3bec58d3ec47e935ad488bafb600.raw.color | |
(:require [viebel.gist-3800b8ebae5292921c7d6fcb6c995c1f.raw.body-color :refer [set-bg-color]])) | |
(set-bg-color "blue") |
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
(ns viebel.gist-3800b8ebae5292921c7d6fcb6c995c1f.raw.body-color) | |
(defn set-bg-color [c] | |
(set! (.. js/document -body -style -backgroundColor) c)) | |
(defn set-bg-color-element [e c] | |
(set! (.. e -style -backgroundColor) c)) |
OlderNewer