Skip to content

Instantly share code, notes, and snippets.

@jschaf
jschaf / go-generics-history.md
Created September 25, 2026 19:06
A history of Go generics proposals: 2009–2022 timeline with syntax snippets and why each was rejected

A history of Go generics proposals

Go shipped generics in Go 1.18 (March 2022) after more than a decade of proposals. This is a timeline of each serious design, what it proposed, and why it was rejected. Syntax is taken from each design document at the commit it was published.

The umbrella issue is golang/go#15292. The accepted proposal is golang/go#43651.

<!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
@jschaf
jschaf / .pnpmfile.cjs
Last active June 13, 2025 05:38
Remove unsupported OS and arch deps with pnpm
// Parses a platform-specific package name.
const supportedRegexp =
/\b(darwin|linux|aix|android|freebsd|netbsd|openbsd|sunos|win32)-(arm64|x64|arm|ia32|loong64|mips64el|powerpc64|ppc64|riscv64|s390x)(?:-(gnu|eabi|musl|msvc|gnueabihf)\b)?(@[0-9.]+)?/;
const supportedPlatforms = new Set(['darwin-arm64', 'linux-x64', 'linux-arm64']);
const supportedABIs = new Set(['gnu']);
/**
* Returns true if the package is supported. Useful to omit unneeded packages
* since pnpm downloads optional dependencies.
@jschaf
jschaf / spelling_bee.go
Last active March 22, 2025 21:31
NYT Spelling Bee with Golang Bitmasks
package main
import (
"bytes"
"flag"
"fmt"
"os"
"slices"
)
@jschaf
jschaf / BUILD.openssl.bazel
Last active January 18, 2024 01:10
Heremetic Postgres
load("@bazel_skylib//rules:build_test.bzl", "build_test")
load("@rules_foreign_cc//tools/build_defs:configure.bzl", "configure_make")
"""An openssl build file based on a snippet found in the github issue:
https://github.com/bazelbuild/rules_foreign_cc/issues/337
"""
# Read https://wiki.openssl.org/index.php/Compilation_and_Installation
CONFIGURE_OPTIONS = [
@jschaf
jschaf / admin.sql
Last active August 22, 2024 21:16
Postgres audit tables with uni-temporal tables
-- create_temporal_past_table creates a new table with the same structure
-- as the current table. Adds triggers to copy all changed or deleted rows
-- from the current table to the past table.
CREATE PROCEDURE admin.create_temporal_past_table(curr_tbl regclass, past_tbl text) AS $fn$
DECLARE
curr_tbl_qual text := simc.quote_regclass(curr_tbl);
past_tbl_schema text := (parse_ident(past_tbl))[1];
past_tbl_name text := (parse_ident(past_tbl))[2];
past_tbl_qual text := quote_ident(past_tbl_schema) || '.' || quote_ident(past_tbl_name);
# We append the integers 1..50 to a base prefix.
# The problematic strings have the apostrophe \xe2
#    Andy’s liqour parent account
#    Carr’s Bar N’ Grill
short dest error transforming unicode to ascii src_bytes="wind-Andy\xe2" src_bytes_read=10, dst_bytes="wind-And\x00\x00" dst_bytes_written=8: transform: short destination buffer
short dest error transforming unicode to ascii src_bytes="wind-Andy\xe21" src_bytes_read=11, dst_bytes="wind-And\x00\x00\x00" dst_bytes_written=8: transform: short destination buffer    ...
...
short dest error transforming unicode to ascii src_bytes="wind-Andy\xe246" src_bytes_read=12, dst_bytes="wind-Andy\x00\x00\x00" dst_bytes_written=9: transform: short destination buffer
short dest error transforming unicode to ascii src_bytes="wind-Andy\xe247" src_bytes_read=12, dst_bytes="wind-Andy\x00\x00\x00" dst_bytes_written=9: transform: short destination buffer
package main
import (
"fmt"
"golang.org/x/text/runes"
"golang.org/x/text/transform"
"golang.org/x/text/unicode/norm"
"unicode"
)
@jschaf
jschaf / port-kill
Last active November 22, 2021 23:50
port-kill
#!/bin/zsh
function port-kill() {
local port="$1"
local pids
# Simplest way to fill an array from a command. The results are whitespace
# safe.
# shellcheck disable=SC2207
pids=( $(lsof -t -i:"${port}") )
if [[ "${#pids[@]}" == 0 ]]; then
@jschaf
jschaf / use_state_ref.ts
Created October 29, 2021 22:51
useStateRef hook
import type { Dispatch, SetStateAction } from 'react';
import { useCallback, useRef, useState } from 'react';
/** The returned value of a useRef hook, but marked as readonly. */
type ReadOnlyRef<T> = {
readonly current: T;
};
/** The return type of useStateRef. */
type StateRefResult<S> = [S, Dispatch<SetStateAction<S>>, ReadOnlyRef<S>];