Skip to content

Instantly share code, notes, and snippets.

View chadbrewbaker's full-sized avatar

Chad Brewbaker chadbrewbaker

View GitHub Profile
@chadbrewbaker
chadbrewbaker / interaction.c
Created May 3, 2026 20:01
Interaction calculus in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Raw dog Interaction Calculus demo in C
// Demonstrates superpositions (SUP), lambdas, apps, global scoping via env
// Uses function pointers for reduction rules and term kinds
typedef enum {
TERM_VAR,
@chadbrewbaker
chadbrewbaker / run_qwen.sh
Created April 28, 2026 22:32
Localhost llama.cpp configuration for Qwen3.6
./build/bin/llama-server \
-m ~/models/Qwen3.6-35B-A3B-UD-Q4_K_XL.gguf \
-ngl 99 \
-c 262144 \
-np 1 \
-fa on \
--jinja --reasoning-format deepseek \
--cache-type-k q4_0 \
--cache-type-v q4_0 \
--host 0.0.0.0
@chadbrewbaker
chadbrewbaker / iowa_offshore_2023.txt
Created April 26, 2026 03:52
FY2023 Iowa Nonprofit Offshore Activity
76 420680387 THE TRUSTEES OF GRINNELL COLLEGE $1,086,636,902.00
227 421143702 IOWA STATE UNIVERSITY FOUNDATION $292,636,627.00
491 420698295 MERCY MEDICAL CENTER $97,889,322.00
555 844628214 University of Iowa Strategic Initiatives Fund $82,026,731.00
637 426139033 COMMUNITY FDN OF GREATER DES MOINES $66,046,696.00
711 420680460 DRAKE UNIVERSITY $53,492,350.00
760 420796760 STATE UNIVERSITY OF IOWA FOUNDATION $48,287,270.00
771 510233180 MERCY HOSPITALCEDAR RAPIDSIA ENDOWMENT $47,162,540.00
815 420703280 ST AMBROSE UNIVE
@chadbrewbaker
chadbrewbaker / offshore_2023.txt
Created April 26, 2026 03:26
NONPROFIT ORGANIZATIONS BY OFFSHORE EXPENDITURES/ASSETS 2023
This file has been truncated, but you can view the full file.
ORG_EIN ORG_NAME_L1 SF_01_FRGN_REG_TOT_EXP
0 980571483 NOVO HOLDINGS AS $23,648,391,120.00
1 941156365 THE BOARD OF TRUSTEES OF THE LELAND $18,850,601,940.00
2 941105628 KAISER FOUNDATION HOSPITALS $12,144,993,009.00
3 210634501 The Trustees of Princeton University $11,728,687,974.00
4 350868188 University of Notre Dame du Lac $11,239,145,760.00
5 980593375 GAVI ALLIANCE $10,845,619,280.00
6 590735717 Howard Hughes Medical Institute $10,526,015,441.00
7 60646973 Yale Unive
@chadbrewbaker
chadbrewbaker / timeshare.txt
Created April 5, 2026 18:46
llama.cpp time sharing
Yes — this is exactly what llama-server's slot system (+ your queue dispatcher) was built for. You can run one llama-server instance on a single GGUF, expose several independent message queues, and give each queue explicit time slices that are long enough to amortize the cost of flushing the KV cache for a fresh context window. Model weights stay hot in VRAM/CPU the whole time; only per-slot KV caches are flushed/recomputed when you want a truly fresh start.Why this works (no cache thrashing)Slots = isolated KV caches: Start the server with -np N (N = number of queues + 1–2 buffer). Each slot gets its own KV cache. The server automatically assigns requests to slots (or you pin with "slot_id": X in the JSON payload). Model weights (the GGUF) are loaded once and stay cached.
Fresh context = intentional flush: In every request from a queue, include "cache_prompt": false. This forces the server to discard/recompute the KV cache for that request (fresh prefill, no reuse from prior work in the slot).
No thrashi
@chadbrewbaker
chadbrewbaker / llm.py
Created March 25, 2026 14:43
Patching tinygrad llm runner for Qwen 3.5 mamba
from __future__ import annotations
import sys, argparse, typing, re, unicodedata, json, uuid, time, functools, itertools
from dataclasses import dataclass
from tinygrad import Tensor, nn, UOp, TinyJit, getenv, function
from tinygrad.uop.ops import resolve
from tinygrad.helpers import partition, DEBUG, Timing, GlobalCounters, stderr_log, colored, Context
from tinygrad.viz.serve import TCPServerWithReuse, HTTPRequestHandler
class SimpleTokenizer:
def __init__(self, normal_tokens:dict[str, int], special_tokens:dict[str, int], preset:str="llama3"):
@chadbrewbaker
chadbrewbaker / setup.md
Last active March 24, 2026 23:36
vibe swift UI app
llama-server \
  --model "/Volumes/Lexar/ollama_models/Qwen3.5-0.8B-Claude-4.6-Opus-Reasoning-Distilled.gguf" \
  --n-gpu-layers 99 \
  --ctx-size 24576 \
  --flash-attn on \
  --mlock \
  --port 8080
@chadbrewbaker
chadbrewbaker / fixTabular.vb
Created March 17, 2026 16:52
fix tabular data
Sub FixTabularData()
Dim rng As Range
Dim cell As Range
' Only act on the selected cells
Set rng = Selection
On Error Resume Next
' Optimization: Only process cells that contain numbers
' This prevents the macro from ruining your text headers
@chadbrewbaker
chadbrewbaker / art.py
Created March 13, 2026 15:44
Contiguous art gallery problem with epsilon overlap
# vibe code of https://arxiv.org/pdf/2511.02960 via Google Gemeni 3 flash preview
import numpy as np
class EpsilonRobustGallerySolver:
def __init__(self, vertices, epsilon=0.1):
self.vertices = [np.array(v, dtype=float) for v in vertices]
self.n = len(vertices)
self.epsilon = epsilon
self.edges = [(self.vertices[i], self.vertices[(i+1)%self.n]) for i in range(self.n)]
self.lengths = [np.linalg.norm(e[1]-e[0]) for e in self.edges]
@chadbrewbaker
chadbrewbaker / egpu.c
Created July 30, 2025 15:58
Grok4 spike on egpu address mapping
#include <IOKit/IOKitLib.h>
#include <CoreFoundation/CoreFoundation.h>
#include <stdio.h>
#include <stdint.h>
#include <mach/mach_port.h>
typedef struct {
uint32_t spaceType;
uint32_t bitWidth;
uint64_t options;