Skip to content

Instantly share code, notes, and snippets.

View hlolli's full-sized avatar
🛀

Hlöðver Sigurðsson hlolli

🛀
View GitHub Profile
@scttnlsn
scttnlsn / debounce.cljs
Created March 24, 2014 17:03
core.async debounce
(defn debounce [in ms]
(let [out (chan)]
(go-loop [last-val nil]
(let [val (if (nil? last-val) (<! in) last-val)
timer (timeout ms)
[new-val ch] (alts! [in timer])]
(condp = ch
timer (do (>! out val) (recur nil))
in (recur new-val))))
out))
@arichiardi
arichiardi / dump-npm-deps.sh
Created March 5, 2018 21:12
Dump the Clojure :npm-deps index
clojure -e "(require '[cljs.closure :as cc] '[clojure.pprint :refer [pprint]]) (pprint (cc/index-node-modules-dir $(cat cljsc_opts.edn)))" > npm-deps.edn
;; Rename clj/cljs/cljc buffers to their namespace name, so you see
;; `foo.bar.core' in the modeline, rather than `core.clj'
(advice-add 'rename-buffer :around #'plexus/clj-ns--rename-buffer-advice)
(defun plexus/clj-ns--rename-buffer-advice (rb-fun newname &optional unique &rest args)
(let ((filename (buffer-file-name (current-buffer)))
(buf-start (buffer-substring-no-properties (point-min) (point-min))))
(if (and (string-match "\\.clj[cxs]?$" filename)
(string-match "(ns \\([^\n )]+\\)" buf-start))
(match-string-no-properties 1 buf-start)