Skip to content

Instantly share code, notes, and snippets.

View jeroenvandijk's full-sized avatar

Jeroen van Dijk jeroenvandijk

View GitHub Profile
@jeroenvandijk
jeroenvandijk / malli_inline_output.clj
Created November 3, 2022 14:25
Malli inline validation printing
(ns malli.inline-output
(:require
[edamame.core :refer [parse-string]]
[malli.core :as m]
[malli.error :as me]))
;; -- helper code to find location data in an edn file
(defprotocol IUnwrap
(unwrap [_]))
@jeroenvandijk
jeroenvandijk / smart_middleware.clj
Last active February 9, 2022 16:00
An example of composing ring middleware in a more robust and intuitive way?
;; When middleware comes with a certain dependency order things get a bit tedious and error prone.
;; Consider example 1 below:
(defn add-cmd [req cmd]
(update req :cmd (fnil conj []) cmd))
(defn add-cmd-handler [cmd]
(fn [req]
@jeroenvandijk
jeroenvandijk / kahn_sort.clj
Last active January 20, 2022 18:16
Malli composite schema that reuses the values of the underlying values during data generation
;; Copy of https://gist.github.com/alandipert/1263783
;;
;; Copyright (c) Alan Dipert. All rights reserved.
;; The use and distribution terms for this software are covered by the
;; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
;; By using this software in any fashion, you are agreeing to be bound by
;; the terms of this license.
;; You must not remove this notice, or any other, from this software.
(ns alandipert.kahn
@jeroenvandijk
jeroenvandijk / com.plex.pms.plist
Created January 18, 2022 10:01 — forked from wahlmanj/com.plex.pms.plist
Plex Media center startup plist for use with launchctl
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.plex.pms</string>
<key>OnDemand</key>
<false/>
<key>ProgramArguments</key>
{:name "Search the Clojurians Slack-archive"
:author "Gert Goet"
:license "MIT"}
;;---
(when-some [q (js/prompt "Search the Clojurians Slack-archive:")]
(.open js/window (str "https://clojurians.zulipchat.com/#narrow/stream/180378-slack-archive/search/" q)))
@jeroenvandijk
jeroenvandijk / sorted.clj
Last active July 3, 2020 09:02
Babashka script for sorting clojure code lines
#!/usr/bin/env bb
(doseq [line (->> (file-seq (clojure.java.io/file (System/getenv "PWD")))
(filter #(.isFile %))
(filter (fn [f] (contains? #{"clj" "cljc" "cljs" "bb"}
(last (clojure.string/split (.getName f) #"\.")))))
(mapcat #(clojure.string/split-lines (slurp %)))
sort
)]
(println line))
@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 = [];