Skip to content

Instantly share code, notes, and snippets.

@nhoag
nhoag / sphp.sh
Last active May 7, 2019 19:26 — forked from w00fz/sphp.sh
PHP switcher
#!/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 September 6, 2016 18:00 — forked from pixelhandler/pre-push.sh
Git pre-push hook to prevent force pushing master branch
#!/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 February 4, 2016 15:43
This is a sample addition to the config.php for SimpleSAMLphp for Acquia Cloud.
<?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 January 2, 2016 14:19 — forked from chrisroos/gpg-import-and-export-instructions.md
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
nhoag / dyn-menu.sh
Last active October 16, 2020 17:46
Dynamic menu in bash
#!/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 December 23, 2015 18:55
Calculate bandwidth per minute from access log
#!/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 January 16, 2016 02:12
Bash Script Boilerplate
#!/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 November 20, 2015 03:18
Return a list of the largest objects in a Git repo in a human-readable format
#!/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 October 31, 2015 16:36
Get Popular Items from Pinboard in your terminal
@nhoag
nhoag / github-trend.sh
Last active October 29, 2015 13:06
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 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