Skip to content

Instantly share code, notes, and snippets.

View sorohan's full-sized avatar

Ben Sorohan sorohan

  • Brisbane, Australia
View GitHub Profile
@sorohan
sorohan / git-find-lost-file
Last active April 14, 2021 01:21
Find a lost file from an orphaned git commit.
file=$1
for f in $(git fsck --lost-found | grep 'dangling commit' | awk '{print $3}'); do
git log --stat $f | grep $file &> /dev/null;
if [ $? -eq 0 ]; then
git log -1 $f;
fi;
done
@sorohan
sorohan / git-folder-renames
Created February 23, 2015 12:43
Track folder renames in git.
#!/bin/bash
d=$1
function first_commit_on_dir() {
d=$1
echo $(git log --follow --oneline --pretty=format:'%H' --reverse -- "$d" | head -1)
}
function get_renames() {
@sorohan
sorohan / check-mysql-disabled-keys.sh
Created July 15, 2014 07:03
Checks all databases/tables in mysql for disabled keys.
#!/bin/bash
#
# Check all databases/tables in mysql for disabled keys.
#
MYSQL="mysql"
dbs=$(echo "show databases" | $MYSQL -N)
for db in $dbs; do
@sorohan
sorohan / mysql-reset-root-pw.sh
Last active October 24, 2016 03:18
Reset mysql root password on unix without needing old password.
#!/bin/bash
MYSQL_ROOT_PASSWORD=$1
if [ -z "$MYSQL_ROOT_PASSWORD" ]; then
echo 'Missing required $1 (password).'
exit 1
fi
# check if mysql is running now.
#!/bin/sh
#
# Usage: mysql-backup.sh dbname <daily|hourly|weekly|monthly> <backup dir> <dump args>
#
if [ -z $1 ]; then
echo "Missing required dbname."
exit 1
fi