Skip to content

Instantly share code, notes, and snippets.


Hermann Stamm-Wilbrandt Hermann-SW

View GitHub Profile
Hermann-SW / 1012x760
Created Jul 22, 2021
HQ camera raspiraw tool allowing to capture 1012x760@130fps
View 1012x760
if [ "$1" = "" ]; then echo "format: `basename $0` ms"; exit; fi
echo "removing /dev/shm/out.*.raw"
rm -f /dev/shm/out.*.raw
if [ "$2" = "" ]; then fps=130; else fps=$2; fi
if [ "$3" = "" ]; then eus=""; else eus="-eus $3 "; fi
echo "capturing frames for ${1}ms with ${fps}fps requested"
Hermann-SW / loop2
Last active Jul 13, 2021
loop2 displays "x->(x^2+a) mod n" graph using Graphviz neato command and Gnome image viewer
View loop2
#if 0
if [ $0 -nt /tmp/$0 ]; then gcc -xc -Wall -Wextra <(tail -n+2 $0) -o /tmp/$0; fi
/tmp/$0 $1 $2 > $1_$
neato -Tsvg $1_$ > $1_$2.svg
eog $1_$2.svg
Hermann-SW / mstr.c
Created Jul 3, 2021
Make mouse and trackball connected to Pi400 work for laptop over netcat session
View mstr.c
/* gcc -Wall -pedantic -Wextra mstr.c -o mstr
Works together with "Raspberry Pi400 as a USB HID Keyboard":
Raspberry mouse and trackball, both connected to Pi400, work on laptop!
On laptop:
$ nc -l 8888 | sudo ./mstr -nodelay
Hermann-SW / mstr_events.c
Last active Jul 2, 2021
Show and parse all mouse/trackball related events
View mstr_events.c
/* gcc -Wall -Wextra mstr_events.c -o mstr_events
/dev/input/eventX (X=0 mouse, X=3 trackball)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <assert.h>
#include <linux/input.h>
Hermann-SW / Makefile
Last active Jul 2, 2021 — forked from Gadgetoid/Makefile
Pi 400 KB
View Makefile
pi400: CFLAGS+=-static -lusbgx -lconfig -DPI400_USB
pi400: pi400.c gadget-hid.c
$(CC) $^ $(CFLAGS) -o $@
-rm pi400
Hermann-SW / search_cycle.c
Created Jun 30, 2021
Determines for "x->(x^2+1)%n" number of steps needed by Pollard-Rho factorization algorithm, with s on cycle of start value 0
View search_cycle.c
// gcc -Wall -Wextra -pedantic search_cycle.c -o search_cycle
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
typedef unsigned long unsig;
unsig gcd(unsig a, unsig b)
if (a<b)
Hermann-SW / period.c
Last active Jun 22, 2021
Determines period of "x->(x^2+a) mod n" for start value s (arbitrary precision, gmplib)
View period.c
/* gcc -O3 -Wall -Wextra -pedantic -fomit-frame-pointer -m64 -o period period.c -lgmp
$ ./period
period [n [a [s]]]
Determines period of x->(x^2+a) mod n for start value s.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
Hermann-SW / sqr.cpp
Last active Jun 7, 2021
compares runtimes of 1 million additions of squares of 128bit numbers (my uint256_t / gmplib / ttmath)
View sqr.cpp
$ g++ -Ittmath -O3 -Wall -Wextra -pedantic -fomit-frame-pointer -m64 -mtune=skylake -march=broadwell -o sqr sqr.cpp -lgmp
$ for((i=0; i<5; ++i)); do ./sqr ; done | grep ns | sort -n
Hermann-SW / gcd.c
Last active Jun 4, 2021
test harness for comparing __uint128_t "gcd()" against gmplib "mpz_mod()"
View gcd.c
#include <stdio.h>
#include <immintrin.h>
#include <time.h>
#include <sys/time.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include "gmp.h"
Hermann-SW / mod_256.c
Created Jun 3, 2021
First version of unit256_t "mod_256()" showing speedup over gmplib "mpz_mod()"
View mod_256.c
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <time.h>
#include <sys/time.h>
#include "gmp.h"
#define N 1000000