Skip to content

Instantly share code, notes, and snippets.

View rodnaph's full-sized avatar
🈲
On vacation

Rhodri Pugh rodnaph

🈲
On vacation
View GitHub Profile
@rodnaph
rodnaph / core.async-lazy-sequence
Last active December 27, 2015 00:29 — forked from gerritjvv/core.async-lazy-sequence
Not tested, but can use first, and need recur to not consume stack?
(use 'clojure.core.async)
;this is the function you want to use
(defn lazy-channels [chs]
(lazy-seq
(cons (first (alts!! chs))
(recur chs))))
@rodnaph
rodnaph / lcss.clj
Last active December 22, 2015 17:59 — forked from owainlewis/lcss.clj
(ns sexp-css.core)
(defn- wrap [forms] (str "{" forms "}"))
(defn map-to-form [m] (let [outer-forms (reduce (fn [out-vec [k v]] (conj out-vec (str (name k) " : " v))) [] m) inner-forms (->> outer-forms (interpose ";") (apply str))] (wrap inner-forms)))
(defmacro defrule [selector & forms] `(str ~selector (apply map-to-form (vector ~@forms))))
(defn px [n] (when (number? n) (str n "px")))
(defn mixin [rule & forms] (merge rule (into {} forms)))
(def my-mixin
{:height "20px"
:width "100px"})
@rodnaph
rodnaph / clojurescript
Last active December 16, 2015 13:38 — forked from jhickner/clojurescript
(defn debounce
([f] (debounce f 1000))
([f timeout]
(let [id (atom nil)]
(fn [evt]
(if (not (nil? @id))
(js/clearTimeout @id))
(reset! id (js/setTimeout
(partial f evt)
timeout))))))