Skip to content

Instantly share code, notes, and snippets.

View beders's full-sized avatar

Jochen Bedersdorfer beders

View GitHub Profile
rickerbh / octopress-to-cryogen.clj
Created July 26, 2020 06:40
Babashka script to port posts from jekyll/octopress format to cryogen
(require '[ :as io]
'[clojure.string :as string]
'[ :refer [parse-opts]])
(def cli-options
[["-o" "--out DIR" "Output directory"
:default "out"]
["-s" "--source SOURCE" "Source directory"
:default "source/_posts"]
["-h" "--help"]])
zoren / download-blob.cljs
Created June 18, 2020 15:21
Download a BLOB via a object URL in ClojureScript
;; heavily inspired by Mariano Guerra
(defn download-blob [file-name blob]
(let [object-url (js/URL.createObjectURL blob)
(doto (js/document.createElement "a")
(-> .-href (set! object-url))
(-> .-download (set! file-name)))]
(.appendChild (.-body js/document) anchor-element)
(.click anchor-element)
lispyclouds / monads.clj
Last active May 17, 2020 02:37
Monads, simple made easier
; A simple demo of monadic composition of side effects
; Program to take 3 nubers as input and print their sum.
(defn read-and-add!
(print "Enter a number: ")
(+ prev (do (flush)
(Integer/parseInt (read-line)))))
(defn bind
borkdude / js_parser.clj
Last active August 6, 2023 22:14
Parse JavaScript in Clojure using the Google Closure Compiler
"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"]}]
sudodoki / flatten-maps.clj
Last active November 29, 2023 00:26
Flatten nested maps using clojure / clojurescript using compound keys
(defn get-key
[prefix key]
(if (nil? prefix)
(str prefix "-" key)))
(defn flatten-map-kvs
([map] (flatten-map-kvs map nil))
([map prefix]
(fn [memo [k v]]
Benchmark: transform values of a small map (1000000 iterations)
Avg(ms) vs best Code
141.61 1.00 (map-vals-map-iterable data inc)
146.86 1.04 (reduce-kv (fn [m k v] (assoc m k (inc v))) {} data)
156.66 1.11 (reduce-kv (fn [m k v] (assoc m k (inc v))) (empty data) data)
161.20 1.14 (transform MAP-VALS inc data)
211.53 1.49 (persistent! (reduce-kv (fn [m k v] (assoc! m k (inc v))) (transient {}) data))
227.91 1.61 (map-vals-map-iterable-transient data inc)
332.09 2.35 (transform [ALL LAST] inc data)
ravihara / jjs-require.js
Created January 13, 2016 13:23
CommonJS require function implementation for Nashorn / Java8
// Based on
"use strict";
(function() {
var System = java.lang.System,
File =,
FileInputStream =,
StringBuilder = java.lang.StringBuilder,
BufferedReader =,
InputStreamReader =;
CraZySacX / git.clj
Last active November 24, 2020 19:23
Clojure git wrapper
(ns org.ozias.git
(:require [me.raynes.conch :refer (with-programs)]))
(def ^:private git-porcelain
["add" "am" "bisect" "branch" "bundle" "checkout" "cherry-pick" "citool"
"clean" "clone" "commit" "describe" "diff" "fetch" "format-patch"
"gc" "grep" "gui" "init" "log" "merge" "mv" "notes" "pull" "push"
"rebase" "reset" "revert" "rm" "shortlog" "show" "stash" "status"
"submodule" "tag"])
hiredman / boot.cljs
Created March 15, 2013 04:43
clojurescript drag and drop
(defn handle-file-select [evt]
(.stopPropagation evt)
(.preventDefault evt)
(let [files (.-files (.-dataTransfer evt))]
(dotimes [i (.-length files)]
(let [rdr (js/FileReader.)
the-file (aget files i)]
(set! (.-onload rdr)
(fn [e]
(let [file-content (.-result (.-target e))
jboner / latency.txt
Last active May 29, 2024 05:28
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD