Skip to content

Instantly share code, notes, and snippets.

View mceachen's full-sized avatar

Matthew McEachen mceachen

View GitHub Profile
@mceachen
mceachen / git-addgrep
Created November 29, 2023 04:11
git addgrep: stage all diff hunks that match a given regexp
#!/bin/bash -e
# Renamed a file or method? Use this to add all files matching that regex pattern.
# Assumes this file lives in $ROOT/bin, so we need to hop up a level (the `/..` bit)
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null 2>&1 && pwd)"
cd "$ROOT"
# Ignore calls to `git add` that have no filenames:
git config advice.addEmptyPathspec false
@mceachen
mceachen / git-restage
Last active November 29, 2023 04:09
git-restage: Ensure all diffs in currently staged files are staged.
#!/bin/sh
# Stage all diffs found in currently staged files
# This is useful if you've got a set of files ready to commit, but edited one
# or more of them (via prettier, delinting, deleting debug statements, adding
# more tests, ...), and want to make sure those changes are included.
# Usage: `git restage`
@mceachen
mceachen / thenCollect.ts
Created July 11, 2020 21:14
Serial collection of a SyncOrAsync array applied against a function
export type SyncOrAsync<T> = T | Promise<T>
export type Maybe<T> = T | undefined
export type MaybeSyncOrAsync<T> = Maybe<SyncOrAsync<Maybe<T>>>
/**
* Serialized promise gathering and compaction
*/
export async function thenCollect<T1, T2>(
arr: MaybeSyncOrAsync<MaybeSyncOrAsync<T1>[]>,
f: (t: T1) => MaybeSyncOrAsync<T2>
@mceachen
mceachen / Example.ts
Last active July 4, 2020 22:14
TypeScript enumerations
export const Directions = strEnum("North", "South", "East", "West")
export type Direction = StrEnumKeys<typeof Directions>
@mceachen
mceachen / library-settings.toml
Created January 8, 2020 18:00
PhotoStructure settings snapshots
#
# Hello!
#
# These are settings for PhotoStructure, and are formatted using TOML. See
# <https://github.com/toml-lang/toml>.
#
# NOTE: Please shut down PhotoStructure before editing this file.
#
# Most settings have reasonable defaults, which are provided after the
@mceachen
mceachen / clone.sh
Created December 13, 2019 23:59
PhotoStructure for Node installation instructions
sudo -u photostructure bash
cd ~photostructure
git clone https://github.com/photostructure/photostructure-for-servers.git
@mceachen
mceachen / fe.ts
Created December 12, 2019 23:38
Add title with URL for browsers that hide the URL on hover
export function $$<T extends HTMLElement = HTMLElement>(selector: string) {
return document.querySelectorAll<T>(selector)
}
export function blank(o: any): o is undefined {
if (o == null) return true
const s = String(o)
return s.length === 0 || s.trim().length === 0
}
@mceachen
mceachen / LICENSE.md
Created October 28, 2019 05:53
TypeScript implementation of Optional/Some/None

MIT License

Copyright (c) 2016-2019 Matthew McEachen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

@mceachen
mceachen / etc > network > if-post-down.d > shutdown
Last active June 28, 2019 23:34
Gracefully shut down when the network shuts down.
#!/bin/sh
# This should be placed in /etc/network/if-post-down.d/shutdown, and set as executable.
/sbin/shutdown -h now
### Keybase proof
I hereby claim:
* I am mceachen on github.
* I am mrmceachen (https://keybase.io/mrmceachen) on keybase.
* I have a public key ASCBWP-ugfBxlKdzBnWZgKVkGVm0WZ3mt7x8Y2OCB-hJfwo
To claim this, I am signing this object: