List all binaries in /usr/bin which do 𝑛𝑜𝑡 have a man page #linux
find /usr/bin -exec basename {} \; | xargs whereis -m | grep -v \/
List all binaries in /usr/bin which do 𝑛𝑜𝑡 have a man page #linux
find /usr/bin -exec basename {} \; | xargs whereis -m | grep -v \/
Calculate the date of Easter, accurate from 1900 to 2368 inclusive, with Python
Easter is celebrated on the first Sunday after the first full moon on or after 21 March.
#!/usr/bin/python3
import sys
y=int(sys.argv[1])
c=y//100;n=y-19*(y//19);k=(c-17)//25;i=c-c//4-(c-k)//3+19*n+15
i=i-30*(i//30);i=i-(i//28)*(1-(i//28)*(29//(i+1))*((21-n)//11))
j=y+y//4+i+2-c+c//4;j=j-7*(j//7);l=i-j;m=3+(l+40)//44;d=l+28-31*(m//4)
print(f"{y:04d}-{m:02d}-{d:02d}")
Print all the four letter words in the Bible:
perl -ne 'for(/\w+/g){$w=lc; $seen{$w}=1 if length$w==4} END{print"$_ " for sort keys %seen}' kjv.txt
Calculate factorials over a range
#!/usr/bin/env python3
import sys
import functools
start = int(sys.argv[1])
end = int(sys.argv[2])
for n in range(start, end + 1):
factorial = 1 if n == 0 else functools.reduce(
lambda x, y: x * y, range(1, n + 1)
)
print(f"{n}! = {factorial}")
#!/usr/bin/python3 import matplotlib.pyplot as plt import numpy as np axes = [5, 5, 5] data = np.ones(axes, dtype=bool) alpha = 0.9 colors = np.empty(axes + [4], dtype=np.float32) colors[0] = [1, 0, 0, alpha] # red colors[1] = [0, 1, 0, alpha] # green colors[2] = [0, 0, 1, alpha] # blue colors[3] = [1, 1, 0, alpha] # yellow colors[4] = [1, 1, 1, alpha] # white fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.voxels(data, facecolors=colors, edgecolors='grey') plt.show()
bumpgen.bas
5 DEF SEG=&HB800 10 SCREEN 2:CLS 15 LINE (0,0)-(639,199),1,BF 20 DIM Y(639):FOR Z=0 TO 639:Y(Z)=999:NEXT Z 25 C=9.800000E-03:B=25:F=9.850000E-03 30 FOR Z=200 TO 0 STEP -3 40 FOR X=0 TO 639:A=A+C:J=Z+SIN(A)*B:IF J>Y(X) THEN 1000 50 Y(X)=J:PSET (X,J),0 1000 NEXT X:B=B*8.999999E-01:C=C+F:NEXT Z
Generate magic squares for any odd side length with #Python
#!/usr/bin/env python3
import sys
def magic_constant(n):
return n * (n * n + 1) // 2
def magic_square(n):
square = [[0] * n for _ in range(n)]
num = 1
i, j = 0, n // 2
while num 1 else 3
square = magic_square(n)
width = len(str(n * n))
print(f"Magic constant for n={n}: {magic_constant(n)}\n")
for row in square:
print(" ".join(f"{x:>{width}}" for x in row))
Combinations of r elements chosen from a pool of n elements with awk
BEGIN {
for (i=1; i <= r; i++) {
A[i] = i
if (i < r ) printf i OFS
else print i}
while (A[1] = 1; i--) {
if (A[i] < n - r + i) {
A[i]++
p = i
break}}
for (i = p + 1; i <= r; i++) A[i] = A[i - 1] + 1
for (i=1; i <= r; i++) {
if (i < r) printf A[i] OFS
else print A[i]}}
exit}
$ awk -v r=3 -v n=5 -f comb.awk
xxd style hex dumper
#!/usr/bin/python3
import sys
with open(sys.argv[1], "rb") as f:
data = f.read()
for offset in range(0, len(data), 16):
b = data[offset:offset + 16]
left = " ".join(f"{x:02x}" for x in b[:8])
right = " ".join(f"{x:02x}" for x in b[8:])
hexpart = f"{left:<23} {right:<23}"
text = "".join(chr(x) if 32 <= x <= 126 else "." for x in b)
print(f"{offset:08x} {hexpart} |{text}|")