Category Archives: Uncategorized

Morse

Morse code generator with Sed #!/bin/sed -rf s/.*/\U&/ s/$/\nA.-B-…C-.-.D-..E.F..-.G–.H….I..J.—K-.-L.-..M–N-.O—P.–.Q–.-R.-.S…T-U..-V…-W.–X-..-Y-.–Z–../ :a s/([A-Z])([^\n]*\n.*\1([-.]+))/\3 \2/ ta s/\n.*//

Posted in Uncategorized | Leave a comment

Triangle

Calculate area and perimeter of any triangle #!/usr/bin/python3 import sys, math a, b, c = map(float, sys.argv[1:]) if a + b <= c or a + c <= b or b + c <= a: print(“Error: not a valid triangle”) … Continue reading

Posted in Uncategorized | Leave a comment

Vidir

Vidir (part of Debian’s moreutils) lets me edit the names of files in a directory in vim as though the directory was just a file, which it really is.  

Posted in Uncategorized | Leave a comment

Box

Put text in an ASCII art box: #!/usr/bin/env python3 import sys print(“+” + “-” * 62 + “+”) for line in sys.stdin: print(f”| {line.rstrip():<60} |”) print(“+” + “-” * 62 + “+”)

Posted in Uncategorized | Leave a comment

1 Liners

Print all primes less than 5000: $ python3 -c ‘print([i for i in range(2,5000) if all(i%j for j in range(2,int(i**0.5)+1))])’ Break a GIF into individual frames: ffmpeg -i taarna.gif frame_%d.jpg List all the words in a file with no matches … Continue reading

Posted in Uncategorized | Leave a comment

TOF

Interplanetary mission velocity change and time of flight using Python (example used is outbound leg to Mars): #!/usr/bin/env python3 import sys from math import sqrt, pi, radians, sin muP, muD, r1, rp1, muA, r2, rp2, inc = map(float, sys.argv[1:]) a … Continue reading

Posted in Uncategorized | Leave a comment

GreatCircle

Calculate a great circle route in kilometers: #!/usr/bin/env python3 import sys from math import radians, degrees, sin, cos, sqrt, asin lat1, lon1, lat2, lon2 = map(float, sys.argv[1:5]) dLat = radians(lat2 – lat1) dLon = radians(lon2 – lon1) lat1 = radians(lat1) … Continue reading

Posted in Uncategorized | Leave a comment

Lagrange

Find barycentric L1 and L2 Lagrange points from normalized mass ratio #!/usr/bin/env python3 import sys from scipy.optimize import brentq R = float(sys.argv[1]) m1 = R / (R + 1.0) m2 = 1.0 / (R + 1.0) x1 = -m2 x2 … Continue reading

Posted in Uncategorized | Leave a comment

Binsep

Python script for calculating the separation in AU between two stars in a binary system with known masses and period of revolution (the example uses Kruger 60 A/B): #!/usr/bin/env python3 import math import sys m1 = float(sys.argv[1]) m2 = float(sys.argv[2]) … Continue reading

Posted in Uncategorized | Leave a comment

Opt

With Python calculate the “comfort zone” of a star system based on visual magnitude and distance. Example is for Ran aka Epsilon Eridani (at Sol the comfort zone happens to be at 1 AU, what a coincidence!) #!/usr/bin/env python3 import … Continue reading

Posted in Uncategorized | Leave a comment