This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type RequiredDefined<T extends Record<string, unknown>> = { | |
[key in keyof T]-?:NonNullable<T[key]> | |
} | |
export function assertOptions<Options extends Record<string, unknown>, Keys extends keyof Options, Result extends Pick<Options, Keys>>(options:Options, ...keys:Keys[]):RequiredDefined<Result> { | |
const result = {} as Record<string, unknown> | |
for (let key of keys as string[]) { | |
if (options[key] === undefined) { | |
throw new TypeError(`Expected ${String(key)} to be defined`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useState } from "react"; | |
type ValidationValues = Record<string, unknown>; | |
type ValidationFunction<T> = (v: T) => string | void; | |
export type ValidationErrors = Record<string, string[]>; | |
function runValidation( | |
key: string, | |
validators: ValidationFunction<unknown>[], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ffmpeg -i $input -vf "fps=16,scale=960:-1:flags=lanczos,split[s0][s1];[s0]palettegen=max_colors=32:reserve_transparent=0[p];[s1][p]paletteuse" demo-create-row.gif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { suite, test, TestContext } from "./mtap"; | |
suite("test label", ({ test }) => { | |
test("another test", (t:TestContext) => { | |
t.assert("OK computer"); | |
t.assert(false, "intentionally failed"); | |
}); | |
test("hula hoop", (t:TestContext) => { | |
t.assert(true, "juhu"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { set, get, createStore, UseStore, values, clear } from 'idb-keyval'; | |
export abstract class Ministor<ItemType> { | |
private db: UseStore; | |
constructor() { | |
const ns = this.constructor.name; | |
this.db = createStore(ns, [ns, "items"].join(":")); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
And the winner is: | |
Encoding and decoding 100000 items. | |
+--------------+--------+--------+--------------+ | |
| Encoding | encode | decode | size (bytes) | | |
+--------------+--------+--------+--------------+ | |
| msgpack-lite | 504 | 206 | 1568544 | | |
| msgpack5 | 448 | 352 | 1568544 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Generate ascii table in 30 lines of readable code from a list of objects: | |
table([ | |
{ | |
description: "description", | |
value: "value" | |
}, | |
{ | |
description: "some variable desc", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -e | |
debug() { | |
echo "$@" 1>&2 | |
} | |
PREVIEW_PORT=8080 | |
get_instance_id() { | |
out=($(ec2-metadata -i)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/usr/bin/env bash | |
# git hook to run a command after `git pull` if a specified file was changed | |
# Run `chmod +x post-merge` to make it executable then put it into `.git/hooks/`. | |
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)" | |
check_run() { | |
echo "$changed_files" | grep --quiet "$1" && eval "$2" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
/** | |
* Instead of squatting https://www.npmjs.com/package/window | |
* Why not make it something useful like: | |
*/ | |
module.exports = typeof window == "undefined" ? null : window; |
NewerOlder