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
#!/bin/bash | |
TMPFILE="/tmp/.bashweb.$(whoami)" | |
PORT=8080 | |
start(){ | |
[[ -n "$1" ]] && PORT="$1"; TMPFILE="$TMPFILE.$PORT"; [[ ! -p $TMPFILE ]] && mkfifo "$TMPFILE" | |
while [[ -p "$TMPFILE" ]]; do | |
[[ -f "$TMPFILE.log" ]] && tail -n5 $TMPFILE.log | |
{ read line<$TMPFILE; | |
logmsg(){ cat - | while read l; do echo "[$(date)] $1> $l" >> $TMPFILE.log; [[ ! "$1" == "in" ]] && echo "$l"; done |
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
echo -e '<b>${title}</b>\n$(ls -la)' > foo.html | |
export title=FOOOOO; | |
cat foo.html | sed 's/"/\\\"/g;s/.*/echo "&"/e' |
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
[[ ${#3} == 0 ]] && echo "Usage: [PASSWORD=""] $0 <dbname> <username> <query>" && exit 11 | |
db="$1" | |
user="$2" | |
query="$3" | |
# execute query, quote quotes, and delimit with "," | |
mysql -u"$user" -p"$PASSWORD" "$db" -B -e "set names 'utf8'; $query" | \ | |
sed -e 's/"/\\"/g' | | |
sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' | sed ':a;N;s/\r//g;s/\\n//g' |
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
# bash colors snippet (Usage: printf "$C_GREEN this is green $C_NORMAL this is normal") | |
C_NORMAL="\\033[0;0m" | |
C_BOLD="\E[1;37;40m" | |
C_BRIGHT="\E[1;33;40m" | |
C_BLACK="\\033[0;30m" | |
C_RED="\\033[0;31m" | |
C_GREEN="\\033[0;32m" | |
C_BROWN="\\033[0;33m" | |
C_BLUE="\\033[0;34m" | |
C_PURPLE="\\033[0;35m" |
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
# quickndirty csv column grep function (for easily selecting columns from csv e.g.) | |
# | |
# Usage: cat my.csv | csv column 2 | |
# | |
# csv is a handy database-format, its editable with an texteditor, importable/exportable by | |
# tech and end-users (mysql/excel/php etc) | |
# | |
column(){ | |
cat - | sed 's/,,,/###/g' | sed 's/,,/##/g' | sed 's/,/#/g' | cut -f$1 -d"#" | sed 's/"//g' |
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
#!/bin/bash | |
# Simple drumloopslicer using purely bash, sox and vamp plugin on the console | |
# @dependancy bc vamp-simple-host | |
slice(){ | |
input="$1" | |
which bc || { echo "please install 'bc' from your package manager"; exit 1; } | |
which vamp-simple-host || { echo "please install 'vamp-examples' from your package manager"; exit 1; } | |
hits="$(vamp-simple-host vamp-example-plugins:percussiononsets "$input" 2>/dev/null | grep -E " [0-9].*" | sed 's/ //g;s/://g')"; | |
declare -a hitArray; |
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
# makes a audiofile to loop itself (seamless by using a crossfade trick) (needs sox audio utilities) | |
# @dependancy sox | |
# Usage: ./loopcrossfade <input.wav> <faderatio> [outputdir] | |
# | |
loopcrossfade(){ | |
input="$1"; faderatio="$2"; outputdir="$3"; tmpinput="/tmp/$(basename "$input").loopcrossfade.wav" | |
[[ ! -f "$input" ]] && echo "cannot find $1" && exit 1 | |
valid=$(echo "$faderatio > 1.99" | bc -l ); | |
(( $valid == 0 )) && echo "faderatio should be 2.0 or bigger" && exit 1 |
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
#!/bin/bash | |
# parse xpath on the commandline (when php is installed) | |
# example usage : xpath /tmp/test.xml /catalog/book[1]/title | |
# example output: XML Developer's Guide | |
# | |
# given that /tmp/test.xml looks like: | |
# <?xml version="1.0"?> | |
# <catalog> | |
# <book id="bk101"> | |
# <author>Gambardella, Matthew</author> |
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
# forces/limits shellscript to only one 1 process, to prevent running twice, aka bash singleton | |
# this function exits when no parameter is passed, and another instance of the script is detected | |
# @dependancies ps grep tr sed | |
# @param string (pass --kill to kill previous process) | |
# usage: change 'foo' and 'bar' to the strings which occur in your process name | |
function singleprocess(){ | |
PID=$$; # current process | |
if [[ "$1" == "--kill" ]]; then | |
PID="$(ps aux | grep foo | grep bar | tr -s [:space:] | cut -d' ' -f2 )" |
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
# simple event / exception handling in bash | |
# | |
# onFoo(){ | |
# echo "onFoo() called width arg $1!" | |
# } | |
# | |
# onExit(){ | |
# echo "onExit called!" | |
# } | |
# |