Skip to content

Instantly share code, notes, and snippets.

@leothorp
leothorp / toggle_desktop_visibility.sh
Last active October 29, 2023 02:38
toggle visibility of desktop icons on mac
function toggle-dtop() {
ICON_VISIBILITY_STATE=${ICON_VISIBILITY_STATE:-1}
defaults write com.apple.finder CreateDesktop $ICON_VISIBILITY_STATE && killall Finder;
ICON_VISIBILITY_STATE=$((!ICON_VISIBILITY_STATE))
}
@leothorp
leothorp / fast-js-pre-commit
Last active October 29, 2023 02:26
JS pre-commit hook (Prettier, linting). Noticeably faster than lint-staged.
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"
set -e
bin_dir="node_modules/.bin"
echo "running pre-commit script..."
# --diff-filter used to exclude deleted files
prettier_staged_files=$(git diff --cached --name-only --diff-filter="ACMRTUXB")
eslint_staged_files=$(git diff --cached --name-only --diff-filter="ACMRTUXB" -- *.{tsx,ts,js,jsx})
@leothorp
leothorp / pnpm-reinstall-post-merge
Last active January 31, 2023 05:50
Husky post-merge hook: auto-update pnpm packages
#!/usr/bin/env sh
. "$(dirname "$0")/_/husky.sh"
# navigate to parent of husky dir- we assume pnpm-lock is located there.
cd "$(dirname $0)/.."
LOCKFILE_CHANGED_LINES=`git diff HEAD@{1} --stat -- pnpm-lock.yaml | wc -l`
@leothorp
leothorp / bash_helpers.sh
Last active January 31, 2023 05:46
git bash helpers
#serve the files in the current directory at http://localhost:3000
alias serve-dir="python -m SimpleHTTPServer 3000"
#undo the last commit, leaving all its changes unstaged but still present
alias grollback="git reset HEAD~"
#reset local master to match origin/master
alias reset-local-master="git checkout -B master origin/master"
alias ga="git add ."
@leothorp
leothorp / jsconfig.json
Created April 17, 2018 22:20
VSCode jsconfig.json React
{
"compilerOptions": {
"target": "ES6",
"module": "commonjs",
"allowSyntheticDefaultImports": true,
"jsx": "react",
"alwaysStrict": true
},
"exclude": [
"dist",