Skip to content

Instantly share code, notes, and snippets.

View zachhardesty7's full-sized avatar

Zach Hardesty zachhardesty7

View GitHub Profile
@zachhardesty7
zachhardesty7 / index.ts
Last active February 29, 2024 21:31
TS: isTruthy
// copyright 2023 Zach Hardesty
// want to check this out in the TypeScript playground?
// visit the following link to automatically see the latest version!
// https://www.typescriptlang.org/play?jsx=0#gist/b1d6650475c0b30dc57eebe13d20ae37
/**
* Type guard helper for checking if a value is truthy. mostly for use with
* {@link Array.prototype.filter} to clean up array types
*
@zachhardesty7
zachhardesty7 / index.ts
Last active March 10, 2023 20:36
TS: KeysAssignableType
// copyright 2023 Zach Hardesty
// want to check this out in the TypeScript playground?
// visit the following link to automatically see the latest version!
// https://www.typescriptlang.org/play?jsx=0#gist/63e56cd69e55a659120ec1e95a380a1e
/**
* Extracts keys of `TObj` that correspond to values that some type in the union
* `TTypes` can be assigned to
*
@zachhardesty7
zachhardesty7 / index.ts
Last active August 9, 2022 15:49
TS: binary math!
// copyright 2022 Zach Hardesty
// want to check this out in the TypeScript playground?
// visit the following link to automatically see the latest version!
// https://www.typescriptlang.org/play?jsx=0#gist/81679a314603786b1ec9106ac82c3444
// DEBUGGING HELP
// https://blog.andrewbran.ch/debugging-the-type-script-codebase/
// https://www.typescriptlang.org/docs/handbook/compiler-options.html
// https://medium.com/jspoint/typescript-compilation-the-typescript-compiler-4cb15f7244bc
@zachhardesty7
zachhardesty7 / parse-vscode-profile.js
Last active May 23, 2023 14:40
parse VSCode `.code-profile` for enabled extensions
// run like this:
// node ./parse-vscode-profile.js "$HOME"/Downloads/profile.code-profile
const fs = require("fs")
const file = fs.openSync(process.argv[2], "r")
for (const line of fs.readFileSync(file, "utf8").split("\n")) {
const extensions = JSON.parse(JSON.parse(line).extensions)
const enabledExtensions = extensions.filter((extension) => !extension.disabled)
@zachhardesty7
zachhardesty7 / index.ts
Last active February 9, 2022 18:48
unsound TS function type annotations
// copyright 2022 Zach Hardesty
// want to check this out in the TypeScript playground?
// visit the following link to automatically see the latest version!
// https://www.typescriptlang.org/play?jsx=0#gist/737d914974c9ae26935a5c3fcfdc0289
// TODO: write functions that mimic React for better example
// see the comment toward the bottom for the issue
type SetStateAction<S> = S | ((prevState: S) => S)
@zachhardesty7
zachhardesty7 / index.ts
Last active February 12, 2024 22:01
TS `Expect` type testing helper
// copyright 2024 Zach Hardesty
// want to check this out in the TypeScript playground?
// visit the following link to automatically see the latest version!
// https://www.typescriptlang.org/play?jsx=0#gist/1b5b6f6de328f1bb7c78cbe96ba5c720
/**
* Passes thru successful test input, errors with inputs that are not equal. nice when
* you have a bunch of `never`s. can handle checking if things are `any` or `unknown` too.
*
@zachhardesty7
zachhardesty7 / index.ts
Last active February 4, 2022 00:04
TypeScript Types binary to decimal exploration
// copyright 2022 Zach Hardesty
// want to check this out in the TypeScript playground?
// visit the following link to automatically see the latest version!
// https://www.typescriptlang.org/play?jsx=0#gist/4b88be5dbc4ce1d00c37df0d1811c48b
// experiments that have thus far been unsuccessful
// https://itnext.io/implementing-arithmetic-within-typescripts-type-system-a1ef140a6f6f
// https://github.com/fightingcat/sits
@zachhardesty7
zachhardesty7 / index.ts
Last active February 4, 2022 00:04
AOC16 Typescript Types
// copyright 2022 Zach Hardesty
// want to check this out in the TypeScript playground?
// visit the following link to automatically see the latest version!
// https://www.typescriptlang.org/play?jsx=0#gist/2bc7327353adb13e7b443f8c85113ba0
// eventually a solution to day 16 of Advent of Code 2021 using only the compile-time
// type system of TypeScript.
// https://adventofcode.com/2021/day/16
@zachhardesty7
zachhardesty7 / index.ts
Last active August 6, 2023 22:34
TS: pathify interface TypeScript (generate all possible paths in string format)
// copyright 2022 Zach Hardesty
// want to check this out in the TypeScript playground?
// visit the following link to automatically see the latest version!
// https://www.typescriptlang.org/play?jsx=0#gist/65ff817661487a3bfb02a5c698825df9
/** test type of obj w nesting */
type T000 = {
a1: {
b1: boolean
@zachhardesty7
zachhardesty7 / on-element-ready.js
Last active March 15, 2021 16:22 — forked from sidneys/library.on-element-ready.js
UserScript | Library | onElementReady ES6
// ==UserScript==
// @name Library | onElementReady ES6
// @namespace de.sidneys.userscripts
// @homepage https://gist.githubusercontent.com/zachhardesty7/b19c33e4b2cec8861d55df10be0ce162/raw/
// @version 0.6.0
// @description Detect any new DOM Element by its CSS Selector, then trigger a function. Includes Promise- & Callback interface. Based on ES6 MutationObserver. Ships legacy waitForKeyElements interface, too.
// @author sidneys
// @icon https://i.imgur.com/nmbtzlX.png
// @include *://*/*
// ==/UserScript==