Skip to content

Instantly share code, notes, and snippets.

View wch's full-sized avatar

Winston Chang wch

View GitHub Profile
@wch
wch / kv_store_server.R
Created September 26, 2025 22:54
Key-value store with subscriptions using websockets, in R
#!/usr/bin/env Rscript
# WebSocket Key-Value Store Server with ID scoping
#
# This server provides a WebSocket-based key-value store with publish/subscribe
# functionality. All operations are scoped by an application ID, allowing multiple
# independent applications to use the same server concurrently.
#
# COMMUNICATION PROTOCOL (JSON):
# ==============================
@wch
wch / rebase-with-prettier.sh
Created September 25, 2025 13:38
Rebase git branch, reformatting each changed file with prettier after each commit
#!/bin/bash
# Rebase with Prettier - Automatically reformat files with prettier during rebase
#
# USAGE:
# ./rebase-prettier-exec.sh
#
# BEFORE RUNNING:
# - Make sure you're on the branch you want to rebase (e.g., your feature branch)
# - This script will rebase your current branch onto origin/main
@wch
wch / extract.py
Created August 15, 2025 00:26
Data extraction with ollama
#!/usr/bin/env python
# pyright: strict
# Usage:
# python extract.py [-o output.txt] [-m model] [-c chunk_size] [-r overlap] [-q] <file_path> "<extraction_prompt>"
import argparse
import sys
from pathlib import Path
from typing import Generator
@wch
wch / .env
Last active April 10, 2025 14:04
20 questions game using several different LLMs
OPENAI_API_KEY=<Paste API key here>
ANTHROPIC_API_KEY=<Paste API key here>
@wch
wch / xhrshim.ts
Last active March 7, 2025 15:22
XMLHttpRequest shim
// ===================================================================
// XMLHttpRequestShim - shim for XMLHttpRequest
// This assumes the XMLHttpRequest types from lib.dom.d.ts are available
//
// Based on https://github.com/apple502j/xhr-shim
// ===================================================================
const sHeaders = Symbol("headers");
const sRespHeaders = Symbol("response headers");
const sAbortController = Symbol("AbortController");
@wch
wch / keybase.md
Created February 20, 2025 23:16
Keybase

Keybase proof

I hereby claim:

  • I am wch on github.
  • I am winston (https://keybase.io/winston) on keybase.
  • I have a public key ASDHlMPPG3dP3sRwu8Y3TZ2nJY9au2IYwL7DWX4mjKgWWwo

To claim this, I am signing this object:

@wch
wch / 00test.js
Last active April 9, 2024 14:42
Attempt to run sass with QuickJS
import * as sass from "./sass.default.js";
console.log(sass.info);
console.log(1);
const res = sass.compileString(`
.box {
width: 10px + 15px;
}
`)
console.log(2);
@wch
wch / collision.R
Created February 16, 2024 14:35
Calculate collision probabilities
# Calculate the probability of a collision if `n` items are randomly drawn (with
# replacement) from a set with `total` number of items.
collision_prob <- function(n, total) {
prob_no_collision <- 1
# Do this in a loop instead of prod(numerators)/prod(denominators), because
# that method is prone to result in a loss of precision due to rounding.
for (i in seq(0, n-1)) {
prob_no_collision <- prob_no_collision * (total - i) / total
}
1 - prob_no_collision
@wch
wch / retirement-logo.png
Last active November 2, 2023 14:02
Retirement simulation Quarto Shiny app
retirement-logo.png
@wch
wch / compress-video
Created June 6, 2023 17:36
Video compression script
#!/bin/bash
# Process command-line arguments
if [[ $# -eq 0 ]] || [[ "$1" == "--help" ]]; then
echo "Usage: compress-video [OPTIONS] [FILENAMES...]"
echo
echo "Options:"
echo " --speed-2x Output video at 2x speed"
echo " --size-half Scale output to half size"
echo " --help Display this help page"