Skip to content

Instantly share code, notes, and snippets.

View jackrusher's full-sized avatar

Jack Rusher jackrusher

View GitHub Profile
;; If you have to do any sophisticated time calculations, including
;; calendrical stuff (day of week, &c), you should obviously use a
;; library to handle that stuff. However, if you only need some simple
;; things it can be very useful to leave ISO 8601 formatted dates in
;; string representation...
;; gold/oz 1995-01-03 to 2016-11-10
(def data
(->> (slurp "https://www.math.ttu.edu/~atrindad/tsdata/FTSdatasets/Gold.csv")
clojure.string/split-lines
@jackrusher
jackrusher / webdav.clj
Last active June 15, 2024 16:14
A minimal webdav server/synthetic filesystem that works with JVM Clojure and babashka. See comments for instructions!
(ns webdav
(:require [clojure.string :as str]
[clojure.data.xml :as xml]
[org.httpkit.server :as hk-server]))
;; add the XML namespace that we'll use later
(xml/alias-uri 'd "DAV:")
(defn dissoc-in
"Should be in the standard library..."
@jackrusher
jackrusher / apple-double-attrs.clj
Created July 20, 2023 13:01
Read the extended attributes from an AppleDouble file (those ._foo.txt files that Apple sprinkles on network drives, in Zip archives, &c).
(let [buf (java.nio.ByteBuffer/wrap byte-buffer-containing-appledouble-binary)
magic-number (.getInt buf)
version-number (.getInt buf)
_ (.position buf 24) ; after magic / version / filler bytes
num-entries (.getShort buf)
;; first entry header, for the data fork
_ (Integer/toUnsignedLong (.getInt buf)) ; entry-id
offset (Integer/toUnsignedLong (.getInt buf))]
;; some sanity checking
@jackrusher
jackrusher / reco.clj
Last active May 18, 2023 08:44
Super simple command line user/post recommender for BlueSky
#!/usr/bin/env bb
;; This script was written using:
;; https://github.com/babashka/babashka
;; ... go there for install instructions.
(ns reco
(:require [babashka.http-client :as http]
[cheshire.core :as json])
(:import [java.net URLEncoder]))
#!/usr/bin/osascript
tell application "Chrome" to tell the active tab of its first window
reload
end tell
@jackrusher
jackrusher / deploy.sh
Created January 17, 2022 15:22
Writing and deploying Google Cloud Functions in Clojure using NBB
# command line to deploy the project
gcloud functions deploy hello --runtime nodejs14 --trigger-http
;; Boot to PRINT10
;;
;; Use nasm to assemble the code to a binary:
;;
;; $ nasm -f bin -o boot.bin boot.nasm
;;
;; Use dd to make an empty floppy disk image:
;;
;; $ dd if=/dev/zero of=boot.flp ibs=1k count=1440
;;
@jackrusher
jackrusher / seq-primer.clj
Created June 1, 2021 12:55
Condensed visual tutorial in #Bauhaus style for a subset of the #Clojure seq API (inspired by similar JS tweets)
(def ■ '■)
(def ▲ '▲)
(def ● '●)
(first [● ■ ▲]) ; ●
(second [● ■ ▲]) ; ■
(nth [● ■ ▲] 2) ; ▲
(rest [● ■ ▲]) ; (■ ▲)
(last [● ■ ▲]) ; ▲
(butlast [● ■ ▲]) ; (● ■)

Twitter abuses all media file uploads, each type in its own way. If we want to upload a good looking animation loop from some low-color, high-detail generative art, we have to game their system's mechanisms.

  • don't upload a video file, they will re-encode it into absolute 💩

  • create a GIF, which they will auto-convert into a video file 😱

  • The frames of the GIF will be resized to an even-sized width using an extremely naive algorithm. Your GIF should be an even size (1000, 2000,

@jackrusher
jackrusher / trinity.js
Created March 29, 2021 09:23
A fast, minimal JS triple store implementation in ~70 lines of code
// three indices to efficiently support all lookups
function createDB() {
return {eav: new Map(),
ave: new Map(),
vea: new Map()};
}
function addToIndex(xs, x, y, z, triple) {
let ys = xs.get(x);
if(ys == undefined) {