Skip to content

Instantly share code, notes, and snippets.

View viebel's full-sized avatar

Yehonathan Sharvit viebel

View GitHub Profile
@viebel
viebel / klipse_first_contact.cljs
Created August 5, 2016 14:29
Klipse first contact
(def check= (fn [a b]
(println "calling check= with: " a b)
(if (= a b)
'😃
'😡)))
(check= 5 4)
@viebel
viebel / fibonacci_tail_y.cljs
Created August 8, 2016 03:56
Fibonnaci: Tail call recursion without names (kind of Y combinator)
((fn [m] (((fn [f] (f f))
(fn [func]
(fn [n a b i]
(if (= n i)
b
((func func) n b (+ a b) (inc i)))))) m 0 1 1))
20)
@viebel
viebel / y_combinator_memo_printer.cljs
Last active August 8, 2016 18:45
Y combinator applications in clojure: memo and printer
(def Y (fn [f]
((fn [x]
(x x))
(fn [x]
(f (fn [y]
((x x) y)))))))
(defn memo []
(let [hist (atom {})]
(fn [f]
((f => f(f)))
(func => n => (n === 0) ? 1 : (n * func(func)(n - 1)))
(19)
(ns zones.tests.core
(:refer-clojure :exclude [binding get set])
(:require [zones.core-fn :refer [default-zone]])
(:require-macros [zones.core :refer [binding bound-fn*]]))
; -- helpers ----------------------------------------------------------------------------------------------------------------
(defn default-zone-str []
(ns my.ns
(:require-macros
[gadjett.core :as gadjett :refer [dbg]]))
(dbg (map inc [1 2 3 4]))
(ns my.lambda$macros)
; from here: http://matt.might.net/articles/implementing-a-programming-language/
(defmacro dbg[x]
`(let [x# ~x]
(println (str '~x ": " x#))
x#))
(def car first)
(def cdr rest)
@viebel
viebel / reduce-by-key.clj
Created August 30, 2016 09:00
scala's reduceByKey in clojure
; in klipse, add the gadjett path:
; http://app.klipse.tech/?external-libs=[https://raw.githubusercontent.com/viebel/gadjett/master/src/]
(ns my.ns
(:require-macros [gadjett.core :refer [dbg]]))
(defn reduce-by-key [s]
(into [] (let [f +]
(reduce (fn [res [k v]]
(assoc res k (f (res k 0) v)))
@viebel
viebel / color-element.cljs
Created August 30, 2016 19:18
This gist is use by a live demo
(ns my.color
(:require
[goog.dom :as dom]
[viebel.gist-3800b8ebae5292921c7d6fcb6c995c1f.raw.body-color :refer [set-bg-color-element]]))
(let [colors ["blue" "red" "yellow" "magenta" "cyan" "green" "purple" "coral" "dodgerblue" "pink"]]
(set-bg-color-element (dom/getElement "klipse-color") (rand-nth colors)))
@viebel
viebel / color-element.cljs
Created August 30, 2016 19:18
This gist is use by a live demo
(ns my.color
(:require
[goog.dom :as dom]
[viebel.gist-3800b8ebae5292921c7d6fcb6c995c1f.raw.body-color :refer [set-bg-color-element]]))
(let [colors ["blue" "red" "yellow" "magenta" "cyan" "green" "purple" "coral" "dodgerblue" "pink"]]
(set-bg-color-element (dom/getElement "klipse-color") (rand-nth colors)))