Skip to content

Instantly share code, notes, and snippets.

@haydnba
Last active September 25, 2023 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haydnba/77c259c8914e2ab0c0f3426b6acd1f19 to your computer and use it in GitHub Desktop.
Save haydnba/77c259c8914e2ab0c0f3426b6acd1f19 to your computer and use it in GitHub Desktop.
#
# NPM
#
# List globally installed dependencies without full tree
npm list -g --depth=0
# Install package under an alias (cli / package)
npm i foo@npm:bar
"foo": "npm:bar@^1.2.3"
# Install package from local dir (cli / package)
npm i <..path/to/dir>
"foo": "file:<../path/to/foo>"
#
# Git
#
# Filter operation results e.g. `git branch`
git branch | grep <pattern>
git branch -d $(git branch | grep <pattern>)
# Delete multiple branches matching a pattern
# https://stackoverflow.com/questions/33631326/how-to-delete-branches-whose-name-matches-a-certain-pattern
git branch --list '<pattern>' | xargs -r git branch -d
# Write diff output to file with syntax highlighting
git diff [options] --output=file.diff
git diff [options] > file.diff
# If directory name has changed
git mv <old name> <new name>
# If just case changed
git mv path/to/NAME tmp
git mv tmp path/to/name
# Basic archiving (use file extension)
git archive --output=file.zip|tar HEAD
#
# SHELL
#
# Make a file executable
chmod u+x <path_to_file>
chmod 755 <path_to_file>
# Make contents of directory executable
chmod ug+x <path_to_dir>/*
# Update a file in-place - mac OS (with / without backup)
sed -i.bak 's/foo/bar/g' <path_to_file>
sed -i '' 's/foo/bar/g' <path_to_file>
# Set for mac OS or default to Unix
[[ $OSTYPE == "darwin"* ]] && echo "foo" || echo "bar"
# Parameter expansions (can use range)
mv foo.{js,js.map} bar
mv foo{1..9}.gif bar
#
# Ngrok
#
# Expose local instance on given host
ngrok http -host-header=<sub.example.com> <port>
# Expose local instance on full origin
ngrok http -host-header=rewrite <protocol:sub.example.com:port>
#
# Mac
#
# Unmount a stuck disk
diskutil list
diskutil unmount /dev/<IDENTIFIER>
# Identify and kill process on port <port-number>
sudo lsof -i :<port-number>
sudo kill -9 <process-id> # get pid from previous command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment