Skip to content

Instantly share code, notes, and snippets.

View crabmusket's full-sized avatar

Daniel Buckmaster crabmusket

View GitHub Profile

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 \
@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]);
}
}
@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 / 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 December 11, 2024 21:59
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 / 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:

deno_env_file.ts

Use this snippet to parse, modify and render environment files.

import { EnvFile } from "https://gist.githubusercontent.com/crabmusket/e10effe4800691bb15543ff264518e76/raw/deno_env_file.ts";

let content = `
KEY=value
SOMETHING_ELSE=cool
@crabmusket
crabmusket / deno_micro_modules.md
Last active August 12, 2019 01:54
Deno micro modules index page

Deno micro modules

Each of these modules is a single file consisting of no more than a page or two of code, which provide some useful 'generic' feature. These modules could be copied as-is into any TypeScript project, but they're designed to work with Deno. Deno's URL loading makes it very easy to import them.

@crabmusket
crabmusket / readme.md
Last active August 12, 2019 23:17
Async semaphore utility class for Deno

semaphore.ts

An asynchronous semaphore utility class meant to work with Deno. You can use it to implement rate-limiting and other concurrency patterns.

Usage example:

import { Semaphore } from "https://gist.githubusercontent.com/crabmusket/681b4f81ed05716f8dd10ac88d1d960b/raw/5e7c18013e896425d1048324f8668932f23437df/semaphore.ts";
@crabmusket
crabmusket / json.ts
Last active October 1, 2019 04:38
JSON utilities for Deno
/** For the spec of the JSON type, see http://json.org */
export type JsonValue = JsonObject | JsonArray | number | string | boolean | null;
/** JSON objects can have any string key. */
export interface JsonObject {[key: string]: JsonValue};
/** For the explanation of this type, see https://github.com/Microsoft/TypeScript/issues/3496#issuecomment-128553540 */
export interface JsonArray extends Array<JsonValue> {};
/** Narrow the type of a JsonValue to check if it's an object. */