Skip to content

Instantly share code, notes, and snippets.

@xfthhxk
xfthhxk / shell.nix
Last active August 7, 2025 14:23
example using nix with clojure and other dev tools
{ use_zsh ? "true" }:
let
# nixos-25.05 stable as of 4 Aug 2025. See: https://status.nixos.org
nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/archive/ce01daebf8489ba97bd1609d185ea276efdeb121.tar.gz";
pkgs = import nixpkgs { config = {}; overlays = []; };
in
pkgs.mkShell {
packages = [
pkgs.clojure
@xfthhxk
xfthhxk / telemere-buffered-sink-handler.clj
Last active November 25, 2024 12:05
Clojure telemere handler for buffering signals and periodically draining to a sink
(defn handler:buffered-sink-handler
"Buffers signals up to `buffer/size` and invokes
`:buffer/signals-handler` when buffer is full or
`:buffer/drain-interval-millis` has elapsed.
`:buffer/signal-dropped` is a 1 arity function that receives
the signal that was dropped because the buffer was full.
The `sink` is a 1 arity function that receives
a coll of telemere signals."
([] (handler:buffered-sink-handler nil))
([{:keys [buffer/drain-interval-millis
@xfthhxk
xfthhxk / transducers.clj
Last active August 27, 2024 19:29
Clojure Transducer Notes
;; Transducer a portmanteau of transform and reducer?
(defn reducing-fn
([]
;; this 0 arity is called when no initial coll is provided to a transducer
;; This should return the starting state
(transient #{}))
([ans]
@xfthhxk
xfthhxk / transients.clj
Last active August 22, 2024 10:50
Clojure transients
;; get, get-in, keyword accessor, destructuring etc all work as expected
(get-in (transient {:a (transient {:b 2})}) [:a :b]) ;; => 2
(get-in (transient {:a {:b 2}}) [:a :b]) ;; => 2
(get-in (transient {:a (transient {:b (transient [10 11 12])})}) [:a :b 1]) ;; => 11
((transient {:a 1}) :a) ;; => 1
(:a (transient {:a 1})) ;; => 1
@xfthhxk
xfthhxk / project_setup.clj
Last active January 8, 2024 14:14
Project setup with babashka & spire
#!/usr/bin/env bb
;; NB. it can be helpful to do `sudo id` on the cmdline before running this script so that the privileged commands work
;; Spire doesn't yet have the ability to ask for a password when sudo is used
;;
;;
;; This script is an example of how to use babashka and spire to automate project setup for local development.
;; Sets up the local development environment so that necessary software is installed and https can be used.
;; You would tailor it to your needs.
@xfthhxk
xfthhxk / digital_signature.py
Last active October 2, 2023 20:52
Digital Signature in Python
#######################################################################
# 1. Generate public and private keys
# ```shell
# openssl genpkey -algorithm ED25519 -out ed25519.pem
# openssl pkey -in ed25519.pem -pubout > ed25519.pem.pub
# ```
# 2. Register the public key with the remote service
# 3. Ensure python requirements
# ```shell
# pip install requests cryptography
@xfthhxk
xfthhxk / digital-signature.js
Created October 2, 2023 19:27
Digital Signatures with Node
/*
# 1. Generate public and private keys
# ```shell
# openssl genpkey -algorithm ED25519 -out ed25519.pem
# openssl pkey -in ed25519.pem -pubout > ed25519.pem.pub
# ```
# 2. Register the public key with the remote service
# 3. Ensure node requirements
# ```shell
# npm install axios
@xfthhxk
xfthhxk / DigitalSignature.java
Last active October 2, 2023 21:02
Digital signatures with Java
/*
# 1. Generate public and private keys
# ```shell
# openssl genpkey -algorithm ED25519 -out ed25519.pem
# openssl pkey -in ed25519.pem -pubout > ed25519.pem.pub
# ```
# 2. Register the public key with the remote service
# 3. Compile
# ```shell
# javac DigitalSignature
@xfthhxk
xfthhxk / digital_signature.clj
Last active September 30, 2023 00:56
Digital Signatures using Clojure without dependencies
(ns digital-signature
(:require [clojure.string :as str])
(:import (java.security.spec PKCS8EncodedKeySpec X509EncodedKeySpec)
(java.security PublicKey PrivateKey Signature KeyFactory KeyPairGenerator)
(java.util Base64)))
(defn gen-key
[pem algo]
(let [priv-header "-----BEGIN PRIVATE KEY-----"
@xfthhxk
xfthhxk / roaring_bitmap.clj
Last active July 9, 2024 12:34
RoaringBitmap Clojure wrapper
(ns roaring-bitmap
(:refer-clojure :exclude [contains? empty? min max seq])
(:import (java.io
DataInput
DataOutput)
(java.nio
ByteBuffer)
(org.roaringbitmap
Container
ContainerPointer