Skip to content

Instantly share code, notes, and snippets.

View midwire's full-sized avatar
🏠
Working from home

Chris Blackburn midwire

🏠
Working from home
View GitHub Profile
@midwire
midwire / gateway.sh
Created July 10, 2014 13:56
Determine the default gateway on OSX.
#!/usr/bin/env bash
# determine the local gateway
netstat -nr|grep '^default'
@midwire
midwire / notify.rb
Created July 10, 2014 13:58
Notify after a long-running shell command
#!/usr/bin/env ruby
require "rubygems"
require "thor"
require 'terminal-notifier'
class NotifyAfter < Thor
desc "after ARGS",
"ARGS is the after and list of arguments to run, after which you will be notified."
@midwire
midwire / postgres.server.sh
Created July 10, 2014 13:58
Postgres control script.
#!/bin/bash
cmd=$1
function init_postgres() {
initdb /usr/local/var/postgres
}
function start_postgres() {
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
@midwire
midwire / recursive_unlock.sh
Created July 10, 2014 13:59
Simple file unlocking utility for Mac OSX.
#! /bin/bash
#
# Simple file unlocking utility for Mac OS X
#
ARGS=1
E_BADARGS=65
SETFILE=/Applications/Xcode.app/Contents/Developer/usr/bin/SetFile
function recursiveUnlock() {
pushd $1
@midwire
midwire / redis.server.sh
Created July 10, 2014 13:59
Redis server control script.
#!/usr/bin/env bash
cmd=$1
function start_redis() {
nohup redis-server /usr/local/etc/redis.conf > /dev/null 2>&1 &
}
function stop_redis() {
redis-cli shutdown
@midwire
midwire / restest.sh
Created July 10, 2014 14:00
Use curl for REST testing APIs
#!/usr/bin/env bash
# Use curl for REST testing apis
#
# curl params:
# i – show response headers
# H – pass request headers to the resource
# X – pass a HTTP method name
# d – pass in parameters enclosed in quotes; multiple parameters are separated by ‘&’
# curl -i -H "Accept: application/json" -X POST -d "firstName=james" http://192.168.0.165/persons/person
@midwire
midwire / set_random_mac_address.sh
Created July 10, 2014 14:01
Set a random MAC address on OSX
#!/bin/bash
# ether 3c:07:54:12:6d:fc
if [ -z "$1" ]; then
echo "usage: $0 NETWORK_INTERFACE(en0|en1)"
exit 1
fi
interface="$1"
mac=`openssl rand -hex 1 | \
@midwire
midwire / tor.server.sh
Created July 10, 2014 14:02
TOR service control script
#!/usr/bin/env bash
cmd=$1
function start_tor() {
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.tor.plist
}
function stop_tor() {
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.tor.plist
@midwire
midwire / varnish.server.sh
Created July 10, 2014 14:02
Varnish service control script
#!/usr/bin/env bash
cmd=$1
PROG=/usr/local/opt/varnish3/sbin/varnishd
VCL=/usr/local/etc/varnish/default.vcl
OPTS="-n /usr/local/var/varnish -f $VCL -s malloc,1G -T localhost:6082 -a :6081"
function start_varnish() {
echo "Running [$PROG $OPTS]"
$PROG $OPTS
@midwire
midwire / bulk_file_rename
Last active August 29, 2015 14:04
bulk_file_rename
#!/usr/bin/env ruby
# A Ruby bulk file renaming script
require 'fileutils'
require 'pry'
require 'colored'
require 'trollop'
class BulkFileRename
include FileUtils