This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
number=$RANDOM | |
let "number %= 10" | |
if [[ $number -gt 8 ]] | |
then | |
echo "Success" | |
exit 0 | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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