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: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('=')
@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: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:8a6073a68cee61ac0d8f
Last active September 28, 2016 18:01
keybase.io identity proof
### Keybase proof
I hereby claim:
* I am heph on github.
* I am heph (https://keybase.io/heph) on keybase.
* I have a public key ASCr40PeHVymBfKyLcK5V_7j42sjUGTFIe8pAMYhaMkSYAo
To claim this, I am signing this object:
@heph
heph / ohai-consul.rb
Created September 27, 2014 02:51
consul ohai plugin (only supports kv lookups at the moment)
require 'net/http'
require 'uri'
require 'base64'
require 'json'
Ohai.plugin(:Consul) do
provides 'consul'
##
# Insert a value into a hash with a '/' delimited path
<VirtualHost _default_:80>
DocumentRoot /opt/deck/html
ProxyPass "/gate" "http://localhost:8084" retry=0
ProxyPassReverse "/gate" "http://localhost:8084"
ProxyPass "/rosco" "http://localhost:8087" retry=0
ProxyPassReverse "/rosco" "http://localhost:8087"
<Directory "/opt/deck/html/">
# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf
Listen 80
<IfModule ssl_module>
Listen 443
</IfModule>
services:
deck:
host: spinnaker.mydomain.com
baseUrl: ${services.default.protocol}://${services.deck.host}
gateUrl: ${services.deck.baseUrl}/gate
bakeryUrl: ${services.deck.baseUrl}/rosco
@heph
heph / task_loader.sh
Created January 19, 2018 21:18
Bash - load and execute functions matching a pattern from include files Raw
for file in $(find ./tasks -type f -name '*.sh' | sort -n); do
current_functions="$(declare -F)"
echo "Sourcing task file: ${file}"
# shellcheck source=/dev/null
source "$file"
new_functions="$(diff <(echo "$current_functions") <($(declare -F))) | awk '$NF ~ /.*::main/ {print $NF}')" || true
for main in "$new_functions"; do
log debug "Executing function ${main} from ${file}:"
$main
done
@heph
heph / chef_hostsfile.sh
Created September 2, 2018 00:11
Write chef node names and public ip addresses to /etc/hosts
#!/bin/bash
set -euo pipefail
HEADER='# All lines below managed by chef_hostfile.sh'
backup_hostsfile() {
sudo cp /etc/hosts{,.$(date +%s)}
}