Skip to content

Instantly share code, notes, and snippets.

View ViktorStiskala's full-sized avatar

Viktor Stískala ViktorStiskala

View GitHub Profile
@ViktorStiskala
ViktorStiskala / test.sh
Created June 29, 2015 11:19
Bash catch exception
#!/bin/bash
set -e
err_report() {
ERR=$?
echo "$1 failed on line $2 ('$3') with error code $ERR" 1>&2
exit $ERR
}
trap 'err_report "$BASH_SOURCE" "$LINENO" "$BASH_COMMAND"' ERR
echo "l" | grep f
@ViktorStiskala
ViktorStiskala / bash_colors.sh
Created July 20, 2015 09:07
Bash color variables
# source: https://wiki.archlinux.org/index.php/Color_Bash_Prompt
txtblk='\e[0;30m' # Black - Regular
txtred='\e[0;31m' # Red
txtgrn='\e[0;32m' # Green
txtylw='\e[0;33m' # Yellow
txtblu='\e[0;34m' # Blue
txtpur='\e[0;35m' # Purple
txtcyn='\e[0;36m' # Cyan
txtwht='\e[0;37m' # White
def note_error(self, *msg):
if self.strict:
raise PermError(*msg)
# if lax mode, note error and continue
if not self.perm_error:
try:
raise PermError(*msg)
except PermError as x:
# FIXME: keep a list of errors for even friendlier diagnostics.
self.perm_error = x
def validate_account_number(value):
checksum = sum(int(value[i]) * (8-i) for i in range(7)) % 11
last_digit = int(value[-1])
if checksum in [0, 10]:
c = 1
elif checksum == 1:
c = 0
else:
c = 11 - checksum