Skip to content

Instantly share code, notes, and snippets.

@algal
algal / vmstatistics64.swift
Last active April 11, 2026 07:33
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 / HOWTO-nemotron-super-on-spark.md
Last active April 5, 2026 20:19
Serving Nemotron-3-Super-120B-A12B-NVFP4 on a single DGX Spark

Serving Nemotron-3-Super-120B-A12B-NVFP4 on a single DGX Spark

Tested 2026-03-27, updated 2026-04-01. Uses sparkrun with a community-patched vLLM container that works around the MIXED_PRECISION whitelist bug in the NGC vLLM container (vllm-project/vllm#37854).

Pinned versions

These are the exact versions tested. Using different versions may break things.

Component Version Immutable ref
@algal
algal / websitescreenshot.md
Last active March 7, 2026 13:36
Taking website screenshots, in Chrome or Safari, including simulating iPhones

Taking website screenshots

These are instructions for taking screenshots of an entire webpage, not just the part of the webpage visible in the browser.

Website Screenshots in Safari

This requires Safari 11.3, which comes on macOS 10.3.4.

  1. Open the website in Safari
  2. If needed, go Safari > Preferences > Advanced > Show Develop Menu in Menu Bar
@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.
*/