Skip to content

Instantly share code, notes, and snippets.

View jeroenvandijk's full-sized avatar

Jeroen van Dijk jeroenvandijk

View GitHub Profile
@jeroenvandijk
jeroenvandijk / multitime.clj
Last active June 12, 2020 15:49
Idea for multitime test in Babashka
;; Like https://github.com/ltratt/multitime but with the power of Clojure: multi-processor, shuffling, advanced statistics
;; export BABASHKA_CLASSPATH=$(clojure -Sdeps '{:deps {org.clojure/data.generators {:mvn/version "1.0.0"}, org.clojure/math.combinatorics {:mvn/version "0.1.6"}}}' -Spath)
(do
(require '[clojure.math.combinatorics :as combo]
'[clojure.data.generators :as gen])
(let [binaries ["../sci/tmp/sci-25ace7c"
"../sci/tmp/sci-3c01531"
"../sci/tmp/sci-6c8852d"]
@jeroenvandijk
jeroenvandijk / repl_usage.txt
Created May 8, 2020 10:25
Babashka spire pod wrapper
bb
user=> (babashka.pods/load-pod "./simple-pod.bb")
nil
user=> (require '[pod.babashka.spire :as spire])
nil
user=> (spire/magic! )
java.lang.NullPointerException
#error {
:cause "Invalid netstring. Unexpected end of input."
:via
@jeroenvandijk
jeroenvandijk / keybase.md
Last active May 5, 2020 18:49
keybase.md

Keybase proof

I hereby claim:

  • I am jeroenvandijk on github.
  • I am jeroenvandijk (https://keybase.io/jeroenvandijk) on keybase.
  • I have a public key whose fingerprint is EABD B08B 7E40 0750 54C2 9F31 1BDC C90E A3CA BA2D

To claim this, I am signing this object:

@jeroenvandijk
jeroenvandijk / sci_google_cloud.js
Created February 22, 2020 17:30 — forked from borkdude/sci_google_cloud.js
Google cloud function running sci
const { evalString } = require("@borkdude/sci");
let printlnArgs = null;
function println(...args) {
printlnArgs = args.map(arg => arg.toString()).join(" ");
}
exports.evalClojureExpr = (req, res) => {
const { text } = req.body;
try {
const result = evalString(text, {namespaces: {"clojure.core": {println: println}}});
let value = [];
@jeroenvandijk
jeroenvandijk / heredoc.clj
Created February 12, 2020 08:47 — forked from cgrand/heredoc.clj
An ugly hacky heredoc for Clojure
(defn heredoc []
(let [delim (.readLine *in*)]
(->> (repeatedly #(.readLine *in*))
(take-while #(not= delim %))
(interpose \newline)
(apply str))))
; The following lines are read (by the reader) as:
; "Look )(\"\\T\na here doc!\n"
#=(heredoc)"""
@jeroenvandijk
jeroenvandijk / datomic.schema_dump.clj
Last active January 23, 2020 10:58
(A) method to dump a datomic database schema
(ns datomic.schema-dump
(:require
[datomic.api :as d]
[clojure.pprint]))
(defmethod clojure.pprint/simple-dispatch datomic.db.DbId [v] (pr v))
(defmethod clojure.pprint/simple-dispatch datomic.function.Function [v] (pr v))
(defn database-url [name]
(str "datomic:mem://" name))
@jeroenvandijk
jeroenvandijk / .closhrc.cljc
Created April 8, 2019 14:03
First experiment with closhrc
(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 / git.zsh.clj
Last active August 29, 2019 17:16
bash to closh porting examples (https://github.com/dundalek/closh)
(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 / clojure_watch_refs.md
Last active May 15, 2019 08:45
Weird watch behaviour

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 April 17, 2019 12:16
(GraalVM) clojure -> js
(ns clojure_js
(:gen-class)
(:import [javax.script
ScriptEngineManager
ScriptException
SimpleBindings]))
;; GraalVM doesn't like reflections
(set! *warn-on-reflection* true)