Skip to content

Instantly share code, notes, and snippets.

@henryw374
henryw374 / keybindings.json
Created January 5, 2026 17:00
vs code setup
[{"key": "f1", "command": "type",
"args": { "text": "(" },
"when": "editorTextFocus & !editorReadonly"}
]
@henryw374
henryw374 / create-zip-archive.clj
Created August 1, 2025 11:58
clojure append to zip file
(ns create-zip-archive
(:import (java.net URI)
(java.nio.charset StandardCharsets)
(java.nio.file FileSystem FileSystems Files Paths StandardOpenOption)))
(let [path (Paths/get "test.zip" (make-array String 0))
uri (URI/create (str "jar:" (.toUri path)))]
(with-open [fs (FileSystems/newFileSystem uri {"create" "true"})]
(let [nf (FileSystem/.getPath fs "new.txt" (make-array String 0))]
(with-open [writer (Files/newBufferedWriter nf, StandardCharsets/UTF_8, (into-array [StandardOpenOption/CREATE]))]
@henryw374
henryw374 / git-analyze-clojure.clj
Last active January 6, 2025 16:48
get clojure data on what files have changed in a git repo and when
(ns git-analyze
(:require [clojure.java.process :as process]
[clojure.string :as string]
[com.widdindustries.tempo :as tempo]))
(defn changed-files []
(->>
(process/exec "git" "log" "--pretty=%x0a%cI" "--name-only" "--date=iso")
(string/split-lines)
(remove string/blank?)
@henryw374
henryw374 / flexi_clock.clj
Created October 17, 2024 16:11
clojure java.time clock
(ns flexi-clock
(:import (java.time Clock Duration Instant ZonedDateTime)))
(defn clock
"potential library function (e.g. in tick or tempo).
This just implements the platform Clock - which works because non-test code only uses that API.
Any manipulation of time (which happens in testing code) is done via changing
what get-instant and get-zone return"
[get-instant get-zone]
@henryw374
henryw374 / webserver-ssl-context.clj
Created July 12, 2024 12:01
Import PKCS12 certificate chain directly in clojure
(ns webserver-ssl-context
(:require [clojure.java.io :as io]
[clojure.string :as str]
)
(:import (java.security KeyFactory KeyStore)
(java.security.spec X509EncodedKeySpec)
[javax.xml.bind DatatypeConverter]))
(defn parse-der-from-pem [pem begin-delimiter end-delimiter]
@henryw374
henryw374 / mutable_clock.clj
Last active July 1, 2024 14:08
mutable-clock java.time clock clojure
(ns mutable-clock
(:import (java.time Clock Duration Instant ZoneId)))
(definterface MutableClock
(setZone [zone])
(setInstant [instant]))
(defn mutable-clock [_instant _zone]
(let [instant-atom (atom _instant)
zone-atom (atom _zone)]
(ns com.widdindustries.minimal-ssl-context
(:import (java.security SecureRandom)
(javax.net.ssl SSLContext X509ExtendedTrustManager)))
(let [context (SSLContext/getInstance "TLS")]
(.init context nil
(into-array [(proxy [X509ExtendedTrustManager] []
(checkClientTrusted [& _])
(checkServerTrusted [& _]))])
@henryw374
henryw374 / tanstack-importmap-demo.js
Created November 7, 2023 16:50
tanstack react-router no build step
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>demo</title>
</head>
<body>
<div id="app" style="min-height:100%">
Hello world!
@henryw374
henryw374 / rounding_numbers.cljc
Last active September 23, 2023 10:59
teaching my children how to get a computer to do their maths homework
(ns rounding-numbers
"teaching my child how to get a computer to do their maths homework"
)
(defn round-number [original round-to]
(let [small-bit (mod original round-to)
round-up? (>= small-bit (* 5 (/ round-to 10)))
medium-bit (mod original (* 10 round-to))
number-that-goes-up-or-stays-the-same (- medium-bit small-bit)
big-bit (- original medium-bit)]
(ns com.widdindustries.kaocha-cljs2-ns-pattern-hook
"the only way I can find to filter kaocha-cljs2 tests by pattern. see comment block for usage"
(:require [kaocha.core-ext :as core-ext]
[kaocha.load :as load]))
(defn ns-filter [plan]
;(def plan plan)
;(println "About to start loading!")
(update plan :kaocha.test-plan/tests