Skip to content

Instantly share code, notes, and snippets.

(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;
@shaunlebron
shaunlebron / polymarket.sign.clj
Last active June 8, 2025 23:23
Polymarket order signing in Clojure
(ns example.polymarket.sign
(:require
[cheshire.core :as json]
[clojure.string :as str])
(:import
(org.web3j.crypto Sign Credentials) ;; org.web3j/crypto "4.12.2"
(org.web3j.utils Numeric)
(java.util Base64)
(javax.crypto Mac)
(javax.crypto.spec SecretKeySpec)))
@shaunlebron
shaunlebron / polymarket-data-api-docs.md
Last active June 22, 2026 05:47
Polymarket Data API Docs