Skip to content

Instantly share code, notes, and snippets.

import {
date as dateRaw,
int8 as int8Raw,
numeric as numericRaw,
} from '@ff00ff/mammoth';
const int8 = () => int8Raw<BigInt>();
const numeric = () => numericRaw<Big>();
const date = () => dateRaw<DateString>();
"use strict";
function sleep() { return new Promise(resolve => setTimeout(resolve, 1)); }
class Query {
constructor(f) {
this.f = f;
}
then(onFulfilled, onRejected) {
this.f()
@cakoose
cakoose / create.bash
Created June 12, 2021 22:10
Using OpenSSL to create a CSR (EC P-256, SHA-256, SAN)
name="blah"
# Create the private key (EC P-256; not RSA).
openssl ecparam -name prime256v1 -genkey -noout -out "$name.key.pem"
# Create the CSR (to give to the CA)
openssl req -new -config csr.conf \
-key "$name.key.pem" \
-out "$name.csr" -outform PEM
@cakoose
cakoose / main.ts
Created January 13, 2021 00:16
Issue with stack traces in NPM library @ff00ff/mammoth
import {defineTable, defineDb, text} from '@ff00ff/mammoth';
const foo = defineTable({
id: text(),
});
const db = defineDb({foo}, async (query, parameters) => {
// To force an async gap.
await new Promise(setImmediate);
// Node used to lose track of stack frames across async gaps. But due to improvements
// in V8, Node 14.x will now preserve stack frames for `async` functions.
//
// Unfortunately, this doesn't work for raw promises and most libraries on NPM either
// use raw promises or are transpiled down to raw promises.
//
// To counter this, you can use this wrapper whenever you're calling into a library
// that returns a raw promise:
// - OLD: const result = await someLibrary.query(...);
// - NEW: const result = await stackTraceFixer.wrap(someLibrary.query(...));
// Pretend this is the non-async library code we're calling in to.
function gap() {
return new Promise(resolve => setTimeout(resolve, 1));
}
function f4() {
return new Promise((resolve, reject) => {
gap().then(() => reject(new Error('from f4')));
});
}
import multiprocessing
import argparse
import random
import time
def main():
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--parallelism', type=parse_int_range(1, 100), default=1,
help='the number of files to process in parallel (hint: the number of CPUs you want to use)')
parser.add_argument('paths', metavar='path', nargs='+', help='files to process')
{
"global": {
"check_for_updates_on_startup": true,
"show_in_menu_bar": true,
"show_profile_name_in_menu_bar": false
},
"profiles": [
{
"complex_modifications": {
"parameters": {
@cakoose
cakoose / .zshrc
Last active February 6, 2020 00:57
setopt histignoredups
setopt ignore_eof # Don't quit shell on Ctrl-D
# Tell Terminal.app whenever folder changes.
# This allows Terminal.app to open new tabs in the same folder as the current tab.
if [[ $TERM_PROGRAM == "Apple_Terminal" ]] && [[ -z "$INSIDE_EMACS" ]] {
function chpwd {
local SEARCH=' '
local REPLACE='%20'