Skip to content

Instantly share code, notes, and snippets.

View heph's full-sized avatar
:shipit:

Heph Adams heph

:shipit:
View GitHub Profile
@heph
heph / gist:5274247
Last active December 15, 2015 14:28
load environment variables from a per-directory rc file, reset to default upon entering any directory which doesn't have a .dirrc owned by your current user
# source each directory's .dirrc for project-specific environment variables
function cd () {
builtin cd "$@"
if [[ $PWD == $HOME* ]]; then
DIRPATH=( $(pwd) )
i=$((${#DIRPATH[@]} - 1))
while [ -O ${DIRPATH[$i]} ]; do
DIRPATH=("${DIRPATH[$i]}/.." "${DIRPATH[@]}")
done
@heph
heph / gist:5260581
Last active December 15, 2015 12:29
Capistrano prompt for username and password with default value
set(:user, Capistrano::CLI.ui.ask("Username ") {|q| q.default = Etc.getlogin })
set(:password, Capistrano::CLI.password_prompt("Password "))
@heph
heph / gist:2714799
Created May 16, 2012 23:12
populate hash with command line arguments in the form of ./script.rb key=value key.key=value key.key.key=value
#!/usr/bin/ruby
require 'rubygems'
require 'json'
h = {}
ARGV.each do |a|
position = ObjectSpace._id2ref(h.object_id)
keys,value = a.split('=')