Skip to content

Instantly share code, notes, and snippets.

@sathishvj
sathishvj / gist:f7e1c28d3ad7d24e8d80
Created May 15, 2015 10:05
bash function to ssh into a server with a matching name in /etc/hosts
# 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`
@sathishvj
sathishvj / gist:7586b3d51d39ab5b7201
Created May 19, 2015 14:36
Rename file or dir by appending current timestamp
# 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=$?
@sathishvj
sathishvj / gist:ab63eb888b1354056073
Created May 19, 2015 14:44
scp a file to a known location on servers based on a part entry from /etc/hosts
# 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`
import (
"archive/zip"
"bytes"
"fmt"
"io/ioutil"
"path"
)
func zipfiles(zippath string, files []string) error {
@sathishvj
sathishvj / prof.bash
Created August 1, 2015 17:19
change profile/colors from the command line on iTerm2 on Mac OSX
# 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=""
@sathishvj
sathishvj / countDigitsIn.go
Created August 15, 2015 09:58
Count Digits in a String
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++
}
}
@sathishvj
sathishvj / main.go
Last active December 29, 2016 08:24
Custom json decoding to check for error or other data
// 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"
)
@sathishvj
sathishvj / script.bash
Created December 29, 2016 09:52
bash function to set gopath automatically if you are already under a src dir
# 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"
@sathishvj
sathishvj / main.go
Last active January 3, 2017 08:39
godo configuration for automatic `ng build --aot` on file change
// 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)
@sathishvj
sathishvj / main.go
Created January 3, 2017 11:51
godo for go web server project
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`