Skip to content

Instantly share code, notes, and snippets.

View wchargin's full-sized avatar

Willow Chargin wchargin

View GitHub Profile
@wchargin
wchargin / multiplyFloat.js
Created April 13, 2020 04:24
multiply bigint by float in JS (spoiler alert: BigInt has no useful functions)
/**
* For a finite normal 64-bit float `f`, extracts integers `sgn`,
* `exponent`, and `mantissa` such that:
*
* - `sgn` is -1 or +1
* - `exponent` is between -1023 and 1024, inclusive
* - `mantissa` is between 0 and 2^51 - 1, inclusive
* - the number given by `f` equals `sgn * 2^exponent * (1 + mantissa / 2^52)`
*
* The results are all bigints within the range of safe integers for
@wchargin
wchargin / soa.go
Created July 30, 2025 22:04
ergonomic, type-precise struct-of-arrays transform in Go
// Package soa implements a Structure-of-Arrays transform.
//
// This makes it convenient to convert a slice of values into a collection of
// correlated slices of individual fields, each representing one "column". For
// example, if you have a slice of N users, you can use [Collect] to extract a
// slice of N user IDs, a slice of N user names, and a slice of N user emails.
// Those slices can be conveniently passed as array parameters to SQL queries.
//
// See: https://en.wikipedia.org/wiki/AoS_and_SoA
//
@wchargin
wchargin / words
Created February 11, 2014 01:14
/usr/share/dict/words
This file has been truncated, but you can view the full file.
A
A's
AA's
AB's
ABM's
AC's
ACTH's
AI's
AIDS's
@wchargin
wchargin / Dockerfile
Last active July 25, 2025 03:51
repro for Dart HTTP/2 issue: client RST_STREAM forgets stream ID and destroys connection on incoming server frame
###
# gRPC server, in Go
###
FROM golang:1.24.5-alpine AS server
WORKDIR /root
RUN apk add git
RUN git clone --branch v1.74.2 --depth 1 https://github.com/grpc/grpc-go

Suppose you have a closed, non self-intersecting 2D curve. Split this curve into N parts, not necessarily equal but with maximum length going to zero. Find a TSP solution (shortest tour containing all the points) on the sampled set. Question: for large N, does the solution mimic the curve?

(Some parts of this are underspecified. Fill in the gaps as you like...)

Spoiler wall...

Spoiler wall...

Spoiler wall...

(() => {
function setDark(dark) {
document.documentElement.classList.toggle("dark", dark);
}
const mql = window.matchMedia("(prefers-color-scheme: dark)");
function updateDark() {
const fromLocalStorage = localStorage.getItem("theme");
if (fromLocalStorage != null) {
setDark(fromLocalStorage === "dark");
return;
@wchargin
wchargin / 1cap.html
Created June 26, 2025 02:23
demo of using "font-size: 1cap" to align icons properly
<!doctype html>
<style>
img {
height: 1em;
}
.cap {
font-size: 1cap;
}
@wchargin
wchargin / yg_edAeTruF.go
Created June 6, 2025 05:55
consts and transitivity in go
package main
import (
"fmt"
"math"
)
func main() {
f := math.SmallestNonzeroFloat64
fmt.Println(f == 5e-324)
panic: test timed out after 10m0s
running tests:
TestGORM (10m0s)
goroutine 43 [running]:
testing.(*M).startAlarm.func1()
/Users/wchargin/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.3.darwin-arm64/src/testing/testing.go:2373 +0x1dc
created by time.goFunc
/Users/wchargin/go/pkg/mod/golang.org/toolchain@v0.0.1-go1.23.3.darwin-arm64/src/time/sleep.go:215 +0x44
@wchargin
wchargin / gormlock.go
Last active May 25, 2025 04:39
consistent repro for deadlock in Gorm prepared statements (repros at gorm v1.26.1)
package main
import (
"context"
"fmt"
"os"
"runtime/pprof"
"sync"
"time"