Instantly share code, notes, and snippets.

View closhrc.clj
;; See
(defn eval-string [s]
(eval (clojure.edn/read-string
(str "(do" s ")"))))
(defn closhrc []
(slurp (str (getenv "HOME") "/.closhrc")))
(defn eclosh []
View repl_compile.clj
(defn compile-inline [ns-name code]
(let [tmp-dir *compile-path*
sanitized-ns-name (.replace (str ns-name) "-" "_")
clj-file ( (str tmp-dir "/" (clojure.string/join "/" (clojure.string/split sanitized-ns-name #"\.")) ".clj"))]
( clj-file)
(with-open [file ( clj-file)]
(binding [*out* file]
View eugene_and_jeroen.clj
(ns clojure-dojo.core)
(import '[javax.imageio ImageIO]
'[java.awt.image BufferedImage])
(def img (let [f "resources/image.png"]
(ImageIO/read ( f))))
View strict_keys_spec.clj
;; If you want to fail before your old
;; function fails the strict-keys macros below will help you find it.
(require '[clojure.spec.alpha :as s]
(defn allowed-keys? [ks]
(fn [m]
(empty? (clojure.set/difference (set (keys m)) ks))))

Empty sets are always identical (apparently)

(identical? #{} #{}) ;=> true

But when we add values this changes

(identical? #{1} #{1}) ;=> false

External dependencies: a different approach?

Libraries like offer a way to share reusable components/namespaces. The downside is that it is impossible to customize (without weird hacks or code). Often it is easier to copy-paste the code in your repo.

What if we could automate the copy-pasting in these cases? I would like to propose an idea for a (leiningen) plugin to share code without the pains of normal dependencies. No (Leftpad)[] issues.


  • No external dependencies (no risk of losing a remote dependency e.g. read about left-pad issues [1])
  • Less work than copy-pasting
  • No conflicts between dependencies
View example.clj
(ns adgoji.rum.reconciler.example
(:require [rum.core :as rum]
[adgoji.rum.subscriptive :as sub]))
(println "This text is printed from src/adgoji.rum.reconciler/core.cljs. Go ahead and edit it and see reloading in action.")
;; define your app data so that it doesn't get over-written on reload
View search.clj
(:require [ :as priority-map]))
(defprotocol IStack
(next-node [_])
(rest-nodes [_])
(add-nodes [_ nodes]))
(defrecord Queue [queue]
View sample_log_normal.clj
(require '[incanter.core :as incanter])
;; From
(defn sample-log-normal [n & {:keys [mean sd]}]
(let [sd-log-part (incanter/log (+ 1.0 (/ (* sd sd) (* mean mean))))
mu (- (incanter/log mean) (* 0.5 sd-log-part))
sigma (incanter/sqrt sd-log-part)]
(incanter/exp (incanter.stats/sample-normal n :mean mu :sd sigma))))