Skip to content

Instantly share code, notes, and snippets.

Michiel Borkent borkdude

Block or report user

Report or block borkdude

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
View notes.md
@borkdude
borkdude / missing_test_assertion.clj
Last active Nov 4, 2019
Report missing test assertion in clojure.test
View missing_test_assertion.clj
(ns missing-test-assertion.core
(:require [clojure.test :refer [report *report-counters*]]))
(def state (atom 0))
(defn assertion-count []
(let [rc @*report-counters*]
(+ (get rc :pass 0)
(get rc :fail 0)
(get rc :error 0))))
View realize-max.edn
{:title "Realize a maximum number of elements."
:options "{:realize-max 100}"
:code "(range 100)"}
@borkdude
borkdude / reader_conditionals.clj
Last active Oct 31, 2019
Sci reader conditionals
View reader_conditionals.clj
{:title "Reader conditionals"
:options "{:read-cond :allow, :features #{:clj}}"
:code "#?(:clj 10 :cljs 20)"}
@borkdude
borkdude / projects.md
Last active Oct 3, 2019
clj-kondo, jet, edamame, sci, babashka
View projects.md

Overview of recent projects and how they relate:

  • clj-kondo: Clojure linter, compiled with GraalVM for fast startup. While implementing clj-kondo I realized that analyzed code could not only be linted, but also interpreted. This gave rise to sci.

  • jet: converts between JSON, EDN and Transit. Supports minimal query language in the spirit of jq. While implementing the query language for jet, I realized that using normal Clojure instead of a DSL was better for most Clojure users. This gave rise to sci.

  • edamame: EDN parser with location metadata and configurable dispatch table. This way of parsing is inspired by rewrite-clj, but it skips the intermediate node representation. This parser was extracted from sci.

@borkdude
borkdude / js_parser.clj
Last active Sep 7, 2019
Parse JavaScript in Clojure using the Google Closure Compiler
View js_parser.clj
#!/bin/sh
#_(
"exec" "clojure" "-Sdeps" "{:deps {org.clojure/clojurescript {:mvn/version \"1.10.520\"}}}" "$0" "$@"
)
;; running js_parser.clj "function foo(x) { var y = x + 1; }" will print:
;; [{:type :function, :name "foo", :body [{:variable-statement [{:lvalue "y", :initializer {:type :binary-op, :left "x", :operator "+", :right "1"}}]}], :params ["x"]}]
@borkdude
borkdude / repl_session.clj
Last active Aug 31, 2019
Safe read-eval with edamame and sci
View repl_session.clj
$ clj -Sdeps '{:deps {borkdude/edamame {:mvn/version "0.0.2"} borkdude/sci {:mvn/version "0.0.9"}}}'
Clojure 1.10.1
user=> (require '[sci.core :as sci])
nil
user=> (require '[edamame.core :as edamame])
nil
user=> (def trusted "{:version #=(slurp \"resources/EDAMAME_VERSION\")}")
#'user/trusted
user=> (edamame/parse-string trusted {:dispatch {\# {\= (fn [expr] (sci/eval-string (str expr) {:bindings {'slurp slurp}}))}}})
{:version "0.0.3-SNAPSHOT\n"}
@borkdude
borkdude / log.txt
Created Apr 8, 2019
Clojure stacktraces in JVM and GraalVM
View log.txt
---
JVM clojure.stacktrace/print-stack-trace
java.lang.NullPointerException: null
at clojure.core$name.invokeStatic (core.clj:1595)
clojure.core$name.invoke (core.clj:1589)
clj_kondo.main$print_findings$fn__3420.invoke (main.clj:30)
clj_kondo.main$print_findings.invokeStatic (main.clj:29)
clj_kondo.main$print_findings.invoke (main.clj:22)
clj_kondo.main$main.invokeStatic (main.clj:262)
@borkdude
borkdude / spec_graal.txt
Created Apr 4, 2019
Spec + Graal Native
View spec_graal.txt
$ clojure -A:native-image --verbose
Loading clj-kondo.main
Compiling clj-kondo.main
Building native image 'clj_kondo.main' with classpath 'classes:src:/Users/Borkdude/.m2/repository/com/cognitect/transit-java/0.8.337/transit-java-0.8.337.jar:/Users/Borkdude/.m2/repository/org/clojure/clojure/1.11.0-master-SNAPSHOT/clojure-1.11.0-master-SNAPSHOT.jar:/Users/Borkdude/.m2/repository/commons-codec/commons-codec/1.10/commons-codec-1.10.jar:/Users/Borkdude/.m2/repository/org/clojure/core.specs.alpha/0.2.44/core.specs.alpha-0.2.44.jar:/Users/Borkdude/.m2/repository/org/clojure/spec.alpha/0.2.177-SNAPSHOT/spec.alpha-0.2.177-SNAPSHOT.jar:/Users/Borkdude/.m2/repository/com/googlecode/json-simple/json-simple/1.1.1/json-simple-1.1.1.jar:/Users/Borkdude/.m2/repository/rewrite-clj/rewrite-clj/0.6.1/rewrite-clj-0.6.1.jar:/Users/Borkdude/.m2/repository/com/fasterxml/jackson/core/jackson-core/2.8.7/jackson-core-2.8.7.jar:/Users/Borkdude/.m2/repository/org/javassist/javassist/3.18.1-GA/javassist-3.18.1-GA.jar:/Users/Borkdude/.m
@borkdude
borkdude / fressian-read.txt
Created Mar 29, 2019
Error when using fressian/read-object
View fressian-read.txt
(fressian/read-object (fressian/create-reader (io/input-stream (io/file clj-cache-file))))
^
$ clojure -A:native-image --verbose
Loading clj-kondo.main
Compiling clj-kondo.main
Building native image 'clj_kondo.main' with classpath 'classes:src:/Users/Borkdude/.m2/repository/org/clojure/clojure/1.10.0/clojure-1.10.0.jar:/Users/Borkdude/.m2/repository/rewrite-clj/rewrite-clj/0.6.1/rewrite-clj-0.6.1.jar:/Users/Borkdude/.m2/repository/org/clojure/data.fressian/0.2.1/data.fressian-0.2.1.jar:/Users/Borkdude/.m2/repository/org/clojure/spec.alpha/0.2.176/spec.alpha-0.2.176.jar:/Users/Borkdude/.m2/repository/org/clojure/core.specs.alpha/0.2.44/core.specs.alpha-0.2.44.jar:/Users/Borkdude/.m2/repository/org/clojure/tools.reader/1.2.2/tools.reader-1.2.2.jar:/Users/Borkdude/.m2/repository/org/fressian/fressian/0.6.6/fressian-0.6.6.jar'
Executing [
/Users/Borkdude/Downloads/graalvm-ce-1.0.0-rc14/Contents/Home/bin/java \
-XX:+UnlockExperimentalVMOptions \
-XX:+EnableJVMCI \
You can’t perform that action at this time.