Skip to content

Instantly share code, notes, and snippets.

@matthewp
matthewp / mastodon-status
Last active March 29, 2023 19:17
A bash script for posting statuses to Mastodon
#!/bin/bash
usage() {
program_name=$(basename $0)
bold=$(tput bold)
normal=$(tput sgr0)
cat <<EOM
Usage: $program_name [options] status
Post a status update to a Mastodon account.
@matthewp
matthewp / pnpm-where
Created March 9, 2022 13:49
pnpm-where
#!/bin/bash
bin_name=$1
bin_path="node_modules/.bin/$bin_name"
bin_dir=$(dirname $bin_path)
if [ ! -f "$bin_path" ]; then
echo "$bin_path does not exists"
exit 1
fi
@matthewp
matthewp / 00explainer.md
Last active December 1, 2021 19:20
SSR discovery
@matthewp
matthewp / parser.md
Last active October 29, 2021 15:08
Binding DSL

Memory layout

1 imported page

[source 32KiB, internal 16KiB, external 16KiB]

Internal

@matthewp
matthewp / readme.md
Created September 17, 2021 17:17
streaming tests
deno run --allow-net --unstable server.js
@matthewp
matthewp / r.ts
Created September 1, 2021 11:50
url-relative
import { resolve } from 'https://deno.land/std@0.105.0/path/posix.ts';
const CHAR_FORWARD_SLASH = 47;
/**
* Return the relative path from `from` to `to` based on current working directory.
* @param from path in current working directory
* @param to path in current working directory
*/
export function relative(origFrom: string, origTo: string): string {
@matthewp
matthewp / to-byte-source.js
Last active August 5, 2021 12:39
Convert a file to its byte source equivalent
const fileName = Deno.args[0];
if(!fileName) {
console.error('No file provided.');
Deno.exit(1);
}
let file = await Deno.open(fileName);
let encoder = new TextEncoder();
@matthewp
matthewp / something
Created June 25, 2021 15:07
tsx example
test
@matthewp
matthewp / basic.js
Last active June 24, 2021 16:04
Event observable
function listen(fn) {
const gen = fn();
function listener(ev) {
let { done } = gen.next(ev);
if(done) {
this.removeEventListener(ev.type, listener);
gen.return();
}
@matthewp
matthewp / notes.ts
Created June 18, 2021 12:24
lucy typescript notes
import { EventObject, Guard, InvokeCreator, StateMachine } from 'xstate'
type EventNames = 'GO_BACK' | 'GO_FORWARD' | 'GO_SIDEWAYS';
type KnownContextKeys = 'user';
type LucyKnownContext<Keys extends string> = Record<Keys, any>
function createMachine<TContext extends LucyKnownContext<KnownContextKeys>, TEvent extends { type: EventNames } = any>() {
return {} as any