Skip to content

Instantly share code, notes, and snippets.

View dylansmith's full-sized avatar

Dylan Smith dylansmith

View GitHub Profile
@dylansmith
dylansmith / npm_userspace.sh
Created January 12, 2015 10:50
Configure npm to install global modules to userspace (set npm prefix to ~/npm)
#!/bin/bash
DIR=~/npm
if [[ ! -e $DIR ]]; then
mkdir $DIR
elif [[ ! -d $DIR ]]; then
echo "$DIR exists but is not a directory" 1>&2
exit 1
fi
@dylansmith
dylansmith / start.sh
Created February 27, 2015 17:00
Run nodemon and gulp serve together in a single command
#!/bin/bash
PIDFILE="nodemon.pid"
SERVER_PATH="server/index.js"
CLIENT_TASK="gulp serve"
if [ ! -f $PIDFILE ]; then
nohup nodemon $SERVER_PATH >/dev/null 2>&1 &
PID=$!
echo $PID > $PIDFILE
@dylansmith
dylansmith / random-pass-bookmarklet.js
Created March 11, 2015 09:48
Bookmarklet to generate a random password
(function() {
var url = 'https://www.random.org/passwords/?num=1&len=$1&format=plain&rnd=new', xhr = new XMLHttpRequest(), len, req, output;
len = window.prompt('How many characters?', 15);
url = url.replace('$1', len);
xhr.onload = function() { prompt('Here\'s your password', this.responseText); };
xhr.open('get', url, true);
xhr.send();
}());
@dylansmith
dylansmith / git_push_set_upstream.sh
Created March 31, 2015 10:22
A bash alias to push a local git branch for the first time with --set-upstream
#!/bin/bash
# place this in your .bash_aliases or similar
git_current_branch() {
git rev-parse --abbrev-ref HEAD
}
git_push_set_upstream() {
branch=`git_current_branch`
cmd="git push --set-upstream origin $branch"
@dylansmith
dylansmith / gist:b61d9272400d169f9364
Last active August 29, 2015 14:19
Test helpers to detect & automatically hand-crank your asynchronous Angular test using $rootScope.$digest()
// see: http://jsbin.com/gipiyi/1/edit?js,output
// App code:
// =========
var app = angular.module('app', []);
app.factory('HodorFactory', function($q) {
return {
isHodor: function() {
return $q(function(resolve) {
@dylansmith
dylansmith / gist:66efa6b9acd696250fb3
Created July 1, 2015 14:58
Gulp task to run sass-lint and pipe to a text file
gulp.task('shell-scss-lint', function() {
gulp.src('')
.pipe($.shell([
'scss-lint -c src/config/scss-lint.config.yml src/app/common/styles/ > scss-report.txt'
]))
// swallow errors
.on('error', function() {
this.emit('end');
});
@dylansmith
dylansmith / compare_mysql_dbs.sql
Last active October 8, 2015 15:08
Compare table counts across 2 MySQL databases
SELECT t1.TABLE_NAME, t1.TABLE_ROWS, t2.TABLE_ROWS
FROM INFORMATION_SCHEMA.TABLES t1, INFORMATION_SCHEMA.TABLES t2
WHERE t1.TABLE_NAME = t2.TABLE_NAME
AND t1.TABLE_SCHEMA = 'table1'
AND t2.TABLE_SCHEMA = 'table2'
@dylansmith
dylansmith / create_aws_creds.sh
Created October 15, 2015 11:18
Create .aws/credentials from environment vars
#!/bin/bash
mkdir -p ~/.aws
echo -e "[default]\naws_access_key_id=$AWS_ACCESS_KEY_ID\naws_secret_access_key=$AWS_SECRET_ACCESS_KEY" > ~/.aws/credentials
@dylansmith
dylansmith / ec2ssh.sh
Last active October 27, 2015 06:11
ec2 ssh access by "name" tag and instance number, with optional command to pass
#!/bin/bash
# USAGE:
# ./ec2ssh.sh <tag:name> <instance_num> [<remote_command>]
if [ $# -lt 2 ]
then
echo "Usage: `basename $0` <tag:name> <instance_num>"
exit 1
fi
@dylansmith
dylansmith / gist:1e398ed1ab92bc0d250e
Created October 27, 2015 08:07
Get directory of current bash script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"