Skip to content

Instantly share code, notes, and snippets.

View jdforsythe's full-sized avatar

Jeremy Forsythe jdforsythe

View GitHub Profile
@jdforsythe
jdforsythe / write-offenders.sh
Created July 13, 2017 12:40
Highest disk usage offending processes
#!/bin/bash
## requires iotop to be installed
sudo iotop -botqqqk --iter=600 >> iotop.log
cat iotop.log \
## remove characters before write speed
| cut -c 41- \
## look for any write speed that is non-zero
@jdforsythe
jdforsythe / vscode-command-editor.sh
Created May 3, 2017 14:45
Use Visual Studio Code as long command editor in Git Bash on Windows
## Bash lets you use CTRL+X CTRL+E to edit-and-execute a command
## This will allow you to set up VS Code as the editor for this (and other Bash edit functions)
echo "export VISUAL=\"code -n -w\"" >> ~/.bashrc
source ~/.bashrc
## Then when you're typing a long command and need to change something or otherwise want better
## editing control over a command, simply hit CTRL+X CTRL+E and edit the command, then save
## and exit VS Code and the command will execute
## For Sublime Text
@jdforsythe
jdforsythe / git-commits-per-author.sh
Last active January 3, 2017 19:18
Git Repo Statistics
#!/bin/bash
if [ ! -f .mailmap ]; then
echo "WARNING: File .mailmap not found. If you get multiples of names check:"
echo "https://git-scm.com/docs/git-shortlog#_mapping_authors"
echo ""
echo "--------------------"
echo ""
fi
@jdforsythe
jdforsythe / unique_index_with_where.sql
Created November 16, 2016 21:35
PostgreSQL constraint - column A unique for rows where column B is true
-- Scenario: There should only exist one record for each distinct value for column A that has column B set to true. There can be any number of records for each distinct value for column A where column B is false.
-- i.e. there can be only one active record (column B true) for each distinct value of column A
DROP TABLE IF EXISTS test;
CREATE TABLE test (
"a" CHARACTER VARYING(3) NOT NULL,
"b" BOOLEAN NOT NULL DEFAULT TRUE
);
@jdforsythe
jdforsythe / sourcetree-open-on-github.bat
Created October 28, 2016 13:48
SourceTree Open on GitHub Custom Actions
ruby d:\dev\sh\sourcetree\sourcetree-open-on-github.rb %1
@jdforsythe
jdforsythe / git-rename-stash.sh
Created October 28, 2016 13:45
Rename Git Stash
#!/bin/bash
git stash list
echo "Enter stash number to rename"
read stash_number
echo "Enter new name"
read new_name
stash_name="stash@{${stash_number}}"
echo "$stash_name"
@jdforsythe
jdforsythe / git-clean.sh
Created September 8, 2016 18:38
Git Maintenance
#!/bin/bash
echo "Cleaning git merge conflict artifacts..."
find . -name "*.bak" | while read filename; do echo "Removing: $filename" && rm -rf "$filename"; done
echo -e "\n"
echo "Counting unreachable objects in git database..."
unreachable=$(git fsck --unreachable | wc -l)
echo "There are $unreachable unreachable objects."
@jdforsythe
jdforsythe / oldest-ancestor-alias.sh
Created August 2, 2016 12:29
GIT find commit where branched off
#!/bin/bash
# "master" is the name of your main branch you'll be comparing to, or you can pass the "parent" branch as an argument
# it compares against the current branch by default, but you can pass a second argument to specify a child branch
# this creates a permanent alias so you can use `git oldest-ancestor` to get the oldest ancestor of the current branch at any time
git config --global alias.oldest-ancestor '!zsh -c '\''diff --old-line-format='' --new-line-format='' <(git rev-list --first-parent "${1:-master}") <(git rev-list --first-parent "${2:-HEAD}") | head -1'\'' -'
@jdforsythe
jdforsythe / changes-between-commits.sh
Last active October 18, 2021 21:45
Show stats in git repo
#!/bin/bash
# did you pass all the arguments?
nl=$'\n'
if [ $# -lt 3 ]; then
echo 1>&2 "$0: not enough arguments${nl}USAGE: changes-between-commits.sh \"Author Name\" FROM_COMMIT_SHA TO_COMMIT_SHA"
exit 2
elif [ $# -gt 3 ]; then
echo 1>&2 "$0: too many arguments${nl}USAGE: changes-between-commits.sh \"Author Name\" FROM_COMMIT_SHA TO_COMMIT_SHA"
exit 2
cat log.log | grep '\[2016\-05' | cut -c 23- | sort | uniq -c | sort -rn > 2016-05_error_count.log