This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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` |
NewerOlder