Skip to content

Instantly share code, notes, and snippets.

@algal
algal / sc_checkpoint.py
Created December 11, 2025 19:28
Saves and Checkpoints
#!/usr/bin/env python3
# /// script
# requires-python = ">=3.9"
# ///
"""Checkpoint: save, then squash consecutive solveit commits into one with given name."""
import subprocess, sys
from datetime import datetime, UTC
def git(*args, check=True):
@algal
algal / nginx-cors.conf
Created April 29, 2013 10:52
nginx configuration for CORS (Cross-Origin Resource Sharing), with an origin whitelist, and HTTP Basic Access authentication allowed
#
# A CORS (Cross-Origin Resouce Sharing) config for nginx
#
# == Purpose
#
# This nginx configuration enables CORS requests in the following way:
# - enables CORS just for origins on a whitelist specified by a regular expression
# - CORS preflight request (OPTIONS) are responded immediately
# - Access-Control-Allow-Credentials=true for GET and POST requests
@algal
algal / notebook-formats.md
Last active September 29, 2025 10:57
notebook formats and converters

Notebook Formats & Conversion Tools

This document summarizes some popular, public notebook formats (Org, Jupyter, Markdown, Python variants) and the tools which interconvert them.

Notable omissions:

  • Wolfram notebooks. My impression is the proprietary platform offer mature export to many formats but not ipynb. There is no mature, widely used too for export to ipynb, not are there great import tools afaict.
  • SolveIt platform. Not publicly released yet. But I suspect it will support excellent ipynb interop. 😉

Epistemic status: Moderate confidence. This is based mostly on AI research on 2025-08-30 but it passes spot checks and matches my prior background knowledge, which covers many of these technologies.)

@algal
algal / studentt.md
Created July 31, 2025 02:44
Studentt #md

Help me understand the Student's t-distribution.

I've studied it but I don't remember it.

Of course, I do want to understand the procedure to use when trying to estimate the variance of a population from a single sample. I understand that this is its main use.

But I mainly want to have a terse, but 100% conceptually crisp, understanding of the key concepts necessary to understand why this procedure is what it is. FOr me to remember things, it is important that they be very coherent. So I care a lot about precision in terminology, e.g., to distinguish what is treated as a random variable, what is a parameter of a distribution, over what range of values an expectation is calculated, etc..

🤖🤖🤖

@algal
algal / Recorder.swift
Created June 26, 2025 00:57
Recorder #swift
import AVFoundation
import Foundation
import os
// Microphone permission (supports macOS, fallback)
func requestMicrophonePermission() async -> Bool {
await withCheckedContinuation { continuation in
AVCaptureDevice.requestAccess(for: .audio) { granted in
continuation.resume(returning: granted)
}
@algal
algal / colorize-emacs.bashsource
Last active March 28, 2025 16:15
Setting up truecolor (24 bit color) in emacs in the terminal, under iTerm2, blink.sh, and others.
# sourcing this file will define a bash functions that
# tries to run subsequent calls to emacs with 24 bit color.
#
# It sets TERM=xterm-emacs-leg if
# - we've created a user-local terminfo record for xterm-emacs-leg, and
# - we're using iTerm2 or something has set COLORTERM=truecolor
#
# This will cause emacs to use 24 bit color only when it will work,
# inside or outside of tmux. I haven't found a way to auto-detect Blink.sh yet.
#
@algal
algal / PKCS12.swift
Last active February 24, 2025 20:47
Reading PKCS12 with Swift in Foundation
// xcode 7.3
import Foundation
/**
Struct representing values returned by `SecPKCS12Import` from the Security framework.
This is what Cocoa and CocoaTouch can tell you about a PKCS12 file.
*/
@algal
algal / lisp_for_zach.el
Created January 17, 2025 02:26
some emacs lisp snippets
;; This is miraculously all you need to add decent support for python.
;; It requires that you have uv installed. Then run `eglot` in a python buffer.
(use-package eglot
:defer t
:config
(add-to-list 'eglot-server-programs
`(python-mode . ,(split-string "uvx --quiet --from pyright pyright-langserver --stdio"))))
;; this is handy for dumping web pages into buffers, to then add them to context for AI with gptel
(defun alg/insert-markdown-from-url (url)
@algal
algal / vmstatistics64.swift
Last active January 6, 2025 12:51
Get virtual memory usage on iOS or macOS
import Darwin
import Foundation
// known good: Swift 5
// runs on macOS, probably works on iOS (but haven't tried)
/// Wraps `host_statistics64`, and provides info on virtual memory
///
/// - Returns: a `vm_statistics64`, or nil if the kernel reported an error
///
@algal
algal / NamesOnMacOS.md
Last active January 2, 2025 10:37
A note on how a Mac gets its various names

Names on macOS

Since I couldn't find documentation on how a Mac machine gets its name, I thought I'd write up these notes for my own reference later.

A macOS machine has a few different names, which might or might not be equal.

1. ComputerName

Every machine has a pretty user-facing name. This is the ComputerName.