Skip to content

Instantly share code, notes, and snippets.

nhoag /
Last active May 7, 2019 — forked from w00fz/
PHP switcher
# 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
# Usage
nhoag /
Created Sep 6, 2016 — forked from pixelhandler/
Git pre-push hook to prevent force pushing master branch
# 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 / 9191_config.php
Created Feb 4, 2016
This is a sample addition to the config.php for SimpleSAMLphp for Acquia Cloud.
View 9191_config.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 /
Created Jan 2, 2016 — forked from chrisroos/
Instructions for exporting/importing (backup/restore) GPG keys

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 /
Last active Oct 16, 2020
Dynamic menu in bash
ENTITIES=$(ls -1)
while read -r line; do
echo "$SELECTION) $line"
done <<< "$ENTITIES"
nhoag /
Created Dec 23, 2015
Calculate bandwidth per minute from access log
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 /
Last active Jan 16, 2016
Bash Script Boilerplate
set -a ; set -o errexit ; set -o nounset
function usage() {
cat <<EOF
Usage: ${0} ARG
-h Show usage
nhoag /
Created Nov 20, 2015
Return a list of the largest objects in a Git repo in a human-readable format
HASHES_SIZES=$(git verify-pack -v .git/objects/pack/pack-*.idx \
| sort -k 3 -rn \
| head -20 \
| awk '{print $1,$3}' \
| sort)
| awk '{printf $1"|"}' \
| sed 's/\|$//')
nhoag /
Last active Oct 31, 2015
Get Popular Items from Pinboard in your terminal
nhoag /
Last active Oct 29, 2015
Returns a pretty list of trending repos from Github in your terminal
function gh-trend() {
local INTERVAL=${1:-'daily'}
echo -e "Github Trending: $INTERVAL"
curl -s\?since=${INTERVAL} \
| xmllint --html --xpath '//h3/a/@href|//p[@class="repo-list-description"]/text()' - 2>/dev/null \
| sed 's#href=\"#\'$'\n' \
| grep -Ev '^[ ]+$' \
| grep -Ev '^$' \
| sed 's/^[ ]*//;s/[ ]*$//;s/\"$//;s/^/* /;s/^* https/\'$'\n\033[0;32mhttps/;s#^* #\\'$'\n\t\033[0m* #'
You can’t perform that action at this time.