Pay

#!/usr/bin/env python3
import sys
from num2words import num2words
def spell_number(my_number):
    my_number = my_number.strip()
    if not my_number:
        return ""
    result = num2words(
        float(my_number),
        to="currency",
        currency="USD"
    )
    result = result.replace(",", "")
    result = result.replace(" and ", " ")
    result = result.replace("-", " ")
    result = result.title()
    result = result.replace(" Dollars ", " Dollars And ")
    result = result.replace(" Dollar ", " Dollar And ")
    return result
def main():
    for line in sys.stdin:
        result = spell_number(line)
        if result:
            print(result)

if __name__ == "__main__":
    main()

Posted in Uncategorized | Leave a comment

Ac

Report statistics of uptime

ac -dp –print-year

 

Posted in Uncategorized | Leave a comment

Abundant

#!/usr/bin/python3
import sys; beg,end=int(sys.argv[1]),int(sys.argv[2]);[print(f"{n} is "+("perfect" if (s:=sum(x for x in range(1,1+n//2) if n%x==0))==n else "abundant" if s>n else "deficient")) for n in range(beg,end+1)]

Posted in Uncategorized | Leave a comment

abcde

abcde for Linux in the off-hand chance you still need to rip a CD.

 

Posted in Uncategorized | Leave a comment

Palin

Find all palindromic words in a file

#!/usr/bin/python3
def words(fileobj):
    for line in fileobj:
        for word in line.split():
            yield word
with open("words.txt") as wordfile:
    wordgen = words(wordfile)
    for word in wordgen:
        if word == word[::-1]:
            print(word, end=" ")
    print()

Posted in Uncategorized | Leave a comment

Paginate

Python code to generate 26 page headers for a chapter of my magnum opus:

 #!/usr/bin/env python3
 import sys
 import string
 letter = sys.argv[1].upper()
 for second in string.ascii_uppercase:
     print(f'<span style="font-size: 1.7em; font-weight: bold;">{letter}{second}</span>')

Posted in Uncategorized | Leave a comment

Boxn

Python script to detect the width of your text and put a box around it

#!/usr/bin/env python3
import sys
lines = [line.rstrip("\n") for line in sys.stdin]
if not lines:
    sys.exit()
width = len(lines[0])
for n, line in enumerate(lines, 1):
    if len(line) > width:
        sys.exit(f"Line {n} is {len(line)} characters, exceeds box width {width}")
print("+" + "-" * (width + 2) + "+")
for line in lines:
    print(f"| {line:<{width}} |")
print("+" + "-" * (width + 2) + "+")

Posted in Uncategorized | Leave a comment

MSDOS



Skyglobe for MSDOS, still the best astronomy software 35 years later…



Before we wasted time on Windows solitaire we wasted time on MSDOS solitaire.







Posted in Uncategorized | Leave a comment

Matrix

while :;do echo $LINES $COLUMNS $((RANDOM%COLUMNS)) $(printf '%b' "\\u$(printf '%04x' $((RANDOM%500)))");sleep .05;done|gawk '{a[$3]=0;for(x in a){o=a[x];a[x]++;printf "\033[%s;%sH\033[2;32m%s",o,x,$4;printf "\033[%s;%sH\033[1;37m%s\033[0;0H",a[x],x,$4;if(a[x]>=$1)a[x]=0}}'

Posted in Uncategorized | Leave a comment

Calculus

Posted in Uncategorized | Leave a comment