Skip to content

Instantly share code, notes, and snippets.

@belo82
belo82 / run.sh
Last active June 18, 2017 15:57
Send file to localhost:8000 in infinite loop, display number of iterations and progress bar for each iteration.
time(i=0; while true; do i=`expr $i + 1`; echo "iteration $i"; pv -p -t -e -r -b -L 10m file.raw | nc localhost 8000; if ! [[ -f "run.txt" ]]; then echo "exit"; break; fi; sleep 1; done)
@belo82
belo82 / format_json.sh
Created July 7, 2015 15:33
Format JSON file on command line
cat file.json | python -m json.tool > formatted_file.json
@belo82
belo82 / ssh_tunnel.sh
Last active November 30, 2017 22:52
SSH tunnel from local port 9200 to remote port 9200 (-f: run in background -N: don't execute command in remote system)
ssh -f -L 9201:localhost:9200 <username>@<host> -N
# To kill tunnel running in background run:
ps aux | grep 9201
kill <pid>
@belo82
belo82 / print-nth-line.sh
Created November 26, 2014 09:17
Prints n-th line from a file
sed 'NUMq;d' file
@belo82
belo82 / unzip.sh
Last active August 29, 2015 14:10
Unzips all *.zip files in current directory to separate directory with name of an zip file
ls -1 *.zip | awk -F'.zip' '{print "unzip " $0 " -d " $1}' | sh
@belo82
belo82 / es_cheatseet.json
Last active August 29, 2015 13:57
Elasticsearch API cheatsheet
# find documents which don't contain field 'non_existing_field'
POST /twitter/tweet/_search
{
"query": {
"bool": {
"must": {
"match_all": {}
},
"must_not": {
"prefix": {
@belo82
belo82 / git_rename.sh
Created October 15, 2013 17:02
Add extension to all files using Git.
for files in *.java; do git mv "$files" "$files.orig"; done
@belo82
belo82 / strip_ext.sh
Created October 15, 2013 16:52
Strip file extension
rename 's/\.orig$//' *.orig
@belo82
belo82 / split_archive.sh
Created September 29, 2013 10:38
Zip and Split files on Mac OS X using console
zip -r -s 3m <zip_file_name>.zip <files_to_zip>.war
@belo82
belo82 / renam_add_extension
Created September 17, 2013 15:00
Add an extension .bak to all JAR files in the current directory
rename -n 's/(.*)/$1.bak/' *.jar