View bank_account_validation.py
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 |
View lol.py
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 |
View bash_colors.sh
# 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 |
View test.sh
#!/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 |
View gist:d9158f027b294f18cca6
with open('even_numbers.txt', 'w') as f: | |
for number in (n for n in range(10**100) if n%2 == 0): | |
f.write('{}\n'.format(number)) |
View SSL cert generator.sh
#!/bin/bash | |
# CONFIGURATION | |
openssl_config_file=$(openssl ca 2>&1 | grep "Using configuration from" | sed 's/Using configuration from //g') | |
################################################################################ | |
txtgrn='\e[0;32m' | |
txtred='\e[0;31m' | |
txtrst='\e[0m' | |
config_tempfile=$(mktemp --suffix openssl) |
View generator.py
def split_sum_into_parts(limit=1500, min_parts=2, max_parts=5): | |
sample = sorted([0, limit] + random.sample(range(limit), random.randint(min_parts-1, max_parts-1))) | |
return [sample[i+1] - item for i, item in enumerate(sample) if i+1 < len(sample)] |
View generator.py
def split_sum_into_parts(limit=1500, min_parts=2, max_parts=5): | |
sample = sorted([0, limit] + random.sample(range(limit), random.randint(min_parts-1, max_parts-1))) | |
return [sample[i+1] - item for i, item in enumerate(sample) if i+1 < len(sample)] |
View random_crash.sh
#!/bin/bash | |
number=$RANDOM | |
let "number %= 10" | |
if [[ $number -gt 8 ]] | |
then | |
echo "Success" | |
exit 0 | |
fi |
View spayd.py
def _convert_to_iban(self, account): | |
""" | |
Convert czech account number to IBAN | |
""" | |
acc = self.RE_ACCOUNT.match(account) | |
iban = 'CZ00{b}{ba:0>6}{a:0>10}'.format( | |
ba=acc.group('ba') or 0, | |
a=acc.group('a'), | |
b=acc.group('b'), | |
) |
NewerOlder