This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this worked for me on the Mac's shell | |
# to search for a string in hosts file | |
function ho() { | |
cat /etc/hosts | grep $1 | |
} | |
# ssh into a server if there is a single entry that matches. Or otherwise list names that match. | |
function hoc() { | |
count=`cat /etc/hosts | grep $1 | wc -l` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# move a file/folder to its name suffixed by the current timestamp | |
function mvdate() { | |
if [ ! -f "$1" -a ! -d "$1" ] | |
then | |
echo "Error! Given file/folder $1 does not exist! Exiting" | |
return 1 | |
fi | |
mv "$1" "$1_$(date +%Y%m%d%H%M%S)" | |
OUT=$? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# function to scp a file to the /home/ec2-user/transfers dir | |
function scpxfer() { | |
file="$1" | |
if [ ! -f "$file" ]; then | |
echo "Error! Given file $file does not exist! Exiting" | |
return 1 | |
fi | |
sshSrvr="$2" | |
count=`cat /etc/hosts | grep $sshSrvr | wc -l` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"archive/zip" | |
"bytes" | |
"fmt" | |
"io/ioutil" | |
"path" | |
) | |
func zipfiles(zippath string, files []string) error { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# function to change the profile on iTerm2. Finds the first profile that matches the partial string and assigns it. | |
# usage: prof jacki -> will set profile JackieBrown in this example | |
# usage: prof red -> will set profile RedSands in this example | |
function prof() { | |
# you have to add these profiles in your iTerm preferences. Create new profiles with the colors you like and add the profile names to the list here | |
avlblProfiles=( "Default" "Espresso" "Mac OSX Term" "JackieBrown" "Urple" "SeaShells" "RedSands" "Sundried" ) | |
profileName="" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func countDigitsIn(s string) int { | |
if len(s) == 0 { | |
return 0 | |
} | |
digitsCount := 0 | |
for _, v:=range s { | |
if v=='0' || v=='1' || v=='2' || v=='3' || v=='4' || v=='5' || v=='6' || v=='7' || v=='8' || v=='9' { | |
digitsCount++ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// play link: https://play.golang.org/p/xf43Ta309p | |
// golan-nuts ref: https://groups.google.com/forum/?fromgroups=#!topic/golang-nuts/gg4T4jMuz0U | |
package main | |
import ( | |
"encoding/json" | |
"errors" | |
"fmt" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# often times I find myself doing a `go build` and then realizing that this project has a different GOPATH | |
# I call the below bash function I am in the go code dir. | |
# It will get the pwd and set the GOPATH automatically to the folder in which there is a "/src/" | |
# depending on whether you are on linux or mac, you can simplify the sed to use the extended options -r or -e respectively, but I've kept it universal for now | |
function setgopath() { | |
pwd=`pwd` | |
newGoPath=`echo $pwd | sed 's/\(.*\)\/src\/.*/\1/'` | |
if [ -z $newGoPath ]; then | |
echo "GOPATH not changed" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// my angular2 project is served from the dist directory (configured in angular-cli.json). | |
// when there are changes to the code, I use the below configuration with godo (https://github.com/go-godo/godo) | |
// to automatically build using `ng build --aot | |
// Put this file as <project>/Gododir/main.go within your web project directory. So, the Gododir and src are at the same level. Then run `godo` from the <project> directory≥. | |
package main | |
import do "gopkg.in/godo.v2" | |
func tasks(p *do.Project) { | |
p.Task("default", do.S{"ng-build"}, nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import do "gopkg.in/godo.v2" | |
func tasks(p *do.Project) { | |
// put your go path configuration as appropriate | |
// do.Env = `GOPATH=.vendor::$GOPATH` | |
// do.Env = `GOPATH=$GOPATH` | |
// do.Env = `GOPATH=/Users/me/projects/abcd/dev/gocode::/Users/me/go/gopath` |
OlderNewer