Skip to content

Instantly share code, notes, and snippets.

View koehn's full-sized avatar
🧐
Coaching

Brad Koehn koehn

🧐
Coaching
View GitHub Profile
@koehn
koehn / quit.sh
Created January 4, 2014 16:48
A simple command-line utility to use AppleScript (neé OSAScript) to quit an application. Usage: `quit [Application Name]`
#!/bin/bash
osascript -e "tell application \"$1\" to quit"
@koehn
koehn / mysql-db-backup.sh
Created December 31, 2013 03:18
A script to backup MySQL databases. If you're using InnoDB and MariaDB 5.3 or higher, --single-transaction will give you a dump that is consistent without locking the tables. I use this as part of my rsnapshot backups. The use of --single-transaction and the echo "" > /dev/null (to avoid returning non-zero) were the only changes I made.
#!/bin/bash
# A UNIX / Linux shell script to backup mysql server database using rsnapshot utility.
# -------------------------------------------------------------------------
# Copyright (c) 2007 Vivek Gite <vivek@nixcraft.com>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# Tested under RHEL / Debian / CentOS / FreeBSD oses
@koehn
koehn / gitconfig
Created December 7, 2013 18:55
GitConfig with a lot of handy aliases I've come to love.
[alias]
co = checkout
ci = commit
st = status
br = branch
hist = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)&lt;%an&gt;%Creset' --abbrev-commit --date=relative
type = cat-file -t
dump = cat-file -p
undo = reset --hard
new = !sh -c 'git log $1@{1}..$1@{0} "$@"'
@koehn
koehn / block-bad-domains.conf
Last active December 29, 2015 10:38
mod_rewrite configuration to send either a 410 (Gone) or a robots file with disallow * for any request to a domain other than one I own. I needed this because some Chinese company had been leasing the IP address that I got and still had dozens/hundreds of domain names pointed at my IP; I didn't want my app server getting these and/or redircting …
RewriteEngine On
RewriteCond %{HTTP_HOST} !^.*koehn\.com$
RewriteRule ^robots\.txt$ /robots-off.txt [L]
RewriteCond %{HTTP_HOST} !^.*koehn\.com$
RewriteRule !^robots-off\.txt$ - [L,G]
@koehn
koehn / getip
Created November 24, 2013 15:38
Send the current IP address to stdout.
#!/bin/bash
CHECK_IP=`curl -m 30 http://checkip.dyndns.org/ 2> /dev/null`
if [ $? -ne 0 ]
then
echo Unable to get current IP address with curl >&2
exit 100
fi
echo $CHECK_IP | sed -e 's!.*: \(.*\)</body>.*!\1!'
@koehn
koehn / getip6
Last active December 29, 2015 06:19
Send the current IPv6 address to stdout.
#!/bin/bash
CHECK_IP=`curl -6 -m 5 http://www.whatismyipv6.com/ 2> /dev/null | awk '/^[0-9a-f:]+<tr><td>/ { sub(/<.*/, "") }; { print $0 }' | egrep '^[0-9a-f:]+$'`
if [ $? -ne 0 ]
then
echo Unable to get current IP address with curl >&2
exit 100
fi
echo $CHECK_IP | sed -e 's!.*is \(.*\)</h1>.*!\1!'
@koehn
koehn / backup to encrypted diskimage on remote AFP server.sh
Last active September 25, 2017 19:36
Script for backing up a Mac OS X folder to an encrypted disk image on a remote AFP server. You must first create the encrypted disk image using Disk Utility. I recommend making it a sparsebundle for better use of space and performance. You can run this with cron and append the output to a log file. Modify the `rsync` command to exclude subdirect…
#!/bin/bash
echo =====================================
echo `date` Backing up Documents
# The URL to your remote AFP server. You can test your URL using command-K in the Finder.
AFP_URL=afp://user:password@afp.server.com/Share
# The place where the AFP server is mounted. By default this will be in /Volumes someplace.
AFP_DIRECTORY=/Volumes/Share