diff --git a/bin/ascii b/bin/ascii new file mode 100755 index 0000000..af8aa8e --- /dev/null +++ b/bin/ascii @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 + +import sys +import os.path + +SEP = '='*10 + +decode = False +tohex = False +if os.path.basename(sys.argv[0]) == 'unascii': + decode = True +if os.path.basename(sys.argv[0]) == 'asciihex': + tohex = True + +if len(sys.argv) < 2 or sys.argv[1] == '-': + text = sys.stdin.readlines() +else: + text = sys.argv[1:] + +for i in range(len(text)): + if decode: + line = text[i] + if line.strip() == SEP: + pass + else: + print(chr(int(line)), end='') + else: + for char in text[i]: + if tohex: + print('0x' + format(ord(char), '02x')) + else: + print(ord(char)) + if i != len(text) - 1: + print(SEP) diff --git a/bin/asciihex b/bin/asciihex new file mode 120000 index 0000000..5c0d149 --- /dev/null +++ b/bin/asciihex @@ -0,0 +1 @@ +ascii \ No newline at end of file diff --git a/bin/days-until b/bin/days-until new file mode 100755 index 0000000..a36795d --- /dev/null +++ b/bin/days-until @@ -0,0 +1,43 @@ +#!/usr/bin/env python3 + +formats = ( + '%Y-%m-%d', + '%d.%m.%Y', + '%Y-%m', + '%d.%m') + +import datetime +import sys + +for format in formats: + try: + day = datetime.datetime.strptime(sys.argv[1], format).date() + except ValueError: + continue + diff = (day - datetime.datetime.now().date()).days + print(str(diff) + " days") + print() + if abs(diff) > 14: + print("{} weeks and {} days".format( + diff // 7, + diff % 7)) + if abs(diff) > 365: + print("{} years, {} weeks and {} days".format( + diff // 365, + (diff % 365) // 7, + (diff % 365 % 7))) + print() + for i in range(abs(diff) // 7): + print("X X X X X X X") + if (i+1) % 4 == 0: + print() + for _ in range(abs(diff) % 7): + print("X ", end="") + if abs(diff) % 7 != 0: + print() + + sys.exit(0) + +print("No format matched:") +print() +sys.exit(1) diff --git a/bin/git-rewrite-author b/bin/git-rewrite-author new file mode 100755 index 0000000..a7ddfd6 --- /dev/null +++ b/bin/git-rewrite-author @@ -0,0 +1,24 @@ +#!/bin/bash +(( $# != 4 )) && { echo "$0 " >&1 ; exit 1 ; } + +_repo="$1" +_oldmail="$2" +_newauthor="$3" +_newmail="$4" + +cd "$_repo" || exit $? + +git filter-branch --force --commit-filter ' + if [ "$GIT_AUTHOR_EMAIL" = "'"$_oldmail"'" ]; + then + export GIT_AUTHOR_NAME="'"$_newauthor"'"; + export GIT_AUTHOR_EMAIL="'"$_newmail"'"; + git commit-tree -S "$@" + elif [ "$GIT_COMMITTER_EMAIL" = "'"$_oldmail"'" ]; + then + export GIT_COMMITTER_NAME="'"$_newauthor"'"; + export GIT_COMMITTER_EMAIL="'"$_newmail"'"; + git commit-tree -S "$@" + fi' \ + --tag-name-filter cat \ + -- --branches --tags diff --git a/bin/kw b/bin/kw new file mode 100755 index 0000000..685d570 --- /dev/null +++ b/bin/kw @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 + +import datetime +import sys + +formats = ( + '%Y-%m-%d', + '%d.%m.%Y') + +for format in formats: + try: + day = datetime.datetime.strptime(sys.argv[1], format).date() + except ValueError: + continue + print(day.isocalendar()[1]) + sys.exit(0) + +print("no format matched:") +print("\n".join(" {}".format(f) for f in formats)) +sys.exit(1) diff --git a/bin/mousespam b/bin/mousespam new file mode 100755 index 0000000..0b26930 --- /dev/null +++ b/bin/mousespam @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +xdotool click --repeat 1000000000 --delay 20ms 1 diff --git a/bin/mypass b/bin/mypass new file mode 100755 index 0000000..0c20e92 --- /dev/null +++ b/bin/mypass @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 + +import sys +import subprocess +import yaml + +PASS = 'pass' + +def run(args): + return(subprocess.run( + args, + stdin=sys.stdin, + stdout=sys.stdout, + stderr=sys.stderr).returncode) + +def get_stdout(args): + return(subprocess.run( + args, + stdout=subprocess.PIPE).stdout) + +def extract_from_dict(d, k, last=None): + if '.' in k: + k1, k2 = k.split('.', 1) + try: + d1 = d[k1] + return extract_from_dict(d1, k2, last=k1) + except KeyError: + print("\"{}\" was not found in the data".format(k)) + sys.exit(3) + else: + if not isinstance(d, dict): + print("element \"{}\" is not a dictionary".format(last)) + sys.exit(3) + try: + return d[k] + except KeyError: + print("\"{}\" was not found in the data".format(k)) + sys.exit(3) + + +def cmd_get(*args): + if len(args) == 1: + print(get_stdout(['pass', 'show', args[0]]).split(b'\n')[0].decode()) + return 0 + + if len(args) != 2: + print("what do you want to get?") + return 1 + + # get the pass output + out = get_stdout(['pass', 'show', args[0]]) + try: + data = list(yaml.safe_load_all(out))[-1] + except yaml.scanner.ScannerError as e: + print("invalid YAML data: {}".format(str(e))) + return 2 + except IndexError: + print("invalid YAML data: no YAML document found") + return 2 + + if not isinstance(data, dict): + print("invalid YAML data, not a dict") + return 2 + + keydata = extract_from_dict(data, args[1]) + if isinstance(keydata, list) or isinstance(keydata, dict): + print(yaml.safe_dump(keydata, default_flow_style=False).strip()) + else: + print(keydata) + +cmds = ['get'] + +if len(sys.argv) == 1 or sys.argv[1] not in cmds: + sys.exit(run([PASS] + sys.argv[1:])) +else: + sys.exit(globals()['cmd_' + sys.argv[1]](*sys.argv[2:])) diff --git a/bin/nato b/bin/nato new file mode 100755 index 0000000..1611ad3 --- /dev/null +++ b/bin/nato @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 + +import sys + +hash = { + 'A': 'Alpha', + 'B': 'Bravo', + 'C': 'Charlie', + 'D': 'Delta', + 'E': 'Echo', + 'F': 'Foxtrot', + 'G': 'Golf', + 'H': 'Hotel', + 'I': 'India', + 'J': 'Juliett', + 'K': 'Kilo', + 'L': 'Lima', + 'M': 'Mike', + 'N': 'November', + 'O': 'Oscar', + 'P': 'Papa', + 'Q': 'Quebec', + 'R': 'Romeo', + 'S': 'Sierra', + 'T': 'Tango', + 'U': 'Uniform', + 'V': 'Victor', + 'W': 'Whiskey', + 'X': 'Xray', + 'Y': 'Yankee', + 'Z': 'Zulu', + '0': 'Zero', + '1': 'One', + '2': 'Two', + '3': 'Tree', + '4': 'Fower', + '5': 'Fife', + '6': 'Six', + '7': 'Seven', + '8': 'Eight', + '9': 'Niner', + '-': 'Dash', + '.': 'Stop', +} + +if len(sys.argv) < 2 or sys.argv[1] == '-': + text = [line.strip() for line in sys.stdin.readlines()] +else: + text = sys.argv[1:] + +for i in range(len(text)): + for char in text[i].upper(): + if char in hash.keys(): + print(hash[char]) + elif char == ' ': + print() + else: + print(">> " + char) + if i != len(text) - 1: + print() + print("===") + print() diff --git a/bin/pprint b/bin/pprint new file mode 100755 index 0000000..9a658d2 --- /dev/null +++ b/bin/pprint @@ -0,0 +1,6 @@ +#!/usr/bin/env python + +import sys +import pprint + +pprint.pprint(eval(sys.stdin.read())) diff --git a/bin/pw b/bin/pw new file mode 100755 index 0000000..fc773cf --- /dev/null +++ b/bin/pw @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +pwgen -s 25 1 diff --git a/bin/randmac b/bin/randmac new file mode 100755 index 0000000..9e3eb7f --- /dev/null +++ b/bin/randmac @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +_max=${1:-6} +for i in $(seq $_max) ; do + printf '%02X' $[RANDOM%256] + (( $i != $_max )) && printf ':' +done +printf '\n' diff --git a/bin/since b/bin/since new file mode 100755 index 0000000..acfb517 --- /dev/null +++ b/bin/since @@ -0,0 +1,44 @@ +#!/usr/bin/env python3 + +import datetime +import sys + +USAGE="""Usage: {program} PATH_TO_FILE""".format(program=sys.argv[0]) + +def die(message, code=1): + print(message) + sys.exit(code) + +def die_usage(code=1): + die(USAGE, code) + +def read_date_from_file(path): + text = open(path).readline().strip() + try: + time = datetime.datetime.strptime(text, '%Y-%m-%d') + except ValueError as e: + die(e) + return time + +def main(argv): + if len(argv) < 2: + die_usage() + last = read_date_from_file(argv[1]) + now = datetime.datetime.now() + diff = now - last + days = diff.days + #hours = diff.seconds // (60 * 60) + if days == 1: + msg = "1 day" + else: + msg = "{days} days".format(days=days) + + #msg += " " + #if hours == 1: + # msg += "1 hour " + #else: + # msg += "{hours} hours ".format(hours=hours) + + print(msg) + +main(sys.argv) diff --git a/bin/unascii b/bin/unascii new file mode 120000 index 0000000..5c0d149 --- /dev/null +++ b/bin/unascii @@ -0,0 +1 @@ +ascii \ No newline at end of file