Skip to content

Instantly share code, notes, and snippets.

@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 March 6, 2025 03:21
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 March 6, 2025 16:39
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 January 4, 2025 20:03
Polymarket Data API Docs
@shaunlebron
shaunlebron / css-typography.md
Last active April 13, 2024 17:07
CSS typography

CSS Typography

We can do typographic things in CSS that we couldn’t before.

Hanging Indent

text-indent: 2em hanging; /* Safari and Firefox only */
@shaunlebron
shaunlebron / flexbox-rosetta.md
Last active April 13, 2024 17:32
Flexbox Rosetta Stone

Flexbox vs Inline alignment

flex-flow: row wrap shows how inline text alignment is a special case of flexbox:

TEXT-ALIGN:         left  | center | right | justify       | __           | __
→ JUSTIFY-CONTENT:  start | middle | end   | space-between | space-around | space-evenly

VERTICAL-ALIGN:     top   | middle | bottom | __
→ ALIGN-SELF: start | center | end | stretch
@shaunlebron
shaunlebron / swift-ui-syntax.md
Created January 3, 2024 19:50
Syntax of a SwiftUI app

Syntax of a SwiftUI app

The structure of a SwiftUI app uses a lot of Swift syntax to appear simple:

import SwiftUI


@main                         // <-- Attribute (potentially an attached macro)
struct MyApp: App {
(defmacro =>>
"Makes ->> faster if the first form is a collection, and the last form is `sequence`, `into`, or `reduce`"
;; adapted from: https://github.com/divs1210/streamer/blob/master/src/streamer/core.clj
[coll & xforms-and-term]
(let [[xforms term] ((juxt butlast last) xforms-and-term)]
(cond
;; sequence
(or (= term 'sequence)
(and (list? term)
(= (first term) 'sequence)))
@shaunlebron
shaunlebron / clojure-core-plus.md
Last active December 1, 2022 15:01
Clojure Core Plus