Skip to content

Instantly share code, notes, and snippets.

Avatar

Michiel Borkent borkdude

View GitHub Profile
@borkdude
borkdude / session.java
Created Jun 22, 2021
Decompiled Clojure
View session.java
$ clj -Sdeps '{:deps {com.clojure-goes-fast/clj-java-decompiler {:mvn/version "0.3.0"}}}'
Clojure 1.10.1
user=> (require '[clj-java-decompiler.core :refer [decompile]])
nil
user=> (decompile (do (ns foo.bar) (defn foo [])))
// Decompiling class: foo/bar$loading__6721__auto____199
package foo;
import clojure.lang.*;
@borkdude
borkdude / promised_let.cljs
Last active Jun 15, 2021
promised-let from Chlorine's repl-tooling
View promised_let.cljs
(ns promised-let
(:require [sci.core :as sci]))
(def ^:private promised-let
"Async let macro from https://github.com/mauricioszabo/repl-tooling."
^:sci/macro
(fn [_&form _&env bindings & body]
(let [binds (->> bindings (partition-all 2 2) reverse)]
(loop [body (cons 'do body)
[[var elem] & rest] binds]
@borkdude
borkdude / DynamicJava.java
Created Jun 15, 2021 — forked from mukel/DynamicJava.java
Compiling Java code dynamically and running it in Espresso.
View DynamicJava.java
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;
@borkdude
borkdude / SetEnv.java
Last active May 21, 2021
C's setenv called from Java in a native image
View SetEnv.java
import org.graalvm.nativeimage.c.function.CFunction;
import org.graalvm.nativeimage.c.function.CFunction.Transition;
import org.graalvm.nativeimage.c.function.CLibrary;
import org.graalvm.nativeimage.c.CContext;
import org.graalvm.nativeimage.c.type.CCharPointer;
import com.oracle.svm.core.c.ProjectHeaderFile;
import org.graalvm.nativeimage.c.type.CTypeConversion;
import org.graalvm.nativeimage.c.type.CTypeConversion.CCharPointerHolder;
import java.util.List;
import java.util.Collections;
@borkdude
borkdude / transit_arrays.clj
Created May 19, 2021
Handling arbitrary array types with transit
View transit_arrays.clj
;; clojure -Sdeps '{:deps {com.cognitect/transit-clj {:mvn/version "RELEASE"}}}' -M /tmp/transit_arrays.clj
(require '[cognitect.transit :as transit])
(def default-write-handler
(transit/write-handler (fn [x]
(when (.isArray (class x))
"java.array"))
(fn [x]
(when (.isArray (class x))
@borkdude
borkdude / jasentaa.clj
Last active May 8, 2021
Jasentaa parser combinator with babashka
View jasentaa.clj
#!/usr/bin/env bb
(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {jasentaa/jasentaa
{:git/url "https://github.com/borkdude/jasentaa"
:sha "7161b0bd8029eb29760abd1eb3026a48a8cde318"}}})
(ns jasentaa.worked-example-1
(:require
@borkdude
borkdude / kern.clj
Created May 6, 2021
Kern parser combinator with bb
View kern.clj
#!/usr/bin/env bb
(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {org.blancas/kern {:git/url "https://github.com/borkdude/kern"
:sha "34a8c2f0c1ec5ab3e0e9aac56e6278abc3ed5a0b"}}})
(use 'blancas.kern.core
'blancas.kern.lexer.basic)
@borkdude
borkdude / cljstyle.clj
Created May 1, 2021
cljstyle with babashka
View cljstyle.clj
(require '[babashka.deps :as deps])
(deps/add-deps '{:deps {borkdude/spartan.spec {:git/url "https://github.com/borkdude/spartan.spec"
:sha "e5c9f40ebcc64b27b3e3e83ad2a285ccc0997097"}
mvxcvi/cljstyle {:git/url "https://github.com/borkdude/cljstyle"
:sha "d264e1e7e634d9f3b3b0aacb3829d430b826766c"}}})
(require '[spartan.spec]) ;; creates clojure.spec.alpha
(require '[cljstyle.config :refer [default-config]]
'[cljstyle.format.core :as fmt]
@borkdude
borkdude / 1) bb.edn
Last active May 28, 2021
Work bb.edn files
View 1) bb.edn
{:tasks {:requires ([babashka.fs :as fs])
:init (do (when (seq (fs/modified-since "deps.edn"
["deps.template.edn"
"../base/deps.edn"]))
(shell {:dir ".."} "script/gen-deps.clj")))
;; Maintenance tasks
install {:doc "Install frontend dependencies from NPM"
:task (shell "npm install")}
clean {:doc "Clean all artifacts"
@borkdude
borkdude / new.clj
Last active Apr 13, 2021
Babashka script that invokes -X clj-new/create
View new.clj
;; Usage:
;; bb new.clj -t luminus -n foobar/baz --force +h2
(require '[babashka.deps :as deps]
'[clojure.tools.cli :refer [parse-opts]])
(def deps '{:deps {com.github.seancorfield/clj-new
{:mvn/version "1.1.297"}}})
(def cli-opts [["-t" "--template NAME" "template"]