Skip to content

Instantly share code, notes, and snippets.

View nickcarenza's full-sized avatar

Nick Carenza nickcarenza

View GitHub Profile
@nickcarenza
nickcarenza / ZSH Vagrant Completion
Last active August 29, 2015 14:02
Provides tab completion of vagrant IDs and displays global-status report
#compdef vagrant
local context state line
typeset -A opt_args
local vagrant_status vagrant_ids
vagrant_status=$(vagrant global-status | head -5)
vagrant_ids=$(echo $vagrant_status | grep -oE '^[0-9a-z]+' | grep '[0-9]')
@nickcarenza
nickcarenza / hhvm-composer.sls
Last active August 29, 2015 14:06
Saltstack - HHVM - Composer State
# Check for latest version based on environment
pull-latest-repo:
git.latest:
- name: git@github.com:you/your-app.git
- rev: {{ salt['pillar.get']('environment') }}
- target: /sites/your-app
- always_fetch: True
# If the previous state made changes, run composer install with environment-specific options
/path/to/repository:
@nickcarenza
nickcarenza / focused-sort.go
Created November 22, 2014 19:54
Golang FocusedSort with known, unsorted index
package _
import (
"fmt"
"log"
"math/rand"
"sort"
"time"
)
@nickcarenza
nickcarenza / detectTypeSetInt.go
Created February 10, 2015 18:12
Using reflection to detect if type is slice and set property
package main
import(
"fmt"
"reflect"
)
type X struct {
Prop int
}
@nickcarenza
nickcarenza / middleware.go
Created February 15, 2015 20:09
Crude HTTP Middleware Implementation
package main
import(
"net/http"
"net/http/httptest"
"log"
"io/ioutil"
"fmt"
)
@nickcarenza
nickcarenza / lazy_evaluation.go
Created February 20, 2015 18:35
Golang Lazy Evaluation
package main
import (
"time"
)
type LazyInt chan func() int
// Can't use pointer receiver: invalid operation: l <- (func literal) (send to non-chan type *LazyInt)
func (l LazyInt) Future(i int) {
@nickcarenza
nickcarenza / aliases.sh
Created February 25, 2015 18:25
Useful shell aliases
alias ll='ls -lG'
alias l='ls'
@nickcarenza
nickcarenza / docker.sh
Created February 25, 2015 18:25
Useful docker aliases
# These don't seem to actually export the environment variables
# boot2docker shellinit &> /dev/null
# export DOCKER_CERT_PATH=/Users/nick/.boot2docker/certs/boot2docker-vm
# export DOCKER_TLS_VERIFY=1
alias docker-kill-all="docker kill \$(docker ps -q)"
alias docker-rm-all="docker rm \$(docker ps -qa)"
# alias b2d-start="boot2docker start && export DOCKER_HOST=tcp://:2375"
@nickcarenza
nickcarenza / functions.sh
Created February 25, 2015 18:26
Useful shell functions
dotil() {
echo "Trying '${@}'"
until $@; do :; done
}
inTmux() {
if ! { [ "$TERM" = "screen" ] && [ -n "$TMUX" ]; } then return 1; fi
}
pane() {
@nickcarenza
nickcarenza / main.sh
Created February 25, 2015 18:26
Shell script to load other shell scripts
# Get current directory
# http://stackoverflow.com/a/246128
SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"