Author Archives: Linuxgal

Unknown's avatar

About Linuxgal

Need a spiritual home? Consider joining us at Mary Queen of the Universe Latter-day Buddhislamic Free Will Christian UFO Synagogue of Vishnu

Trig

Trig functions #! /usr/bin/bc -l define t(x) { return s(x) / c(x) } define y(y) { if (y == -1) return -2 * a(1) /* -pi/2 */ if (y == 1) return 2 * a(1) /* pi/2 */ return a(y … Continue reading

Posted in Uncategorized | Leave a comment

All the vowels

With Python find words longer than 10 characters that use all the vowels: #! /usr/bin/env python3 with open(‘unixdict.txt’) as f: while (line := f.readline().strip()): if (len(line) > 10 and all( line.count(c) == 1 for c in ‘aeiou’)): print(line)

Posted in Uncategorized | Leave a comment

Say

Number to words #!/usr/bin/env python3 import sys n = int(sys.argv[1]) ones = [“zero”, “one”, “two”, “three”, “four”, “five”, “six”, “seven”, “eight”, “nine”] teens = [“ten”, “eleven”, “twelve”, “thirteen”, “fourteen”,”fifteen”, “sixteen”, “seventeen”, “eighteen”, “nineteen”] tens = [“”, “”, “twenty”, “thirty”, “forty”,”fifty”, … Continue reading

Posted in Uncategorized | Leave a comment

Spiral

Archimedes spiral with turtle graphics #!/usr/bin/env python3 from turtle import * from math import * color(“blue”) speed(0) down() for i in range(200): t = i*pi/20 r = 1+5*t goto(r*cos(t), r*sin(t)) done()

Posted in Uncategorized | Leave a comment

Compile

Compile short C programs on the fly at the command prompt echo ‘main() { printf(“Hello world!\n”); }’ | gcc -w -x c – -o hello echo ‘#include <stdio.h> int fibonacci(int n){return n<2?n:fibonacci(n-1)+fibonacci(n-2);} int main(){printf(“%d\n”,fibonacci(19));return 0;}’ | gcc -x c – … Continue reading

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