Skip to content

Instantly share code, notes, and snippets.

@sathishvj
sathishvj / flatten-dir.go
Last active August 31, 2018 10:35
Flatten a directory - copy all files into one directory with directory named prefixed to files
package main
import (
"flag"
"fmt"
"io"
"log"
"os"
"path/filepath"
"strings"
@sathishvj
sathishvj / up.sh
Created August 24, 2018 10:16
Bash script to go back up to any dir in path
# A very useful (and very much used) bash script I found recently to go back up to any dir in the current path. Supports autocomplete also which is awesome.
# go back up to a directory - https://unix.stackexchange.com/questions/14303/bash-cd-up-until-in-certain-folder
function up()
{
if [ -z "$1" ]; then
return
fi
local upto=$1
cd "${PWD/\/$upto\/*//$upto}"
@sathishvj
sathishvj / project-git-repos-status.sh
Created August 15, 2018 14:15
check the git status of many repos together
#!/bin/bash
# a script to check the git status of many repos together
# this one is customized to work with a given list of git repos rather than all repos under a specified folder
# based on: https://gist.github.com/aroberts/3018100
# You can add something like this to your .profile/.bashrc to make it convenient to call this from anywhere
# alias allgit='path-to-project/dev-setup/project-git-repos-status.sh'
red="\033[00;31m"
@sathishvj
sathishvj / surround_selection.vimrc
Last active August 13, 2018 08:54
Vim: Surround selected text with parentheses, quotes, braces, brackets, single quotes
" surround selection with parentheses, quotes, braces, brackets
xnoremap <leader>( xi ()<Esc>P
xnoremap <leader>" xi ""<Esc>P
xnoremap <leader>{ xi {}<Esc>P
xnoremap <leader>' xi ''<Esc>P
xnoremap <leader>[ xi []<Esc>P
@sathishvj
sathishvj / cdd.sh
Last active August 21, 2018 10:29
bash script to go into a sub directory that matches a pattern
# go into dir with a specific file in the subdirectory
function cdf() {
f=$(dirname $(find . -iname "*$1*" -type f -print -quit 2>/dev/null | head -1) 2>/dev/null)
if [ -z "$f" ]; then
echo #'not found'
else
#echo "found in:" $f
cd "$f"
fi
}
@sathishvj
sathishvj / gist:87ac391577727fcd3add3da570db39da
Last active February 9, 2018 04:15
Toggle Mac/OSX wifi from command line
# add this to your .profile or .bashrc or other.
alias wifitoggle='echo -n "Previous status: " && networksetup -getairportpower en0 | grep "Wi-Fi"; networksetup -getairportpower en0 | grep -q "On" && networksetup -setairportpower en0 off || networksetup -setairportpower en0 on; echo -n "New status: " && networksetup -getairportpower en0 | grep "Wi-Fi"; '
@sathishvj
sathishvj / main.go
Created April 26, 2017 14:06
Custom json decoding for changing one member data field
package main
import (
"fmt"
"encoding/json"
)
var d1 = []byte(`
{
@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`
@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 / 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"