Skip to content

Instantly share code, notes, and snippets.

Jeroen van Dijk jeroenvandijk

Block or report user

Report or block jeroenvandijk

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
@jeroenvandijk
jeroenvandijk / clojure_watch_refs.md
Last active May 15, 2019
Weird watch behaviour
View clojure_watch_refs.md

I am observing this weird behaviour of watching a clojure ref. It seems to behave wrong/delayed when not wrapped in a let block:

(let []
  (def ^{:flag 1} v 1))

(def ^{:flag 2} v 2)

(add-watch #'v ::listener (fn [_key _ref old-value new-value]
                            (println "old " old-value ", new" new-value "new-meta " _ref (select-keys (meta _ref) [:flag]))))
@jeroenvandijk
jeroenvandijk / clojure_js.clj
Created Apr 17, 2019
(GraalVM) clojure -> js
View clojure_js.clj
(ns clojure_js
(:gen-class)
(:import [javax.script
ScriptEngineManager
ScriptException
SimpleBindings]))
;; GraalVM doesn't like reflections
(set! *warn-on-reflection* true)
View git.zsh.clj
(defcmd git [& [dispatch :as args]]
(if (= dispatch "browse")
(let [{:keys [code stderr]
remote-url :stdout} (sh-value "git" "remote" "get-url" "origin")]
(if (zero? code)
(do (println "Opening" remote-url)
(sh "open" (clojure.string/trim remote-url)))
(println stderr)))
(eval `(sh "git" ~@args))))
@jeroenvandijk
jeroenvandijk / .closhrc.cljc
Created Apr 8, 2019
First experiment with closhrc
View .closhrc.cljc
(defcmd git [& [dispatch :as args]]
(if (= dispatch "browse")
(let [{:keys [code stderr]
remote-url :stdout} (sh-value "git" "remote" "get-url" "origin")]
(if (zero? code)
(do (println "Opening" remote-url)
(sh "open" (clojure.string/trim remote-url)))
(println stderr)))
(eval `(sh "git" ~@args))))
@jeroenvandijk
jeroenvandijk / README.md
Last active Jan 17, 2019
boot-clj + rebl
View README.md
@jeroenvandijk
jeroenvandijk / closhrc.clj
Created Oct 16, 2018
Example ~/.closhrc file
View closhrc.clj
;; See https://github.com/dundalek/closh/
(defn eval-string [s]
(eval (clojure.edn/read-string
(str "(do" s ")"))))
(defn closhrc []
(slurp (str (getenv "HOME") "/.closhrc")))
(defn eclosh []
@jeroenvandijk
jeroenvandijk / repl_compile.clj
Last active Oct 4, 2018
Repl compiling Clojure
View repl_compile.clj
(defn compile-inline [ns-name code]
(let [tmp-dir *compile-path*
sanitized-ns-name (.replace (str ns-name) "-" "_")
clj-file (clojure.java.io/file (str tmp-dir "/" (clojure.string/join "/" (clojure.string/split sanitized-ns-name #"\.")) ".clj"))]
(clojure.java.io/make-parents clj-file)
(with-open [file (clojure.java.io/writer clj-file)]
(binding [*out* file]
@jeroenvandijk
jeroenvandijk / eugene_and_jeroen.clj
Last active May 16, 2018 — forked from skuro/README.md
Dutch Clojure Meetup #102
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 (clojure.java.io/file f))))
@jeroenvandijk
jeroenvandijk / strict_keys_spec.clj
Last active Aug 22, 2018
clojure.spec being strict on superfluous keys
View strict_keys_spec.clj
;; If you want to fail before your old https://github.com/plumatic/schema
;; function fails the strict-keys macros below will help you find it.
(require '[clojure.spec.alpha :as s]
'[clojure.set])
(defn allowed-keys? [ks]
(fn [m]
(empty? (clojure.set/difference (set (keys m)) ks))))
View set_and_identity.md

Empty sets are always identical (apparently)

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

But when we add values this changes

(identical? #{1} #{1}) ;=> false
You can’t perform that action at this time.