Skip to content

Instantly share code, notes, and snippets.

View jonathanconway's full-sized avatar
⌨️
Typing

Jon jonathanconway

⌨️
Typing
View GitHub Profile
@jonathanconway
jonathanconway / bash.sh
Created January 21, 2026 11:54
Some handy shell commands for MacOS
gh gist list --limit 1000
find . -name '' -type f
@jonathanconway
jonathanconway / nil.ts
Created January 21, 2026 02:16
Type and related utilities for dealing with nil or "falsy" values in Typescript
// Type and related utilities for dealing with nil or "falsy" values in Typescript
// Credits:
// • You Don't Know Javascript by Kyle Simpson [Book]
// • Javascript – The Good Parts by Douglas Crockford [Book]
/**
* Value which behaves the same as `false` when evaluated.
*/
export type Nil = undefined | null | false | 0 | -0 | typeof NaN | "";
@jonathanconway
jonathanconway / type-of-const.ts
Created January 11, 2026 02:12
Type utility to transform an object const map into a literal union
/**
* Transform an object const map into a literal union.
*
* @example
* const Colors = {
* Red = "red",
* Green = "green",
* Blue = "blue",
* } as const;
*
@jonathanconway
jonathanconway / deep-merge-maps-of-arrays.ts
Last active January 9, 2026 03:18
Merges multiple maps of T to Array of U into one map
type MapOfArrays<
TKey extends string | number | symbol,
TArrayItem,
TArray extends RelativeIndexable<TArrayItem>,
> = Partial<Record<TKey, TArray>>;
type ReadonlyMapOfArrays<
TKey extends string | number | symbol,
TArrayItem,
> = MapOfArrays<TKey, TArrayItem, ReadonlyArray<TArrayItem>>;
@jonathanconway
jonathanconway / create-with-hoc.ts
Created December 15, 2024 13:27
Creates a function that applies a HOC to a React component
import { get, omit } from "lodash";
import { ComponentType } from "react";
export function createWithHOC<THOCProps, THOCName extends string>(
HOC: ComponentType<THOCProps>,
hocName: THOCName,
) {
return function withHOC<TLOCProps extends JSX.IntrinsicAttributes>(
LOC: ComponentType<TLOCProps>,
) {
@jonathanconway
jonathanconway / list_authors.sh
Created December 14, 2024 02:10
Lists all the unique authors who have edited a given file in the current Git repository
#!/bin/bash
# Generated by ChatGPT.
# Prompt:
# Please write a bash script which finds and lists all the unique authors who
# have edited the given file in the current Git repository. The given file
# will be specified as the first parameter to the bash script.
# Check if a file parameter is provided
@jonathanconway
jonathanconway / .prettierrc
Created March 18, 2024 10:12
Handy sensible defaults for prettier including import ordering and grouping
{
"tabWidth": 2,
"useTabs": false,
"singleQuote": false,
"importOrder": ["^[@]?[a-zA-Z]", "^[@/a-zA-Z]", "^../", "^./"],
"importOrderSeparation": true,
"importOrderSortSpecifiers": true,
"plugins": ["@trivago/prettier-plugin-sort-imports"]
}
alias subl='open -a "Sublime Text"'
alias l="ls -la"
/**
* Enum which supports attached methods.
* Each method's `this` is the enum object.
*/
class Enum {
/**
* @param items {Object} Enum keys and values as a plain object
* @param methods {Object} Enum methods as a plain object
* (names are keys, values are methods)
*/
@jonathanconway
jonathanconway / create-react-app-minimal.sh
Last active May 13, 2018 13:47
Minimalist create-react-app. Just enough to write a failing unit-test. 🔴 ✅
################################################################################
#
# 1. Save this file to /usr/local/bin
#
# 2. To make it executable: chmod u+x /usr/local/bin/create-react-app-minimal.sh
#
# 3. To create your app: create-react-app-minimal {app-name}
#
# 4. In your package.json, change this line:
# "test": ...