Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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=""
import (
"archive/zip"
"bytes"
"fmt"
"io/ioutil"
"path"
)
func zipfiles(zippath string, files []string) error {
@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`
@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: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`