Skip to content

Instantly share code, notes, and snippets.

@piranha
piranha / ghost.restclient
Last active June 23, 2023 08:52
Making requests to Ghost from restclient.el (or generating JWT in elisp, whatever)
# use with https://github.com/pashky/restclient.el
:admin := <<
(let* ((key "649484dc581803f494a07f40:dbee81202550e7afe5a022405d8b5b10da9f24d18883c92d5331bace31f6796d")
(bits (split-string key ":"))
(jwt-header (base64url-encode-string
(json-serialize (list :alg "HS256"
:typ "JWT"
:kid (car bits)))))
(payload (base64url-encode-string

What

The world needs another utility lib for Clojure, since the existing ones are seldom accepting new stuff in. Ideally it would have an understandable rules how to add more stuff in, so that it's utility will grow over time.

What's not to replace

  • hashp is almost perfect (?), only needs (defmacro p [form] (p* form)) to call it in threading pipelines

Ideas to bring in

@piranha
piranha / cond+.clj
Last active April 4, 2024 16:18
cond+
(defmacro cond+ [& clauses]
(when-some [[test expr & rest] clauses]
(condp = test
:do `(do ~expr (cond+ ~@rest))
:let `(let ~expr (cond+ ~@rest))
:some `(or ~expr (cond+ ~@rest))
`(if ~test ~expr (cond+ ~@rest)))))
@piranha
piranha / standalone.clj
Last active January 20, 2025 12:28
Single-file Clojure script with dependencies
#!/usr/bin/env clojure -M
;;; setup
;; this classloader stuff is needed so that `add-lib` sees the DynamicClassLoader that's used by `require`
(.setContextClassLoader (Thread/currentThread) (clojure.lang.RT/baseLoader))
(require '[clojure.repl.deps :as deps])
(binding [clojure.core/*repl* true]
(deps/add-lib 'http-kit {:mvn/version "2.8.0"}))
;;; actual script
@piranha
piranha / co
Last active February 18, 2025 09:30
git branch checkout/delete via fzf
#!/bin/sh
set -eo errexit
sep=' '
# NOTE: $1 should not intersect with real branch names
case "$1" in
--LIST)
refname='%(refname:short)'
@piranha
piranha / sse.clj
Created March 27, 2025 11:51
http-kit sse
(ns something.core.sse
(:require [charred.api :as json]
[hiccup2.core :as hi]
[org.httpkit.server :as httpd]
[clojure.tools.logging :as log]))
(def ^:dynamic *report-ch* nil)
(declare sse!)