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 { readFileSync } from 'node:fs' | |
import { resolve } from 'node:path' | |
import JSON5 from 'json5' | |
import ts from 'typescript' | |
import * as prettier from 'prettier' | |
/** | |
* reveal all top level `type` declarations from a file | |
*/ | |
export const reveal = async (sourcePath: string) => { |
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
/** | |
* @example | |
* type P = Permutation<1 | 2 | 3> | |
* // [1, 2, 3] | [1, 3, 2] | [2, 1, 3] | [2, 3, 1] | [3, 1, 2] | [3, 2, 1] | |
*/ | |
export type Permutation<U, T = U> = [U] extends [never] | |
? [] | |
: T extends unknown | |
? [T, ...Permutation<Exclude<U, T>>] | |
: never |
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 { DocumentNode } from 'graphql' | |
import { | |
gql, | |
QueryHookOptions, | |
QueryResult, | |
TypedDocumentNode, | |
useQuery, | |
} from '@apollo/client' | |
export type Query<TData, TVariables> = |
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 electron | |
const { app, BrowserWindow, TouchBar } = require("electron") | |
app.whenReady().then(() => { | |
const window = new BrowserWindow({ | |
titleBarStyle: "hiddenInset", | |
width: 0, | |
height: 0, | |
}) | |
window.loadURL("about:blank") |
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 | |
set -euo pipefail | |
SEP="${SEP:=,}" | |
TER="${TER:=\n}" | |
TABLE="${1}"; shift # first positional argument is the tablename | |
CMD="${@}" # the rest is the mysql command | |
# examples: | |
# cat myfile.csv | csv-mysql mytable mysql -Dtest -uroot --ppassword |
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
-- usage: CALL convert_to_enum('my_table', 'my_column'); | |
DELIMITER $$ | |
CREATE PROCEDURE `convert_to_enum`(IN tablename TEXT, IN colname TEXT) | |
BEGIN | |
SET @temp = CONCAT( | |
"SELECT CONCAT(\"ENUM('\", GROUP_CONCAT(DISTINCT ", | |
colname, | |
" ORDER BY ", | |
colname, | |
" SEPARATOR \"', '\"), \"')\") INTO @temp FROM ", |
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
// UnionToTuple<1 | 2 | 3> -> [3, 2, 1] | [2, 3, 1] | [3, 1, 2] | [1, 3, 2] | [2, 1, 3] | [1, 2, 3] | |
type UnionToTuple<U> = _UnionToTuple<U, []>[0] | |
type _UnionToTuple<U, L extends Array<U>> = Done<U, L> extends true | |
? [L] // boxing prevents circulatory reference | |
: [_UnionToTuple<U, ConsDistinct<U, L>>[0]] | |
// ConsDistinct<(1 | 2), ([1] | [2] | [3])> -> [1, 2] | [1, 3] | [2, 1] | [2, 3] | |
type ConsDistinct<A, L extends Array<unknown>> = L extends any | |
? A extends any |
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
// Spread<{x: number} & {y: string}> -> {x: number, y: string} | |
export type Spread<T> = ReturnType<() => { [P in keyof T]: T[P] }> | |
// Merge<{x: number} | {y: string}> -> {x: number} & {y: string} | |
export type Merge<T> = (T extends any ? (k: T) => void : never) extends (k: infer U) => void | |
? U | |
: never | |
// Values<{x: number, y: string}> -> number | string | |
export type Values<T> = T[keyof T] |
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 | |
# takes paths in argv, assumes they are in absolute, as if it was outputed by `pwd` | |
common_path() { | |
if [ "$(printf '%s\n' "${@}" | sort | uniq | wc -l)" -eq 1 ]; then | |
printf %s "${1}" | |
return | |
fi |
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
Maybe::Just() { | |
printf 'Maybe::Just(%s)' "${1}" | |
} | |
Maybe::Nothing() { | |
printf 'Maybe::Nothing' | |
} | |
Maybe::map() { | |
case "${2}" in |