Skip to content

Instantly share code, notes, and snippets.

View maxcountryman's full-sized avatar
🦀

Max Countryman maxcountryman

🦀
View GitHub Profile
(ns datastructures.queue
(:refer-clojure :exclude [compare-and-set! pop])
(:import java.util.concurrent.atomic.AtomicReference))
(defn- compare-and-set! [^AtomicReference aref oldval newval]
(or (.compareAndSet aref oldval newval)
(throw (RuntimeException. ::loop))))
(defmacro with-contention
[& body]
@maxcountryman
maxcountryman / bf.c
Created January 29, 2012 17:20
A simple brainfuck interpreter in C
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
// initialize the tape with 30,000 zeroes
unsigned char tape[30000] = {0};
// set the pointer to point at the left-most cell of the tape
unsigned char* ptr = tape;
@maxcountryman
maxcountryman / sleep_sort.py
Created June 20, 2011 13:27
Sleep sort in Python
import thread
from time import sleep
items = [2, 4, 5, 2, 1, 7]
def sleep_sort(i):
sleep(i)
print i
[thread.start_new_thread(sleep_sort, (i,)) for i in items]
@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 / tabula_recta.py
Created December 18, 2010 01:42
Generates a string from a randomly generated tabula recta that is hopefully secure.
#! /usr/bin/env python
import sys
import json
import argparse
from string import uppercase, digits, letters, punctuation
from random import SystemRandom
FULL_MAP = letters + digits + punctuation
@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 / 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))
@maxcountryman
maxcountryman / facebook-cli-py3.py
Created March 30, 2013 16:16
Updated rauth examples supporting Python 3.
from rauth import OAuth2Service
import re
import webbrowser
try:
read_input = raw_input
except NameError:
read_input = input
@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'