Skip to content

Instantly share code, notes, and snippets.

View viebel's full-sized avatar

Yehonathan Sharvit viebel

View GitHub Profile
@viebel
viebel / dump-1464465956723.cljs
Created May 28, 2016 20:05
ClojureScript REPL dump
cljs.user=> (ns my.ns$macros)
nil
my.ns$macros=> (defmacro hello[x] x)
true
my.ns$macros=> (my.ns/hello 19)
19
@viebel
viebel / dump-1464465971417.cljs
Created May 28, 2016 20:06
ClojureScript REPL dump
cljs.user=> (ns my.ns$macros)
nil
my.ns$macros=> (defmacro hello[x] x)
true
my.ns$macros=> (my.ns/hello 19)
19
@viebel
viebel / spec.cljs
Last active June 8, 2016 14:00 — forked from swannodette/spec.cljs
om.next query spec
(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
@viebel
viebel / regex_as_a_function.cljs
Last active June 10, 2016 07:51 — forked from alandipert/reinvoke.cljs
Make a regex behave like a function
; 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")
(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)))))
@viebel
viebel / green_body_background.cljs
Created June 15, 2016 05:40
green body background
(defn set-bg-color [c]
(set! (.. js/document -body -style -backgroundColor) c))
(set-bg-color "green")
@viebel
viebel / nvd3_chart.js
Created June 16, 2016 20:01
create a nvd3 chart
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)}
);
@viebel
viebel / to_hash.rb
Last active June 20, 2016 18:21
ruby array to hash
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
function cartesianProductOf() {
return _.reduce(arguments, function(a, b) {
return _.flatten(_.map(a, function(x) {
return _.map(b, function(y) {
return x.concat([y]);
});
}), true);
}, [ [] ]);
};
function bar(x) {
return x + x;
}