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
cljs.user=> (ns my.ns$macros) | |
nil | |
my.ns$macros=> (defmacro hello[x] x) | |
true | |
my.ns$macros=> (my.ns/hello 19) | |
19 |
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
cljs.user=> (ns my.ns$macros) | |
nil | |
my.ns$macros=> (defmacro hello[x] x) | |
true | |
my.ns$macros=> (my.ns/hello 19) | |
19 |
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 om.next.spec | |
(:require [cljs.spec :as s])) | |
(s/def ::ident (s/and vector? (s/cat :ident keyword? :value #(not (coll? %))))) | |
(s/def ::join-key (s/or :prop keyword? :ident ::ident)) | |
(s/def ::join (s/and (s/map-of ::join-key ::query) #(= (count %) 1))) | |
(s/def ::union (s/and (s/map-of keyword? ::query) #(> (count %) 1))) | |
(s/def ::param-expr | |
(s/cat :query-expr ::query-expr |
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
(extend-type object | |
ILookup | |
(-lookup | |
([this k] | |
(-lookup this k nil)) | |
([this k not-found] | |
(let [k (name k)] | |
(if (.hasOwnProperty this k) | |
(aget this k) | |
not-found))))) |
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 set-bg-color [c] | |
(set! (.. js/document -body -style -backgroundColor) c)) | |
(set-bg-color "green") |
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
data = function() { | |
var sin = [], | |
cos = []; | |
for (var i = 0; i < 100; i++) { | |
sin.push({ | |
x: i, y: Math.sin(i/10)} | |
); | |
cos.push({ | |
x: i, y: .5 * Math.cos(i/10)} | |
); |
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
function cartesianProductOf() { | |
return _.reduce(arguments, function(a, b) { | |
return _.flatten(_.map(a, function(x) { | |
return _.map(b, function(y) { | |
return x.concat([y]); | |
}); | |
}), true); | |
}, [ [] ]); | |
}; |
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 bar(x) { | |
return x + x; | |
} |