// tree node type
type Node = {
id: number;
children: () => Promise<Node[]>
}
// results array
const results: Node[] = [];
This file contains hidden or 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
| # sts - Secrets Manager | |
| # Manages environment variables backed by macOS Keychain via `security`. | |
| # Config file maps ENV_VAR_NAME to keychain account name (one per line). | |
| # | |
| # Usage: | |
| # sts # Toggle all keys (load/unload) | |
| # sts load [name] # Load all keys, or a specific key by name | |
| # sts unload [name] # Unload all keys, or a specific key by name | |
| # sts i # Interactive fzf session for managing keys |
This file contains hidden or 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
| help() { | |
| if [[ -z "$1" ]]; then | |
| echo "Usage: help <command>" | |
| return 1 | |
| fi | |
| local output | |
| output=$("$@" --help 2>&1) | |
| if [[ $? -ne 0 && -z "$output" ]]; then | |
| echo "No help available for '$1'" | |
| return 1 |
This file contains hidden or 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
| # pbgist - Create a GitHub Gist from clipboard contents with an interactive gum UI | |
| function pbgist() { | |
| if ! command -v gum &>/dev/null; then | |
| echo "Error: gum is required. Install it with: brew install gum" >&2 | |
| return 1 | |
| fi | |
| if ! command -v gh &>/dev/null; then | |
| echo "Error: gh is required. Install it with: brew install gh" >&2 | |
| return 1 |
This file contains hidden or 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
| unalias gbl | |
| function gbl() { | |
| # todo: colorize branches by last commit | |
| # todo: show 10 by default | |
| gb --sort=committerdate | | |
| tail -n 5 | | |
| gum filter --limit=1 --header="Type to checkout a branch" --placeholder="" | | |
| xargs -I _ git checkout _ || echo Current branch already checked out. | |
| } |
This file contains hidden or 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 ObjectPathValue<T, U extends readonly string[]> = U extends [ | |
| infer FirstProp extends keyof T, | |
| ...infer RestProps extends readonly string[] | |
| ] | |
| ? ObjectPathValue<T[FirstProp], RestProps> | |
| : T; | |
| function $get<T extends object, U extends readonly string[]>( | |
| target: T, | |
| path: [...U] |
This file contains hidden or 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 TokenSpec<T = any> = { match: RegExp; value: (s: string) => T }; | |
| type TokenConfig = Record<string, RegExp | TokenSpec>; | |
| type TokenTypes<T extends TokenConfig> = { | |
| [Type in keyof T]: T[Type] extends TokenSpec | |
| ? { type: Type; value: ReturnType<T[Type]['value']> } | |
| : { type: Type; value: string }; | |
| }[keyof T]; | |
| /** | |
| * @param str The input string |
This file contains hidden or 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
| export function range(start: number, stop = start, step = 1) { | |
| start = stop === start ? 0 : start; | |
| const end = stop === start ? start : stop; | |
| return { | |
| *[Symbol.iterator]() { | |
| for (let i = start; i < end; i += step) yield i; | |
| }, | |
| }; | |
| } |
This file contains hidden or 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
| const dogs = [ | |
| { name: 'Fido', favorites: ['sam', 'mark', 'bob'] }, | |
| { name: 'Happy', favorites: ['mark'] }, | |
| { name: 'Buddy', favorites: ['bob'] }, | |
| { name: 'Oscar', favorites: ['mark', 'sam', 'bob'] }, | |
| ]; | |
| const friends = [ | |
| { name: 'sam', age: 22, toes: 5 }, | |
| { name: 'mark', age: 37, toes: 9 }, |
This file contains hidden or 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
| function render(template: string, data: any, brackets = ['{{', '}}']) { | |
| const output: string[] = []; | |
| const [left, right] = | |
| brackets.length > 1 ? brackets : [...brackets, ...brackets]; | |
| let pos = 0; | |
| while (pos < template.length) { | |
| const start = template.indexOf(left, pos); | |
| if (start < 0) break; |
NewerOlder