Skip to content

Instantly share code, notes, and snippets.

View dyoung522's full-sized avatar

Donovan C. Young dyoung522

View GitHub Profile
@dyoung522
dyoung522 / options.rb
Created May 11, 2015 21:00
Ruby OptParse
require 'optparse'
require 'ostruct'
class OptParse
#
# Return a structure describing the options.
#
def self.parse(args)
# The options specified on the command line will be collected in *options*.
# We set default values here.
@dyoung522
dyoung522 / add_static_route.sh
Created January 8, 2015 19:01
Add a permanent static route to OS X 10.10
#!/bin/bash
sudo /sbin/route add -net x.x.x.0/24 xxx.xxx.xxx.xxx
# Save this file somewhere and make it executable (chmod a+x <file>)
# Then run 'sudo defaults write com.apple.loginwindow LoginHook /Path/To/Your/Script'
@dyoung522
dyoung522 / pathmunge.sh
Last active November 22, 2015 10:32
pathmunge() bash function to add to PATH without duplication
pathmunge () {
if [ "$2" = "force" ] || ! echo $PATH | $(which egrep) -q "(^|:)$1($|:)"
then
if [ "$2" = "after" ]
then
PATH=$PATH:$1
else
PATH=$1:$PATH
fi
export PATH
@dyoung522
dyoung522 / boxen-setup.sh
Last active December 23, 2015 08:59
Boxen configuration setup
#!/bin/sh
fail() {
echo "Whoops... $*"
exit 1
}
if [ ! -d /opt/boxen ] ; then
sudo mkdir -p /opt/boxen && sudo chown ${USER}:staff /opt/boxen
fi || fail "could not create /opt/boxen"
@dyoung522
dyoung522 / State.rb
Created November 9, 2012 18:12
Ruby on Rails 3 model to serve US States without a database
class State
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_reader :all
US_STATES = {
AL: "Alabama",
AK: "Alaska",
AZ: "Arizona",