Skip to content

Instantly share code, notes, and snippets.

Yehonathan Sharvit viebel

Block or report user

Report or block viebel

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@viebel
viebel / dump-1464465956723.cljs
Created May 28, 2016
ClojureScript REPL dump
View dump-1464465956723.cljs
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
ClojureScript REPL dump
View dump-1464465971417.cljs
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 Jun 8, 2016 — forked from swannodette/spec.cljs
om.next query spec
View spec.cljs
(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 Jun 10, 2016 — forked from alandipert/reinvoke.cljs
Make a regex behave like a function
View regex_as_a_function.cljs
; 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")
View js_objects_as_clj_objects.cljs
(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)))))
View green_body_background.cljs
(defn set-bg-color [c]
(set! (.. js/document -body -style -backgroundColor) c))
(set-bg-color "green")
@viebel
viebel / nvd3_chart.js
Created Jun 16, 2016
create a nvd3 chart
View nvd3_chart.js
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 Jun 20, 2016
ruby array to hash
View to_hash.rb
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
View cartesianProduct.js
function cartesianProductOf() {
return _.reduce(arguments, function(a, b) {
return _.flatten(_.map(a, function(x) {
return _.map(b, function(y) {
return x.concat([y]);
});
}), true);
}, [ [] ]);
};
View bar.js
function bar(x) {
return x + x;
}
You can’t perform that action at this time.