Sort processes by how big of a bite they’re taking out of your RAM:
ps aux –sort=+%mem | awk ‘{print $4,”\t”, $11}’
Sort processes by how big of a bite they’re taking out of your RAM:
ps aux –sort=+%mem | awk ‘{print $4,”\t”, $11}’
Add line numbers to a file (Four digits, leading zeros, separated by a colon):
nl -i1 -s’: ‘ -nrz -w4 cotus.txt
Calculate absolute magnitude from visual magnitude for Sirius and Tau Ceti
#!/usr/bin/python3
import math
vmag = float(input("Visual magnitude?: "))
dist = float(input("Distance in light-years?: "))
amag = vmag-5*((math.log(dist/3.26156)/math.log(10))-1)
print ("Absolute magnitude=",amag)
Okay, here’s a way ChatGPT can shine, teaching LaTeX :
R_{\mu\nu} - \frac{1}{2} g_{\mu\nu} R + \Lambda g_{\mu\nu} = \frac{8\pi G}{c^4} T_{\mu\nu}
Plot a function as a contour map
#!/usr/bin/python3
import matplotlib.pyplot as plt
import numpy as np
X, Y = np.meshgrid(np.linspace(-4, 4, 512), np.linspace(-4, 4, 512))
Z = (1 - X/2 + X**4 + Y**3) * np.exp(-X**2 - Y**2) * (1 - X/3 - Y **4) * (3 - Y + X **2)
levels = np.linspace(np.min(Z), np.max(Z), 20)
fig, ax = plt.subplots()
ax.contour(X, Y, Z, levels=levels)
plt.show()
Plot city population as a pie chart for Washington cities with more than 100,000 people
#!/usr/bin/python3
import matplotlib.pyplot as plt
labels = 'Seattle', 'Spokane', 'Tacoma', 'Vancouver', 'Bellevue','Kent', 'Everett', 'Renton', 'Spokane Valley', 'Federal Way'
sizes = [737015, 228989, 219346, 190915, 151854, 136588, 110629, 106785, 102976, 101030]
fig1, ax1 = plt.subplots()
ax1.pie(sizes, labels=labels, autopct='%1.1f%%',
shadow=True, startangle=90)
ax1.axis('equal')
plt.show()
Use grep to find adjacent duplicate words in standard input:
nl gettysburg.txt | grep -E “(\b\w+\b)\s+\1”