Skip to content

Instantly share code, notes, and snippets.

View nickcarenza's full-sized avatar

Nick Carenza nickcarenza

View GitHub Profile
@nickcarenza
nickcarenza / prompt.sh
Created February 25, 2015 18:28
Messing with the shell prompt
bold=`tput bold`
normal=`tput sgr0`
prompt_user() {
echo "${bold}\u${normal} in ${bold}\W${normal} >> "
}
prompt_vagrant() {
# Find closest .vagrant folder or exit
# @TODO
@nickcarenza
nickcarenza / nodejs.sh
Created February 25, 2015 18:27
Useful nodejs shell script
source $(brew --prefix nvm)/nvm.sh
export NVM_DIR=~/.nvm
nvm use default &> /dev/null
@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 )"
@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 / 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 / aliases.sh
Created February 25, 2015 18:25
Useful shell aliases
alias ll='ls -lG'
alias l='ls'
@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 / 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 / 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 / focused-sort.go
Created November 22, 2014 19:54
Golang FocusedSort with known, unsorted index
package _
import (
"fmt"
"log"
"math/rand"
"sort"
"time"
)