Skip to content

Instantly share code, notes, and snippets.

View kanwren's full-sized avatar
🐢

Nicole Wren kanwren

🐢
View GitHub Profile
@kanwren
kanwren / dependent_typescript.ts
Last active May 9, 2026 22:02
Hacking in HKTs and dependent constructions like GADTs, Leibniz equality, and singletons into TypeScript
function id<A>(x: A): A {
return x;
}
function unreachable(x: never): never {
return x;
}
function unused(_: unknown) {}
@kanwren
kanwren / selector.jq
Last active May 14, 2025 20:33
Parse a Kubernetes-style selector into a consumable tree in jq
def o(P):P//.;
def k(P):o(P|k(P));
def w(P;f):(.r=[]|P) as $r|.s=$r.s|.r+=[$r.r|f];
def s($r):(.s|match("^(?:"+$r+")")) as $m|.s|=.[$m.length:]|.m=$m.string;
def _:s(" *");
def r($r;f):s($r)|.r+=[.m|f];
def l($s):select(.s|startswith($s))|.s|=.[$s|length:]|_;
"[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?" as $d|
"(?:[a-zA-Z0-9](?:[a-zA-Z0-9_.-]{0,61}[a-zA-Z0-9])?)" as $l|
def K:r("(?:\($d)(?:\\.\($d))*/)?"+$l;.)|_;
author Nicole Wren
date 2024-11-07
paging Slide %d / %d

Property testing

presented using slides

Keybase proof

I hereby claim:

  • I am kanwren on github.
  • I am kanwren (https://keybase.io/kanwren) on keybase.
  • I have a public key ASCvjJQR1c6UZSHjGAV2yHitMtvUUE0xcTt_ZIwD26vAlwo

To claim this, I am signing this object:

@kanwren
kanwren / numbers_from_ops.py
Last active January 6, 2024 00:51
Find all the ways that you can combine a range of numbers with addition and multiplication
#!/usr/bin/env nix-shell
#!nix-shell -i python3 -p python3
import sys
def compute(nums):
def go(remaining_nums_stack, ops, size):
if len(remaining_nums_stack) == 0 and size == 1:
print(f'{eval_ops_stack(ops)} = {postfix_to_infix(ops)}')
return
@kanwren
kanwren / parsec.go
Last active September 30, 2023 04:30
Small parser combinator implementation in Go modeled off of prataprc/goparsec
package main
import (
"bytes"
"fmt"
"regexp"
"strconv"
"strings"
"sync"
"unicode/utf8"
@kanwren
kanwren / bitwise_test.go
Last active July 5, 2023 14:15
Some interesting properties about bitwise arithmetic I found
package bitwise_test
import (
"fmt"
"testing"
"testing/quick"
)
// First, note some simple properties:
//
@kanwren
kanwren / ExistentialExample.java
Last active February 2, 2023 05:15
An encoding (albeit limited) of existential types in Java through higher-rank polymorphism
import java.util.List;
// some defunctionalization symbols to help us
interface K1 {} // kind Type -> Type
interface K2 {} // kind Type -> Type -> Type
interface A1<F extends K1, A> {} // Apply1 :: (Type -> Type) -> Type -> Type
interface A2<F extends K2, A, B> {} // Apply2 :: (Type -> Type -> Type) -> Type -> Type -> Type
// we encode the existential using two tricks:
// 1. the CPS transform: a ≅ ∀ r. (a -> r) -> r
@kanwren
kanwren / resolver.go
Created January 31, 2023 23:00
a cute test DNS resolver I wrote for my gf
package main
import (
"bytes"
"log"
"net"
"os"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
@kanwren
kanwren / sexprs.rs
Created June 6, 2022 21:59
Quick demonstration of expressing an LL(1) lexer/parser as lazy iterator in Rust
// Quick demonstration of expressing an LL(1) lexers/parsers as lazy iterators in Rust.
// This lets you begin lexing/parsing without reallocating the input, loading the whole of the
// input into memory at once, etc. This does not attempt to address some realistic concerns, such
// as:
// - Incremental parsing; you can't resume a partial parse, which would be annoying if doing
// streaming parsing. For example, if you're writing a Lisp REPL, you might want to allow the
// user to type part of a function call, hit "enter" before they've closed the parentheses, and
// keep typing arguments on separate lines, deferring the execution until they've closed the
// expression. This usually requires something like incremental parsing, which this can't do.
// - Error messages; no location information is retained for good error message reporting!