Skip to content

Instantly share code, notes, and snippets.

sarnobat

Block or report user

Report or block sarnobat

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@sarnobat
sarnobat / url_param.js
Last active Sep 30, 2017
Get and Set URL parameter in javascript
View url_param.js
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/purl/2.3.1/purl.js"></script>
<script>
// Get the URL parameter
var argName = $.url().param('argName');
// Set the URL parameter
if (argName == null) {
history.pushState(null, null, '/?argName=defaultValue');
}
@sarnobat
sarnobat / bindkey_multiline.zsh
Last active Sep 27, 2017
ZSH key binding that spans multiple lines
View bindkey_multiline.zsh
bindkey -s "^[T" 'sh <<EOF ^[^M'\
'^[^M'\
' # Run the main test.^[^M'\
' cd ~/work/src/tests/ && JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home mvn --quiet test --settings ~/sarnobat.git/mac/.m2/settings.xml -Dsurefire.useFile=false -Dsurefire.printSummary=false -Dtier=devint -Dtest="*#*" | grcat ~/conf.tail ; popd; osascript -e '\''tell app \"System Events\" to display dialog \"Tests finished\"'\'' ^[^M'\
'^[^M'\
'EOF'\
'^[[A^[[A^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D^[[D'
View variable_is_set.sh
## default value
URL=${1:-"https://www.amazon.com/War-That-Made-America-French/dp/B000E1MXZ0"}
## Error message and exit with non zero status
${1:?"You didn't pass a value, exiting"}
## No need for this (even Bourne Shell has shorthands)
if [ -n "$1" ];
then
View file_exists.sh
test -e "$1" || echo "[DEBUG] Does not exist: $1"
# Do we ever need if-else syntax? Probably not but here it is anyway:
if [ -e "$1" ]
then
echo "ok"
else
echo "nok"
fi
View Bourne shell iterate over stdin.sh
while read line
do
echo "$line"
done < "${1:-/dev/stdin}"
@sarnobat
sarnobat / .bashrc.keys.sh
Last active Sep 25, 2017
Key binding equivalents between Bash and Zsh
View .bashrc.keys.sh
# bash
bind '"\el":"ls -lrtha --color=always\n"'
bind '"\ef":"find $PWD -type f -iname \"**\""'
bind '"\eg":"| xargs grep --delimiter \"\\n\" grep --color=always -ni \"*\""'
bind '"\e[1;3D": backward-word'
bind '"\e[1;3C": forward-word'
bind '"\e[1;3A": history-search-backward'
bind '"\e[1;3B": history-search-forward'
bind '"\ep":"pwd\n"'
bind '"\e4"':yank-last-arg
@sarnobat
sarnobat / mac_install.sh
Last active Sep 19, 2017
MAC OS X - install these
View mac_install.sh
brew install coreutils
brew install findutils
brew install wget
brew install netcat --verbose
brew install ssh-copy-id
@sarnobat
sarnobat / ubuntu_install.sh
Last active Sep 19, 2017
Ubuntu - install these
View ubuntu_install.sh
sudo apt-get install -y zsh
chsh $(whoami) -s /usr/bin/zsh
sudo apt-get install -y git
sudo apt-get remove -y vim
sudo apt-get install -y vim
sudo apt-get install -y openjdk-7-jdk
#sudo apt-get install -y default-jdk
@sarnobat
sarnobat / cygwin_install.txt
Last active Sep 19, 2017
Cygwin - install these
View cygwin_install.txt
# From Wizard
Admin
cron
Archive
p7zip
rsnapshot
zip
Devel
git
You can’t perform that action at this time.