Namegen

Random name generator with Python

#!/usr/bin/python3
import sys
import random
from pathlib import Path
script_dir = Path(__file__).resolve().parent
with open(script_dir / "fnames.idx", "r") as female:
    lines1 = female.readlines()
with open(script_dir / "mnames.idx", "r") as male:
    lines2 = male.readlines()
with open(script_dir / "lnames.idx", "r") as last:
    lines3 = last.readlines()
random.shuffle(lines1)
random.shuffle(lines2)
random.shuffle(lines3)
sys.stdout.write("Male\n\n")    
for i in range (0, 10, 1):
    sys.stdout.write(lines2[i].rstrip())
    sys.stdout.write(" ")
    sys.stdout.write(lines3[i])
sys.stdout.write("\nFemale\n\n")
for i in range (11, 21, 1):
    sys.stdout.write(lines1[i].rstrip())
    sys.stdout.write(" ")
    sys.stdout.write(lines3[i])

Posted in Uncategorized | Leave a comment

Intersect

Using Python and linear algebra to find the intersection of two lines, each line defined by four points.

#!/usr/bin/env python3
import sys,numpy as n
p,q,r,s=map(n.array,((float(sys.argv[i]),float(sys.argv[i+1])) for i in (1,3,5,7)))
M=n.c_[q-p,s-r]
d=n.linalg.det(M)
if abs(d)<1e-10:
    print("Coincident" if abs(n.cross(q-p,r-p))<1e-10 else "Parallel")
else:
    t,_=n.linalg.solve(M,r-p)
    print(p+t*(q-p))

Posted in Uncategorized | Leave a comment

Ascii.bas

Bywater Basic

for x=33 to 126
print using “###”;x;
print ” “;chr$(x);
print ” “;
if pos > 60 then print
next x
print

Posted in Uncategorized | Leave a comment

QMMP

QMMP for fans of WinAmp

Posted in Uncategorized | Leave a comment

Lagrange

Find barycentric L1 and L2 Lagrange Points from normalized mass ratio with Python

#!/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 =  m1
def f(x):
    r1 = abs(x - x1)
    r2 = abs(x - x2)
    return (
        x
        - m1 * (x - x1) / r1**3
        - m2 * (x - x2) / r2**3
    )
eps = 1e-12
L1 = brentq(f, x1 + eps, x2 - eps)
L2 = brentq(f, x2 + eps, x2 + 2.0)
r1 = x2 - L1
r2 = L2 - x2
print(f"Primary   : {x1:.12f}")
print(f"Secondary : {x2:.12f}")
print(f"L1        : {L1:.12f}")
print(f"L2        : {L2:.12f}")
print(f"L1 offset : {r1:.12f}")
print(f"L2 offset : {r2:.12f}")

Posted in Uncategorized | Leave a comment

Calendar

Build a calendar in Python

import calendar
calendar.setfirstweekday(6)
calendar.prcal(2026)

Posted in Uncategorized | Leave a comment

Plotfunc

Additive synthesis of square wave and sawtooth wave

#!/usr/bin/python3
import matplotlib.pyplot as plt
import numpy as np
x = np.arange(0, 2 * np.pi, 0.01)
y = np.zeros_like(x)
for n in range(1, 16, 2):
    y += np.sin(n * x) / n
z = np.zeros_like(x)
for n in range(1, 9):
    z += np.sin(n * x) / n
plt.figure(figsize=(10, 5))
plt.plot(x, y, label="Odd harmonics (1, 3, 5, ..., 15)")
plt.plot(x, z, color="red", label="All harmonics (1 through 8)")
plt.xlim(0, 2 * np.pi)
plt.xticks(
    [0, np.pi/2, np.pi, 3*np.pi/2, 2*np.pi],
    ["0", "π/2", "π", "3π/2", "2π"]
)
plt.xlabel("Radians")
plt.ylabel("Amplitude")
plt.title("Fourier Series")
plt.grid(True)
plt.legend()
plt.tight_layout()
plt.show()

Posted in Uncategorized | Leave a comment

Names

Random name generator

#!/usr/bin/python3
import sys
import random
from pathlib import Path
script_dir = Path(__file__).resolve().parent
with open(script_dir / "fnames.idx", "r") as female:
    lines1 = female.readlines()
with open(script_dir / "mnames.idx", "r") as male:
    lines2 = male.readlines()
with open(script_dir / "lnames.idx", "r") as last:
    lines3 = last.readlines()
random.shuffle(lines1)
random.shuffle(lines2)
random.shuffle(lines3)
sys.stdout.write("Male\n\n")    
for i in range (0, 10, 1):
    sys.stdout.write(lines2[i].rstrip())
    sys.stdout.write(" ")
    sys.stdout.write(lines3[i])
sys.stdout.write("\nFemale\n\n")
for i in range (11, 21, 1):
    sys.stdout.write(lines1[i].rstrip())
    sys.stdout.write(" ")
    sys.stdout.write(lines3[i])

Posted in Uncategorized | Leave a comment

Intersect

Using Python and linear algebra to find the intersection of two lines, each line defined by four points.

#!/usr/bin/env python3
import sys,numpy as n
p,q,r,s=map(n.array,((float(sys.argv[i]),float(sys.argv[i+1])) for i in (1,3,5,7)))
M=n.c_[q-p,s-r]
d=n.linalg.det(M)
if abs(d)<1e-10:
    print("Coincident" if abs(n.cross(q-p,r-p))<1e-10 else "Parallel")
else:
    t,_=n.linalg.solve(M,r-p)
    print(p+t*(q-p))

Posted in Uncategorized | Leave a comment

Maze

A compact recursive-backtracking maze generator in #Python using a randomized depth-first search to carve passages through a rectangular grid.

#!/usr/bin/python3
from random import shuffle, randrange
def makemaze(w=20,h=12):
    vis = [[0] * w + [1] for _ in range(h)] + [[1] * (w + 1)]
    ver = [["|  "] * w + ['|'] for _ in range(h)] + [[]]
    hor = [["+--"] * w + ['+'] for _ in range(h + 1)]
    def walk(x, y):
        vis[y][x] = 1
        d = [(x - 1, y), (x, y + 1), (x + 1, y), (x, y - 1)]
        shuffle(d)
        for (xx, yy) in d:
            if vis[yy][xx]: continue
            if xx == x: hor[max(y, yy)][x] = "+  "
            if yy == y: ver[y][max(x, xx)] = "   "
            walk(xx, yy)
    walk(randrange(w), randrange(h))
    s = ""
    for (a, b) in zip(hor, ver):
        s += ''.join(a + ['\n'] + b + ['\n'])
    return s
print(makemaze())

Posted in Uncategorized | Leave a comment