Skip to content

Instantly share code, notes, and snippets.

View sarnobat's full-sized avatar

sarnobat

View GitHub Profile
## 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
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
while read line
do
echo "$line"
done < "${1:-/dev/stdin}"
@sarnobat
sarnobat / .bashrc.keys.sh
Last active September 25, 2017 20:55
Key binding equivalents between Bash and Zsh
# 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 September 19, 2017 21:32
MAC OS X - install these
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 September 19, 2017 22:58
Ubuntu - install these
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 September 19, 2017 21:22
Cygwin - install these
# From Wizard
Admin
cron
Archive
p7zip
rsnapshot
zip
Devel
git
@sarnobat
sarnobat / .bashrc.prompt
Last active August 30, 2017 23:10
PROMPT
# bash
# zsh
@sarnobat
sarnobat / CommonsCLI.java
Last active September 19, 2017 21:37
java command line options
import org.apache.commons.cli.*;
/** TODO: which maven artifact version do we need? */
public class CommandLineOptionsExample {
public static void main(String[] args) {
String port;
_parseOptions: {
Options options = new Options()
@sarnobat
sarnobat / index.html
Last active August 30, 2017 22:50
jQuery call REST service
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
$.getJSON("http://localhost:9099/helloworld/json?param1=" + encodeURIComponent(document.getElementById("urls").innerHTML),function(result){
$.each(result, function(i, field){
$("#items").append(i + " " + field + " ");