Skip to content

Instantly share code, notes, and snippets.

View erichs's full-sized avatar

Erich Smith erichs

View GitHub Profile

Keybase proof

I hereby claim:

  • I am erichs on github.
  • I am erichs (https://keybase.io/erichs) on keybase.
  • I have a public key whose fingerprint is 688D B17A 9CCD EA27 8C9E F6A4 91CC 9E0A 4A75 C982

To claim this, I am signing this object:

@erichs
erichs / shellgoodies.sh
Last active January 31, 2017 21:13
Fuzzy find, open, edit, etc. from current dir with text preview -- source me!
wut () {
local needle="$*"
local out file key OIFS
OIFS=$IFS
IFS=$'\n' out=($(ag -il $needle | fzf --reverse \
--preview="ag --color -C 5 $needle {}" \
--prompt '(ctrl-{l,o,e,g} to link, open, edit, or browse in github)> ' \
--expect=ctrl-l,ctrl-o,ctrl-e,ctrl-g))
IFS=$OIFS
if [ -z "$out" ]; then
@erichs
erichs / capfile.md
Last active November 22, 2017 14:42
Papers, Please
    set :application, `basename $(pwd)`.chomp
    set :commit_sha, `git rev-parse --short "HEAD"`.chomp
    set :default_environment, {
      "RATIONALE_CLIENT" => "capistrano",
      "RATIONALE" => "'Deploying #{application} #{commit_sha}'"
    }
@erichs
erichs / pb.sh
Created July 30, 2015 21:17
pb - DWIM clipboard manipulation
pb() {
if [[ -p /dev/stdin ]]; then # STDIN is attached to a pipe
pbcopy
fi
if [[ ! -t 0 && ! -p /dev/stdin ]]; then # STDIN is attached to a redirect
pbcopy
fi
if [[ -t 1 ]]; then # STDOUT is attached to a TTY
@erichs
erichs / improved_binary.sh
Last active January 21, 2018 19:10
Improved Shell script with binary data
#!/bin/bash
{
cd /path/to/unzip || exit
while read line; do
case $line in
"exit 0") break;;
esac
done
tar zxf -
} < "$0"
@erichs
erichs / binary.sh
Created August 19, 2014 12:57
Shell script with inline binary data
#!/bin/bash
sudo do_whatnot_first
tail -n +8 $0 | tar -zxf - -C /tmp
cd /tmp/my_extracted_tarfile_location
./configure && make && sudo make install
exit 0
#//EOF
$ cat myprog.tar.gz >> binary.sh

Using Unicorn with Upstart

This configuration works with Upstart on Ubuntu 12.04 LTS

The reason why it needs to be done this way (i.e. with the pre-start and post-stop stanzas), is because Upstart is unable to track whever Unicorn master process re-execs itself on hot deploys. One can use it without hot-deploys and run Unicorn in foreground also, it then only needs one exec stanza.

This presumes you are not using RVM, so no voodoo dances.

@erichs
erichs / wphosting.md
Last active August 29, 2015 13:58
Thoughts on WordPress hosting

Comparing Red Delicious to Granny Smith

How do you like these apples?

Assumptions:

  • shared hosting
  • ftp and cPanel access (+phpMyAdmin)
  • wordpress optimized, all or most themes supported

Start with Performance

Speed: more than a movie with Sandra Bullock

@erichs
erichs / ghanity.sh
Created March 18, 2013 15:02
create GitHub vanity url using git.io shortening service. Works with OSX clipboard
ghanity ()
{
local code="$1" url="$2";
echo 'creating vanity GitHub URL... ';
ghurl=$(curl -s -i http://git.io -F "url=$url" -F "code=$code" | grep Location | awk '{print $2}');
echo $ghurl | pbcopy;
echo "copied to clipboard: ${ghurl}"
}
@erichs
erichs / backup_mysql_databases.rb
Created March 17, 2013 14:07
backup mysql databases over SSH
#!/usr/bin/env ruby
# backup_mysql_databases.rb - pulls data from various database hosts and dbs,
# and stores these in a centrally mounted location
# for offsite backup
#
# Erich Smith
#
# This script is intended to be run via daily CRON task, and will generate a
# single set of zipped backup files per day, one file per defined host