Skip to content

Instantly share code, notes, and snippets.

@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 February 22, 2023 19:41
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
@xfthhxk
xfthhxk / test-db.clj
Last active July 23, 2022 03:39
Clojure + Postgres Test Container + Flyway example
(ns test-db
"Example of using testcontainers and launching a postgres container with flyway migrations.
NB. databases are created but not destroyed which can be handy for debugging tests.
* Connecting to template1 from psql for example will cause create database to fail
* Based on ideas from https://github.com/opentable/otj-pg-embedded"
(:require [clj-test-containers.core :as tc]
[clojure.java.jdbc :as jdbc]
[clojure.string :as str])
(:import (org.flywaydb.core
Flyway)))
@xfthhxk
xfthhxk / aes256gcm.cljs
Created October 19, 2021 19:33
ClojureScript AES 256 GCM encrypt/decrypt compatible with the Buddy library
(ns aes256gcm
(:require ["crypto" :as crypto]
[clojure.string :as str]))
(defn url-safe-base64-encode
[s]
(-> s
(str/replace "+" "-")
(str/replace "/" "_")))
@xfthhxk
xfthhxk / tree_traversals.clj
Created April 19, 2021 02:06
Tree traversals
(ns tree-traversals)
(def tree
{:item 8
:left {:item 3
:left {:item 1
:left nil
:right nil}
:right {:item 6
:left {:item 4
@xfthhxk
xfthhxk / graph.clj
Created April 19, 2021 02:04
DFS & BFS in clojure
(ns graph)
(def graph
{:A {:children #{:E :B}
:population 200
:id :A}
:B {:children #{:A :C :E}
:population 300
:id :B}
:C {:children #{:B :D}