Add a load of handy ~/bin scripts

This commit is contained in:
2020-02-23 15:07:02 +01:00
parent 99fbfc42fe
commit 8032cee29c
13 changed files with 323 additions and 0 deletions

34
bin/ascii Executable file
View File

@@ -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)