Skip to content

Instantly share code, notes, and snippets.

View zachhardesty7's full-sized avatar

Zach Hardesty zachhardesty7

View GitHub Profile
@zachhardesty7
zachhardesty7 / __wdyr-18.ts
Last active June 30, 2025 19:38
React: wdyr (why-did-you-render)
/// <reference types="@welldone-software/why-did-you-render" />
// ^ doesn't actually do anything in some projects?
import React from "react";
// NOTE: add `import './__wdyr-18';` to top of your entry file (e.g. `index.tsx` or `App.tsx`) to enable WDYR
// NOTE: to install the correct version for React 18, run `npm install @welldone-software/why-did-you-render@^8 --save-dev --save-exact`
// https://github.com/welldone-software/why-did-you-render/tree/version-8
// https://github.com/welldone-software/why-did-you-render/tree/version-8#tracking-components
@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 December 3, 2024 00:12
TS: KeysAssignableType
// copyright 2023 Zach Hardesty
// TODO: check out https://www.totaltypescript.com/get-keys-of-an-object-where-values-are-of-a-given-type
/**
* Extracts keys of `TObj` that correspond to values that some type in the union
* `TTypes` can be assigned to
*
* @template TObj Object to extract keys from
* @template TTypes Type to check for assignability
@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 August 12, 2024 22:46
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