Skip to content

Instantly share code, notes, and snippets.

View gwpl's full-sized avatar

Grzegorz Wierzowiecki gwpl

  • Europe - usually: Zürich, Warsaw or Berlin
View GitHub Profile
@gwpl
gwpl / glabels-3-fetch_and_print.sh
Created October 12, 2016 20:42
glabels-3-fetch_and_print.sh # wrapper around https://github.com/barcode-utils/glabels-3-templates fetching from given google_spreadsheets sheet
#!/bin/bash
# Usage:
# optionally you can provide .csv file as parameter
# if GLABELS3TEMPLATESDIR= is pointing to directory with glabels-3-templates, then it's copied from there
orig_dir="$PWD"
tmpdir="$(mktemp -d)"
if [ -r "$1" ]; then
@gwpl
gwpl / ubuntu_purge_non_active_kernels.sh
Created November 22, 2016 20:58
/boot full on ubutu! Use last line or full script! Thanks: http://askubuntu.com/a/90219/31300 !
#!/bin/bash
echo Current active: "$(uname -r)"
echo Remove rest:
set -x
sudo apt-get purge $(dpkg -l linux-{image,headers}-"[0-9]*" | awk '/ii/{print $2}' | grep -ve "$(uname -r | sed -r 's/-[a-z]+//')")
#!/bin/bash
# based on tutorial :
# "How To: Use Your Raspberry Pi as a Proxy for Google Chrome" https://mpacewriting.wordpress.com/2014/01/09/how-to-use-your-raspberry-pi-as-a-proxy-for-google-chrome/
# Notes in : https://docs.google.com/document/d/1NZ1o6HiyqVCgAiScDd0SDJIGR-aon13e6ojh9AjwOa8
select cfg in no_proxy via_p; do break; done
case "$cfg" in
no_proxy)
exec chromium --user-data-dir=/home/${user?}/.config/chromium_p
;;
via_p)
@gwpl
gwpl / boxes.csv
Last active January 31, 2017 15:51
csvsql_query.sh is example usage of `csvsql` direct sql execution on `.csv` files examples, inspired by https://source.opennews.org/en-US/articles/eleven-awesome-things-you-can-do-csvkit/
id name description
33 Music CDs Box with "Music CDs"
44 Movies "Box" Box with Movies
55 Toys Toys
@gwpl
gwpl / csvsql_inventory_join.output.csv
Created January 31, 2017 16:17
csvsql_inventory_join.sh example of csvsql sql query joining scanned barcodes with bardcodes database into more meaningful output
id name
23 Toy T
44 Movie M2
68 Music CD 2
@gwpl
gwpl / git-latexdiff
Created May 10, 2017 13:16
git-latexdiff # how to configure latexdiff in git
#!/bin/bash
# http://tex.stackexchange.com/a/1417/7128
TMPDIR=$(mktemp -d /tmp/git-latexdiff.XXXXXX)
latexdiff "$1" "$2" > $TMPDIR/diff.tex
pdflatex -interaction nonstopmode -output-directory $TMPDIR $TMPDIR/diff.tex
okular $TMPDIR/diff.pdf
rm -rf $TMPDIR
# Add to ~/.gitconfig
@gwpl
gwpl / depend_on_hour.sh
Last active May 21, 2017 22:27
Handy snippet to depending behaviour on hour in bash
echo 'Current hour'
hour=$(date +%H);
if [ $hour -gt 9 -a $hour -lt 23 ]; then echo -n '*'; else echo -n '#'; fi; echo ' '$hour;
echo 'Test around the clock:'
for hour in {0..23} {0..23}; do
if [ $hour -gt 9 -a $hour -lt 23 ]; then echo -n '*'; else echo -n '#'; fi; echo ' '$hour;
done
echo 'If you need to depend on UTC, just add `-u` flag to `date` command'
@gwpl
gwpl / gen_basic_files_metadata.csv.sh
Last active May 25, 2017 14:12
Generate .csv formatted basic metadata, fast to obtain, but allowing heuristics for syncing files or initial eastimation of backup/sync coverage. ( And yes, I know that this find command will not properly encode filenames containing quotes according to csv standard )
#!/bin/bash
# Generate .csv formatted basic metadata, fast to obtain, but allowing heuristics for syncing files or initial eastimation of backup/sync coverage.
fullpath="${1:-$PWD}"
dest="${2:-"$fullpath"/basic_files_metadata.csv.gz}"
hostname="${3:-"$(hostname)"}"
echo "find \"${fullpath}\" -type f -exec stat --format=\"%i,%Y,%s,%m,%n\" \"{}\" \\; > \"${dest}\""
echo "Progress in lines generated:"
(echo "inode,modification_ts,size,hostname,mount,path";
find "${fullpath}" -type f -exec stat --format="%i,%Y,%s,${hostname},%m,%n" "{}" \;
@gwpl
gwpl / .bashrc PS1 colorful prompt
Created May 27, 2017 18:27
.bashrc PS1 colorful prompt # playing with tput to make variables using it... ("SEA" color is unfortunate, I should find better name for this color)
alias ls='ls --color=auto'
#export PS1='[\u@\h \W]\$ '
#export PS1='\W\$ '
#export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$'
#export PS1='\[\033[01;34m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]\$'
#export PS1='\[\033[01;34m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[01;37m\]\$\[\033[00m\]'
PROMPT_RED="\[$(tput setaf 1)\]"
PROMPT_GREEN="\[$(tput setaf 2)\]"
PROMPT_ORANGE="\[$(tput setaf 3)\]"
PROMPT_NAVY="\[$(tput setaf 4)\]"
@gwpl
gwpl / bash_test_rsync_options.sh
Last active August 27, 2017 15:19
./bash_test_rsync_options.sh # testing different rsync options and how outputs look like # TODO: extend with xattr test case and my favourite options combo 'rsync -aAXHzvR --progress' (# tweeted: https://twitter.com/GWierzowiecki/status/901825874416295936 )
#!/bin/bash
tmpdir="$(mktemp -d)"
function cleanup {
echo '@ cleanup {'
set -x
rm -r "$tmpdir"
set +x
echo '@ } end of cleanup'
}