Skip to content

Instantly share code, notes, and snippets.

View jasontbradshaw's full-sized avatar

Jason T. Bradshaw jasontbradshaw

View GitHub Profile
@jasontbradshaw
jasontbradshaw / start-autostart-freenas-jails.sh
Last active March 24, 2016 02:18
This script starts FreeNAS 9.3 jails that are configured to auto-start, but due to a bug (https://bugs.pcbsd.org/issues/7155) don't do so after pool unlock. This should be run as a CRON job as root every minute, and will only attempt to start the jails a single time.
#!/usr/bin/env bash
# Strict mode (see: http://redsymbol.net/articles/unofficial-bash-strict-mode/).
set -euo pipefail
IFS=$'\n\t'
# Exit if not running as root.
if [ "$(id -u)" != "0" ]; then
>&2 echo "This script must be run as root."
exit 1
#!/usr/bin/env bash
# Strict mode (see: http://redsymbol.net/articles/unofficial-bash-strict-mode/).
set -euo pipefail
IFS=$'\n\t'
@jasontbradshaw
jasontbradshaw / ztype-ftw.js
Created December 18, 2015 22:59
How to win at ZType (http://zty.pe).
clearInterval(window.shootInterval);
var targetComparator = function (a, b) {
var aDist = ig.game.player.distanceTo(a);
var bDist = ig.game.player.distanceTo(b);
return aDist - bDist;
};
shootInterval = setInterval(function () {
if (!ig.game) { return; }
@jasontbradshaw
jasontbradshaw / dice-10.sh
Last active December 4, 2015 17:37
Generate a Diceware-style password list.
#!/usr/bin/env bash
# This script takes a list of words and turns it into a 10-sided-die version of a
# Diceware list. It:
# * Reads a list of words
# * Removes long words and those with non-ASCII characters, for ease-of-use
# * Randomly orders them
# * Takes the first 10,000 (for use with 10-sided dice)
# * Sorts them nicely
# * Numbers the lines appropriately
@jasontbradshaw
jasontbradshaw / backup.bup
Last active December 28, 2021 12:56
A backup script using bup.
#!/usr/bin/env bash
# Strict mode (see: http://redsymbol.net/articles/unofficial-bash-strict-mode/).
set -euo pipefail
IFS=$'\n\t'
# We name the repository directory after the system's hostname and the current
# year/month. We include the year/month combo so our backup repository doesn't
# continue to grow forever, and we can manually delete old ones as necessary.
name="$(hostname)"
@jasontbradshaw
jasontbradshaw / backup.tar
Last active December 28, 2021 12:56
A simple backup script using tar.
#!/usr/bin/env sh
# arguments
name="${1}"
src="${2}"
dest_dir="$(dirname "${3}/gets_removed")"
# validate arguments
if [ -z "${name}" ]; then
echo "Invalid backup name (first argument)"
@jasontbradshaw
jasontbradshaw / iso-select.sh
Created April 18, 2015 23:35
isostick ISO Selector Script
#!/usr/bin/env sh
isofile='./config/iso_filename.txt'
isofile_pretty="$(basename "${isofile}")"
iso="${1}"
# if the user supplied an argument, write it to the file, otherwise offer them a
# choice of all present ISO files
if [ -n "${iso}" ]; then
echo "${iso}" > "${isofile}"
@jasontbradshaw
jasontbradshaw / burnin
Last active December 13, 2018 05:46
Hard Drive burn-in script. Useful for testing new drives to make sure they're up-to-snuff, and to prepare them for subsequent full-disk encryption.
#!/usr/bin/env bash
if [ "${EUID}" -ne 0 ]; then
echo "This script must be run as root!" 1>&2
exit 1
fi
# Gets the progress of a running SMART test as a string, or outputs nothing if
# no test is currently running.
function get_smart_progress {
@jasontbradshaw
jasontbradshaw / resolve
Last active September 11, 2016 20:25
A bash script that resolves its own physical path
#!/usr/bin/env bash
# Courtesy http://stackoverflow.com/a/246128.
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do
# Resolve `$SOURCE` until the file is no longer a symlink.
DIR="$(cd -P "$(dirname "$SOURCE")" && pwd)"
SOURCE="$(readlink "$SOURCE")"
# If `$SOURCE` was a relative symlink, we need to resolve it relative to the
@jasontbradshaw
jasontbradshaw / endpoint-test
Last active August 29, 2015 14:01
Given a series of URLs, tests them for a success response. Exits success only when all pass.
#!/usr/bin/env sh
# handy colors, for readability
black='\033[0;30m'
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
blue='\033[0;34m'
purple='\033[0;35m'
cyan='\033[0;36m'