Skip to content

Instantly share code, notes, and snippets.

Clojure ->css

A small alternative to the Garden CSS compiler that maps to modern CSS:

  1. It compiles to native nested rules.
  2. [:a :b :c {…}] compiles to a b c {…} not a, b, c {…}.
  3. Its grammar is flexible enough to allow arbitrary @-rules.
(defmacro defn* [name & fdecl]
(let [[docs impl] (split-with (some-fn symbol? string? map?) fdecl)]
(letfn [(wrap [[bindings & body]]
(let [[condition-map & body] (if (and (map? (first body))
(> (count body) 1))
body
(cons nil body))]
`(~bindings
~condition-map
;; TODO: do what you need here if you want to wrap the body
(ns shaun.lib.head-retention
"Provides a `let-drain` macro for when we need to dangerously create a binding for a
giant sequence. If we tag the consumption point with ^:draining, at
compile-time it will catch any head retention caused by symbolic references.
Non-problematic references can be manually tagged with ^:releasing to make the
checker pass. It won't catch subtler cases that we likely won't see, but it
will at least communicate that we are trying to avoid OOM in critical areas."
(:require
[clojure.walk :refer [macroexpand-all]]
[schema.core :as s]))
@shaunlebron
shaunlebron / reagent-flash.cljs
Last active March 26, 2026 19:18
Flashing intermediate changes inside a render batch in Reagent
(ns example.reagent-flash
(:require
[reagent.core :as r]
[reagent.ratom :as ra]
))
(defn- resolve-ratom [r* path]
(cond
(instance? Atom r*) [r* path]
(instance? ra/RAtom r*) [r* path]
(ns example.touch-surface
(:require
[applied-science.js-interop :as j]
[reagent.core :as r]
[reagent.hooks :as hooks]))
(defn with-nonpassive-event-listeners
"TODO: remove this when React supports non-passive event listeners:
https://github.com/facebook/react/issues/22794
@shaunlebron
shaunlebron / safe-navigation-clojure.md
Last active November 5, 2025 21:31
Safe Navigation in Clojure

Safe Navigation in Clojure

safe-> is a safe navigation macro for Clojure. It extends some-> with additional guards:

  1. doesn’t call nil values
  2. doesn’t call missing methods (ClojureScript only)

#!/bin/bash
# Cheatsheet for remembering Bash rules for Parameter Substitution:
# https://tldp.org/LDP/abs/html/parameter-substitution.html#PSUB2
# Fallback for unset vars
# Bash #——> like JavaScript
${a+b} #——> a && b
@shaunlebron
shaunlebron / timed-functions.clj
Created March 16, 2025 03:06
setTimeout and setInterval in clojure (java)
(ns user
(:import (java.util.concurrent Executors TimeUnit)))
(defn set-timeout [^Callable f ^long ms]
(doto (Executors/newScheduledThreadPool 1)
(.schedule f ms TimeUnit/MILLISECONDS)))
(defn set-interval [^Callable f ^long ms]
(doto (Executors/newScheduledThreadPool 1)
(.scheduleAtFixedRate f 0 ms TimeUnit/MILLISECONDS)))
@shaunlebron
shaunlebron / kalshi-signing.java
Last active December 1, 2025 17:14
Kalshi signing in Java
import java.nio.charset.StandardCharsets;
import java.security.PrivateKey;
import java.security.Security;
import java.security.Signature;
import java.util.Base64;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
import org.bouncycastle.openssl.PEMKeyPair;
import org.bouncycastle.openssl.PEMParser;