Skip to content

Instantly share code, notes, and snippets.

View crabmusket's full-sized avatar

Daniel Buckmaster crabmusket

View GitHub Profile
@crabmusket
crabmusket / server.py
Created May 6, 2020 00:57
Python simple HTTP server
# https://blog.notryan.com/server.py
# https://www.reddit.com/r/programming/comments/gdxh3w/http_blog_server_100_lines_of_c_in_a_closet/fpkqvqw/
import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.bind(("0.0.0.0", 8080))
sock.listen(1)
while True:
@crabmusket
crabmusket / README.md
Last active September 30, 2025 14:32
Headless rendering with THREE.js

Headless THREE

Created with

Make sure you install headless-gl's dependencies, then run with XVFB like so:

@crabmusket
crabmusket / README.md
Last active July 12, 2022 14:13
Benchmarking msgpack versus JSON

Run this code using Deno:

deno run https://gist.githubusercontent.com/crabmusket/2c8c6e692974edd56cd6ab8fee14addd/raw/869958a7094daf17b36be6ac078aa0eafb4b0a9d/benchmark.js

It will prompt you for two network permissions, to download the sample data files.

An example of results from my laptop:

@crabmusket
crabmusket / README.md
Last active February 9, 2023 01:45
Helper for sending JSON-RPC to/from an iframe

Frame RPC helper

This set of helpers makes it easy to communicate with an iframe via JSON RPC.

This gist contains both the TypeScript source code, and a stripped JavaScript version.

If you have an iframe on your page you want to communicate with, download the source code and use it like so:

import {makeRpcClient, makeRpcServer} from "./framerpc.js";
@crabmusket
crabmusket / update.ts
Last active May 18, 2023 07:17
Immer-like updates with explicit keys
// Modify an object, passing an explicit key array. The callback only has access to the keys in the array.
function modify<T, K extends keyof T>(instance: T, keys: K[], update: (v: Pick<T, K>) => void) {
const draft = structuredClone(instance);
update(draft);
// for example's sake, just log the changed keys
for (let k of keys) {
console.log("updated", k, "from", instance[k], "to", draft[k]);
}
}

https://superuser.com/a/1415765

The wget command you'll need to use is much lengthier as explained below. As such, you may wish to commit it to a file like wholesite.sh, make it an executable, and run it. It'll create a directory of the url and subdirectories of the site's assets, including images, js, css, etc.

wget \
     --recursive \
     --level 5 \
     --no-clobber \
 --page-requisites \