Hexes

Hexes

seq 0 255 | awk '{printf "%02x ", $1}' | xargs -n16

Posted in Uncategorized | Leave a comment

Morse

Morse Code 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

Fourier

Additive synthesis with Python

#!/usr/bin/env python3
import numpy as n,matplotlib.pyplot as p
x=n.linspace(0,2*n.pi,1000)
def s(x,t):
    k=n.arange(1,2*t,2)
    return 4/n.pi*(n.sin(k[:,None]*x)/k[:,None]).sum(0)
N=12
colors=p.cm.rainbow(n.linspace(0,1,N))
for i,t in enumerate(range(1,N+1)):
    p.plot(x,s(x,t),color=colors[i],label=f'{2*t-1} harmonics')
p.title('Fourier Series Approximation of a Square Wave')
p.grid()
p.legend()
p.show()

Posted in Uncategorized | Leave a comment

Prep

Remove ASCII art boxes from text

#!/usr/bin/env python3
import sys
import re
def prep(lines):
    cleaned = []
    for raw in lines:
        line = raw.rstrip("\n")
        if re.fullmatch(r"\+[-+]+\s*", line):
            continue
        if line.startswith("|"):
            line = line[1:]
        if line.endswith("|"):
            line = line[:-1]
        line = line.rstrip()
        if not line.strip():
            if cleaned and cleaned[-1] != "":
                cleaned.append("")
            continue
        line = line.lstrip()
        if cleaned and cleaned[-1] != "":
            cleaned[-1] += " " + line
        else:
            cleaned.append(line)
    return "\n".join(cleaned) + "\n"
if __name__ == "__main__":
    sys.stdout.write(prep(sys.stdin))

Posted in Uncategorized | Leave a comment

dfc

dfc (Disk Free Color)

Posted in Uncategorized | Leave a comment

Units

teresita:~$ units -1 -o "%.0f" "299792458 m/s" "furlongs per fortnight" 
	* 1802617499785
teresita:~$ 

Posted in Uncategorized | Leave a comment

Ellipse

#! /usr/bin/python3
import math
import sys
a = float(sys.argv[1])
b = float(sys.argv[2])
h = ((a - b) / (a + b))**2
eps = sys.float_info.epsilon
def binom_half(n):
    coef = 1.0
    for k in range(n):
        coef *= (0.5 - k) / (k + 1)
    return coef
perimeter = 0.0
n = 0
term = 1.0  
while abs(term) > eps:
    coef = binom_half(n)
    term = (coef**2) * h**(2*n)
    perimeter += term
    n += 1
perimeter *= math.pi * (a + b)
print(f"Ellipse perimeter: {perimeter:.17f}")
print(f"Series converged after {n} terms")

$ ellipse .387 .379
Ellipse perimeter: 2.40645997980731741
Series converged after 3 terms

Posted in Uncategorized | Leave a comment

Html.py

Python script to convert the text in your json Mastodon timeline archive to html

import json

with open("outbox.json") as f: outbox = json.load(f)
with open("actor.json") as f: actor = json.load(f)

articles = []
for s in [item.get("object") for item in outbox.get("orderedItems", [])]:
    if isinstance(s, dict):
        date, sumry, content = s.get("published")[:10], s.get("summary"), s.get("content", "")
        if sumry:

art = f”<article class=’post’>

{date}

<details><summary class=’sum’>{sumry}</summary>

{content}

</details></article>”

        else:

art = f”<article class=’post’>

{date}
{content}

</article>”

        articles.append(art)

css = """<style>
body { margin:0; background:#282c37; color:#fff; font-family:sans-serif; line-height:1.5; padding:20px; }
#header { text-align:center; max-width:600px; margin:0 auto 30px auto; padding:20px; background:#1f232b; border-radius:12px; }
.post { max-width:600px; margin: 0 auto 20px auto; border:1px solid #393f4f; border-radius:12px; padding:15px; background:#1f232b; }
.date { text-align:right; font-size:0.85em; color:#8c8d9a; margin-bottom:10px; }
.sum { background:#282c37; padding:8px; border-radius:6px; cursor:pointer; font-weight:bold; }
.sum::after { content:' [Click to Open]'; font-size:0.8em; color:#8585f2; }
a { color:#8585f2; }
</style>"""

html = f"""<!DOCTYPE html><html><head><meta charset='UTF-8'><title>Archive</title>{css}</head><body>
<section id='header'>

{actor.get(‘name’)}

@{actor.get(‘preferredUsername’)}

{actor.get(‘summary’)}
</section>
{"".join(articles)}
</body></html>"""

with open("processed_archive.html", "w", encoding="utf-8") as f: f.write(html)

Posted in Uncategorized | Leave a comment

Xkcd

Revel in your Linux nerddom with two xkcd fonts

mkdir -p $HOME/.local/share/fonts/xkcd
cd $HOME/.local/share/fonts/xkcd
wget https://
github.com/ipython/xkcd-font/raw/refs/heads/master/xkcd/build/xkcd.otf
wget https://
github.com/ipython/xkcd-font/raw/refs/heads/master/xkcd-script/font/xkcd-script.ttf
fc-cache -f

Posted in Uncategorized | Leave a comment

Alpine

This is the way. My first thirty years online looked like this. Usenet on UW’s legendary Pine then later the Alpine fork.

Posted in Uncategorized | Leave a comment