Skip to content

Instantly share code, notes, and snippets.

View jhunterkohler's full-sized avatar
🇺🇸
Working from the USA

Hunter Kohler jhunterkohler

🇺🇸
Working from the USA
  • United States
View GitHub Profile
@jhunterkohler
jhunterkohler / memory-store.ts
Created November 2, 2021 21:24
Writable stream with options to cap in-memory store on internal buffer. Stores in array, then concats last.
import { WritableOptions, Writable } from "stream";
export interface MemoryStoreOptions extends WritableOptions {
objectMode?: false | undefined;
maxBufsize?: number;
}
export const DEFAULT_MAX_BUFSIZE = 1024 ** 2;
export class MemoryStore extends Writable {
@jhunterkohler
jhunterkohler / globals.css
Created October 24, 2021 19:21
Interproject default global styles
/*
* Copyright (C) 2021 Hunter Kohler <[email protected]>
*/
/*
* Global variables
*/
:root {
}
@jhunterkohler
jhunterkohler / templates.js
Created October 23, 2021 20:11
Simple template-literal helpers for dynamic DOM manipulation.
/*
* Copyright (C) 2021 John Hunter Kohler <[email protected]>
*
* Simple template-literal helpers for dynamic DOM manipulation.
*/
const emptyTagNames = new Set([
"area", "base", "br",
"col", "embed", "hr",
"img", "input", "link",
@jhunterkohler
jhunterkohler / openapi-types.ts
Last active January 31, 2022 21:30
Relatively good; hand written Types for OpenAPI 3.1
/**
* Copyright (C) 2021 Hunter Kohler <[email protected]>
*/
type Dict<T> = { [P: string]: T | undefined };
export type SpecificationExtension = any;
export type OpenAPI = {
components?: Components;
@jhunterkohler
jhunterkohler / regex_operators.h
Last active October 13, 2021 06:10
An overcomplete set of user-defined literals for std::regex.
/*
* Copyright (C) 2021 Hunter Kohler <[email protected]>
*
* WARNING: AUTOGENERATED FILE, DO NOT EDIT DIRECTLY
*/
#ifndef REGEX_OPERATORS_H_
#define REGEX_OPERATORS_H_
#include <string>
#include <regex>
@jhunterkohler
jhunterkohler / frozen-set.js
Created September 7, 2021 19:04
FrozenSet: An overly simply helper class
export class FrozenSet extends Set {
clone() {
return new FrozenSet(this);
}
}
FrozenSet.prototype.add = undefined;
FrozenSet.prototype.delete = undefined;
FrozenSet.prototype.clear = undefined;
@jhunterkohler
jhunterkohler / functional.js
Last active December 11, 2021 17:34
Some lodash-esc functional utilities; mostly manipulating path strings.
/*
* Copyright (C) 2021 John Hunter Kohler <[email protected]>
*/
/**
* Returns true if `value` is non-primitive (ECMA script standard, i.e., null is
* a primitive, function is an object).
*
* @param {any} value
* @returns {bool}
@jhunterkohler
jhunterkohler / table.js
Last active August 1, 2021 05:57
'jest-each'-like tagged template literal tables for pretty JavaScript source code constants
export function mktable(strings, ...args) {
strings = strings[0].split("|");
if (!strings.length || !args.length || args.length % strings.length) {
throw new TypeError("Label and argument count do not match");
}
const labels = new Set();
const table = new Array(args.length / strings.length)
@jhunterkohler
jhunterkohler / promise.js
Created July 31, 2021 15:25
A partially implemented A+ compliant Promise class
// const GlobalPromise = global.Promise;
// delete global.Promise;
function typename(value) {
if (typeof value == "object" && typeof value != "null") {
let name;
try {
name = value.constructor?.name;
@jhunterkohler
jhunterkohler / random
Last active July 31, 2021 02:38
simple bash script for generating random bytes
#!/usr/bin/env bash
read -r -d '' usage <<EOF
Usage:
random [options] bytes
random -h|--help
Generate random bytes from /dev/random.
Options: