Skip to content

Instantly share code, notes, and snippets.

Nathaniel Hoag nhoag

Block or report user

Report or block nhoag

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@nhoag
nhoag / sphp.sh
Last active May 7, 2019 — forked from w00fz/sphp.sh
PHP switcher
View sphp.sh
#!/bin/bash
# Check if command was run as root.
if [[ $(id -u) -eq 0 ]]; then
echo "The command \"sphp\" should not be executed as root or via sudo directly."
echo "When a service requires root access, you will be prompted for a password as needed."
exit 1
fi
# Usage
@nhoag
nhoag / pre-push.sh
Created Sep 6, 2016 — forked from pixelhandler/pre-push.sh
Git pre-push hook to prevent force pushing master branch
View pre-push.sh
#!/bin/sh
# Called by "git push" after it has checked the remote status,
# but before anything has been pushed.
#
# If this script exits with a non-zero status nothing will be pushed.
#
# Steps to install, from the root directory of your repo...
# 1. Copy the file into your repo at `.git/hooks/pre-push`
# 2. Set executable permissions, run `chmod +x .git/hooks/pre-push`
@nhoag
nhoag / 9191_config.php
Created Feb 4, 2016 — forked from acquialibrary/9191_config.php
This is a sample addition to the config.php for SimpleSAMLphp for Acquia Cloud.
View 9191_config.php
<?php
// All custom changes below. Modify as needed.
// Defines account specific settings.
// $ah_options['database_name'] should be the Acquia Cloud workflow database name which
// will store SAML session information.set
// You can use any database that you have defined in your workflow.
// Use the database "role" without the stage ("dev", "stage", or "test", etc.)
$ah_options = array(
'database_name' => 'mydatabasename',
'session_store' => array(
@nhoag
nhoag / gpg-import-and-export-instructions.md
Created Jan 2, 2016 — forked from chrisroos/gpg-import-and-export-instructions.md
Instructions for exporting/importing (backup/restore) GPG keys
View gpg-import-and-export-instructions.md

Every so often I have to restore my gpg keys and I'm never sure how best to do it. So, I've spent some time playing around with the various ways to export/import (backup/restore) keys.

Method 1

Backup the public and secret keyrings and trust database

cp ~/.gnupg/pubring.gpg /path/to/backups/
cp ~/.gnupg/secring.gpg /path/to/backups/
cp ~/.gnupg/trustdb.gpg /path/to/backups/
# or, instead of backing up trustdb...
@nhoag
nhoag / dyn-menu.sh
Last active Jan 1, 2016
Dynamic menu in bash
View dyn-menu.sh
#!/bin/bash
ENTITIES=$(ls -1)
SELECTION=1
while read -r line; do
echo "$SELECTION) $line"
((SELECTION++))
done <<< "$ENTITIES"
@nhoag
nhoag / bandwidth-per-min.sh
Created Dec 23, 2015
Calculate bandwidth per minute from access log
View bandwidth-per-min.sh
#!/bin/bash
cat access.log \
| awk -F' ' '{
time = substr($4, 2, 17);
times[time] = time;
bandwidth[time] += $10
} END {
for (t in times) print times[t],bandwidth[t]/1024/1024
}' \
@nhoag
nhoag / bash-boilerplate.sh
Last active Jan 16, 2016
Bash Script Boilerplate
View bash-boilerplate.sh
#!/bin/bash
set -a ; set -o errexit ; set -o nounset
function usage() {
cat <<EOF
Usage: ${0} ARG
OPTIONS:
-h Show usage
EOF
@nhoag
nhoag / git-large-humanized.sh
Created Nov 20, 2015
Return a list of the largest objects in a Git repo in a human-readable format
View git-large-humanized.sh
#!/bin/bash
HASHES_SIZES=$(git verify-pack -v .git/objects/pack/pack-*.idx \
| sort -k 3 -rn \
| head -20 \
| awk '{print $1,$3}' \
| sort)
HASHES=$(echo "$HASHES_SIZES" \
| awk '{printf $1"|"}' \
| sed 's/\|$//')
@nhoag
nhoag / pinboard-popular.sh
Last active Oct 31, 2015
Get Popular Items from Pinboard in your terminal
View pinboard-popular.sh
@nhoag
nhoag / github-trend.sh
Last active Oct 29, 2015
Returns a pretty list of trending repos from Github in your terminal
View github-trend.sh
function gh-trend() {
local INTERVAL=${1:-'daily'}
echo -e "Github Trending: $INTERVAL"
curl -s https://github.com/trending\?since=${INTERVAL} \
| xmllint --html --xpath '//h3/a/@href|//p[@class="repo-list-description"]/text()' - 2>/dev/null \
| sed 's#href=\"#\'$'\nhttps://github.com#g' \
| grep -Ev '^[ ]+$' \
| grep -Ev '^$' \
| sed 's/^[ ]*//;s/[ ]*$//;s/\"$//;s/^/* /;s/^* https/\'$'\n\033[0;32mhttps/;s#^* #\\'$'\n\t\033[0m* #'
echo
You can’t perform that action at this time.