Skip to content

Instantly share code, notes, and snippets.

View crabmusket's full-sized avatar

Daniel Buckmaster crabmusket

View GitHub Profile
@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]);
}
}
@crabmusket
crabmusket / MJML.php
Last active April 12, 2024 11:39
MJML emails in Laravel
<?php
namespace App\Mail;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Exception\RuntimeException;
use Illuminate\Contracts\View\Factory as ViewFactory;
use Illuminate\Support\HtmlString;

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 / README.md
Last active April 16, 2024 10:20
Headless rendering with THREE.js

Headless THREE

Created with

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