This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/bb | |
| (import '[java.io ByteArrayOutputStream]) | |
| (import '[java.util Base64]) ; | |
| (import '[java.util.zip Inflater]) ; | |
| (defn uncompress [source-bytes] | |
| (let [inflater (doto (Inflater.) | |
| (.setInput source-bytes)) | |
| outputStream (new ByteArrayOutputStream (count source-bytes)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bb | |
| ; run the script from any dir to serve its files | |
| (require '[babashka.deps]) | |
| (def deps '{:deps {io.github.babashka/http-server | |
| {:git/sha "b38c1f16ad2c618adae2c3b102a5520c261a7dd3"}}}) | |
| (babashka.deps/add-deps deps) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns same-thread-executor | |
| "handy in unit tests to have things happen straight away" | |
| (:import (java.util.concurrent ExecutorService Future))) | |
| (defn executor [] | |
| (reify ExecutorService | |
| (^Future submit [_ ^Callable f] | |
| (let [r (f)] | |
| (reify Future | |
| (get [_] r)))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (slingshot.slingshot/try+ | |
| (kaocha.plugin.cloverage/cloverage-main-hook (kaocha.repl/config)) | |
| (catch :kaocha/early-exit m | |
| (prn m))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns com.widdindustries.reagent-interval | |
| "functions to create reagent reactions (ie ratoms) whose value changes | |
| as an argument function is called periodically" | |
| (:require [reagent.ratom :as ratom] | |
| [reagent.core :as r])) | |
| (defn interval-async | |
| "create ratom whose value will initially be initial-state, | |
| and thereafter may change as f is called with the 'state' atom every delay-ms" | |
| [f delay-ms initial-state] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns delete-on-close-fileinput-stream) | |
| (defn create-fis [^java.io.File f] | |
| (proxy [java.io.FileInputStream] [f] | |
| (close [] | |
| (try | |
| (proxy-super close) | |
| (finally | |
| (.delete f)))))) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ; demonstrating that offset names such as EST, CEST etc are not always parsed properly into ZonedDateTime. | |
| ; EST, CEST are defined as fixed offsets from UTC so are not ambiguous in that respect, although apparently the same abbreviation | |
| ; is used more than once for the same thing in some cases! Ideally they could be parsed to OffsetDateTime, | |
| ; but I can't find a way to get that working. Comment if you know how ;-) | |
| ; old parse api | |
| (-> | |
| (SimpleDateFormat. "M/d/y, H:m z") | |
| (.parse "3/26/2020, 14:00 EST")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns com.widdindustries.safe-subs) | |
| (defn subs-safe | |
| "like clojure.core/subs but more forgiving" | |
| ([^String s start] (subs-safe s start (count s))) | |
| ([^String s start end] | |
| (when s | |
| (let [end (if (> end (count s)) | |
| (count s) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (ns streaming | |
| "read-write large json arrays with jsonista - techniques from | |
| https://cassiomolin.com/2019/08/19/combining-jackson-streaming-api-with-objectmapper-for-parsing-json/ | |
| comment at end shows running/testing code" | |
| (:require [jsonista.core :as j]) | |
| (:import (com.fasterxml.jackson.databind ObjectMapper) | |
| (com.fasterxml.jackson.core JsonToken JsonGenerator JsonParser) | |
| (java.io OutputStream ByteArrayOutputStream ByteArrayInputStream InputStream))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {:paths ["."] | |
| :deps {time-literals/time-literals {:mvn/version "0.1.5"} | |
| com.cognitect/transit-clj {:mvn/version "0.8.319"} | |
| com.cognitect/transit-cljs {:mvn/version "0.8.256"} | |
| }} |