Skip to content

Instantly share code, notes, and snippets.

View maxcountryman's full-sized avatar
🦀

Max Countryman maxcountryman

🦀
View GitHub Profile
@maxcountryman
maxcountryman / login.rs
Created October 4, 2023 15:15
A sketch of generalized user authentication based on tower-sessions.
use std::{marker::PhantomData, net::SocketAddr};
use async_trait::async_trait;
use axum::{
error_handling::HandleErrorLayer,
middleware::{self, Next},
routing::get,
Router,
};
use axum_core::{
@maxcountryman
maxcountryman / example.sh
Created January 9, 2023 19:57
Generating tags with GPT
echo -e $(curl -s https://api.openai.com/v1/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d '{"model": "text-davinci-003", "prompt": "Extract tags from the following text. Limit five tags. Output JSON.\\n\\nText: Folksonomy is a classification system in which end users apply public tags to online items, typically to make those items easier for themselves or others to find later. Over time, this can give rise to a classification system based on those tags and how often they are applied or searched for, in contrast to a taxonomic classification designed by the owners of the content and specified when it is published.[1][2] This practice is also known as collaborative tagging,[3][4] social classification, social indexing, and social tagging.\\n\\n<Output>", "temperature": 0, "max_tokens": 1000}' | jq .choices[0].text) | tr -d '\\' | sed -r 's/^"|"$//g' | jq .tags
@maxcountryman
maxcountryman / com.docker.system-prune.plist
Created June 1, 2021 14:51
launchctl load -w /Library/LaunchDaemons/com.docker.system-prune.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.docker.system-prune</string>
<key>Program</key>
<string>/usr/local/bin/docker</string>
<key>ProgramArguments</key>
<array>
set shell=/bin/bash
if &compatible
set nocompatible
endif
call plug#begin('~/.vim/plugged')
Plug 'airblade/vim-gitgutter'
Plug 'arcticicestudio/nord-vim'
@maxcountryman
maxcountryman / merkle.tree.clj
Last active January 13, 2022 20:53
A Clojure Merkle tree utilizing SHA-256.
(ns merkle.tree
(:import [java.security MessageDigest]))
(defn sha-256-digest [bs]
(.digest
(doto (MessageDigest/getInstance "SHA-256")
(.update bs))))
(def double-sha-256 (comp sha-256-digest sha-256-digest))
> "To be honest, this is a somewhat advanced usage of the transducers machinery," says the Grammarly Engineering Blog, right after shoehorning a BufferedReader into the mold with "reify IReduceInit". I already felt I'd got my money's worth from reading up to this half-way point. But I was astonished at what came next.
Though it pains me to speak of it, I tell you now I have seen this "blog post", and seen too what came next. Astonishing indeed! I admire your simple description of these events, as it suggests either a man of great fortitude in the face of horror, or a man who was able to flee and forget, and I know that I am neither.
I remember the reified specimen – still alive, god have mercy – placed upon an altar to be offered up to `eduction`. Yes! Placed squarely on its unsightly variadic first argument. Why? For what purpose? We are told: "it's a recipe for the values to come." The blood drained from my face.
It was soon apparent what eldritch function would feast upon the values begotten by t

Flask-Login Demo

Setup

$ pip install flask
$ pip install flask-login

Run

(def ^{:const true :private true}
base-62-alphabet
"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
(defn encode
"Encodes v in a new base of ks."
[ks v]
(let [base (count ks)]
(apply str
(reduce
(defn half
[s]
(bit-shift-right (count s) 1)) ;; faster division by 2
(defn left-right
[v]
(let [v (if-not (vector? v) (vec v) v)
h (half v)]
[(subvec v 0 h) (subvec v h)]))
(defmacro loop-vars
"Like loop, but will automatically populate recur points where the special
var recur-> is found.
Mostly useful in mutable contexts, where some external factor causes the
recur bindings to change.
"
[bindings & body]
{:pre [(and (vector? bindings)
(even? (count bindings)))]}