Skip to content

Instantly share code, notes, and snippets.

Avatar

Hermann Stamm-Wilbrandt Hermann-SW

View GitHub Profile
@Hermann-SW
Hermann-SW / 640x75_640x150.picam.py
Created Jan 14, 2023
Overlay displaying 640x75 and 640x150 areas for Raspberry v2 camera raspiraw capturing at 1007fps (with 640x75 and 640x150_s tools)
View 640x75_640x150.picam.py
#!/usr/bin/python3
import numpy as np
from picamera import PiCamera
win = 100, 100, 640, 480
picam = PiCamera()
picam.resolution = (640, 480)
@Hermann-SW
Hermann-SW / 640x75_640x150.picam2.py
Created Jan 14, 2023
Overlay displaying 640x75 and 640x150 areas for Raspberry v2 camera raspiraw capturing at 1007fps (with 640x75 and 640x150_s tools)
View 640x75_640x150.picam2.py
#!/usr/bin/python3
import numpy as np
from picamera2 import Picamera2, Preview
picam2 = Picamera2()
picam2.configure(picam2.create_preview_configuration())
picam2.start_preview(Preview.QTGL, x=100, y=100, width=640, height=480)
picam2.start()
@Hermann-SW
Hermann-SW / BufferlessVideoCapture.py
Last active Dec 9, 2022
Allows to always get most recent frame, in case video capture loop has some (computation) delay inside
View BufferlessVideoCapture.py
# Based on: https://stackoverflow.com/questions/43665208/how-to-get-the-latest-frame-from-capture-device-camera-in-opencv/54755738#54755738
#
# Added:
# - configurable delay handling
# - renamed class
# - per frame timestamp output
#
import cv2, threading, time, queue
from sys import argv
@Hermann-SW
Hermann-SW / bash_.py
Last active Dec 6, 2022
Remote control bash from Python
View bash_.py
from subprocess import Popen, PIPE
from sys import argv
import re
stop = "qwertz1234567890ufugUUGUGUgUgUGuGFzR775§%!=%%54321rUF/Rtt8t8TTT4§2hj\n"
bye = ["tschüs","do_widzenia","ahoj","ciao","salut","adieu","vaarwel","farvel"]
byes = re.sub(r"['[]]*", "", str(bye))
cmd = "bash" if len(argv) == 1 else argv[1]
@Hermann-SW
Hermann-SW / bash1.py
Created Dec 6, 2022
Execute bash or other executable via Popen(), use .stdin/.stdout to send/recv one line
View bash1.py
from subprocess import Popen, PIPE
from sys import argv
cmd = "bash" if len(argv) == 1 else argv[1]
p = Popen(cmd, stdin=PIPE, stdout=PIPE)
while True:
p.stdin.write(bytes(input(cmd + ": ") + "\n", 'utf-8')); p.stdin.flush()
@Hermann-SW
Hermann-SW / RSA_numbers_factored.py
Last active Dec 20, 2022
Provides already factored RSA numbers
View RSA_numbers_factored.py
https://github.com/Hermann-SW/RSA_numbers_factored/
# RSA_numbers_factored.py
#
# v1.9
# remove not needed anymore RSA().__init__()
# add RSA().square_sums()
# manual transpilation to RSA_numbers_factored.js
# new home in RSA_numbers_factored repo python directory
# gist now is pointer to new home only
@Hermann-SW
Hermann-SW / factorial_pow2_odd.tex
Created Nov 21, 2022
Factorial, powers and odd numbers …
View factorial_pow2_odd.tex
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{eqnarray*}
(2^n)! \cdot 2 & =& 2^{2^n} \cdot \prod_{j=1}^{n-1} \enspace \prod_{i=2^{n-j-1}+1}^{2^{n-j}}(2i-1)^{j} \\
\end{eqnarray*}
\end{document}
@Hermann-SW
Hermann-SW / fac.bc
Created Nov 19, 2022
fac(n) computes factorial, facmod(n, m) is faster in reducing all recursive results "mod m"
View fac.bc
define fac(n) {
if (n==0) return 1;
return n*fac(n-1)
}
define facmod(n, m) {
if (n==0) return 1;
return n*fac(n-1)%m
}
@Hermann-SW
Hermann-SW / gcd.bc
Created Nov 18, 2022
greatest common divisor / lowest common multiple
View gcd.bc
define gcd_(a, b) {
if (b==0) return a
return gcd_(b, a%b)
}
define gcd(a, b) {
if (a<b) return gcd_(b, a)
return gcd_(a, b)
}
@Hermann-SW
Hermann-SW / trig.c
Created Nov 18, 2022
more trigonomic functions and definitions
View trig.c
pi=4*a(1)
d=pi/180
define sin(x){return s(x)}
define cos(x){return c(x)}
define atan(x){return a(x)}
define tan(x) {
if (c(x)==0) return pi/2
return s(x)/c(x)