Skip to content

Instantly share code, notes, and snippets.

Avatar

Hermann Stamm-Wilbrandt Hermann-SW

View GitHub Profile
@Hermann-SW
Hermann-SW / irplay
Created Oct 12, 2021
Script to easily send keys via IR led, includes (unmodified) irrp.py pigpio lib demo, as well as codes file created by it
View irplay
#!/usr/bin/bash
clean=0; if [ ! -f /var/run/pigpio.pid ]; then sudo pigpiod; clean=1; fi
# script from http://abyz.me.uk/rpi/pigpio/code/irrp_py.zip
script="/irrp\.py$/,/Disconnect/p"
# json created with "./irrp.py -r -g17 -fcodes 1 3"
json="/^{/,/\]}/p"
@Hermann-SW
Hermann-SW / CTRL_ALT_Q.c
Last active Oct 18, 2021
keybinder repo modified demo, for switching Raspberry Pi400 between USB keyboard mode and normal operation
View CTRL_ALT_Q.c
/* main.c
* Created in 2010 by Ulrik Sverdrup <ulrik.sverdrup@gmail.com>
*
* This work is placed in the public domain.
*/
#include <stdio.h>
#include <gtk/gtk.h>
#include <keybinder.h>
@Hermann-SW
Hermann-SW / fagnano.tex
Created Oct 2, 2021
Simple check of Fagnano identity via Euler's identity, with Latex ("chktex"ed)
View fagnano.tex
\documentclass{article}
\begin{document}
\begin{eqnarray*}
Fagnano: \pi& =& 2 i \log\frac{1-i}{1+i} \\
& & \\
Euler: -1 & =& e^{i \pi} \\
& =& e^{-2 \log\frac{1-i}{1+i} } \\
& =& \left(\frac{1-i}{1+i}\right) ^ {-2} \\
& =& \left({\frac{1+i}{1-i}}\right) ^ 2 \\
@Hermann-SW
Hermann-SW / hello_world.cpp
Created Sep 16, 2021
C++ script with bash part output "hello " and C++ part output "world"
View hello_world.cpp
#!/bin/bash
exc=/tmp/`basename $0`
if [ $0 -nt $exc ]; then sed -n "/^\/\*\*$/,\$p" $0 | g++ -x c++ - -o $exc; fi
echo -n "hello "
$exc
exit
/**
@Hermann-SW
Hermann-SW / run_from_memory_stdin.c
Last active Sep 16, 2021
C script runs C code without temp space (tcc -run) and script stdin available to C
View run_from_memory_stdin.c
#!/bin/bash
echo "foo"
tcc -run <(sed -n "/^\/\*\*$/,\$p" $0) 42
exit
/**
*/
#include <stdio.h>
@Hermann-SW
Hermann-SW / mergesort
Created Sep 15, 2021
Parallel recursive bash mergesort
View mergesort
#!/bin/bash
tms="/tmp/ms.$1"
rm -f ${tms}[01]
IFS=''
while read line1
do
let n1=n1+1; echo $line1 >> ${tms}0
if read line2; then let n2=n2+1; echo $line2 >> ${tms}1; fi
@Hermann-SW
Hermann-SW / mfpsyuv
Last active Sep 7, 2021
Measure framerate really achieved by raspividyuv (varying mode, width, height, record time and requested framerate)
View mfpsyuv
# mfpsyuv: measure framerate really achieved by raspividyuv, varying
# mode, width, height, record time and requested framerate
#
#!/bin/bash
align () {
let x=$(($1-1))
echo $((x+$2-(x%$2)))
}
@Hermann-SW
Hermann-SW / encode.c
Last active Sep 5, 2021
parallel version of "/opt/vc/src/hello_pi/hello_encode"
View encode.c
/*
Copyright (c) 2012, Broadcom Europe Ltd
Copyright (c) 2012, Kalle Vahlman <zuh@iki>
Tuomas Kulve <tuomas@kulve.fi>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
@Hermann-SW
Hermann-SW / pipeN.c
Last active Sep 5, 2021
"man pipe" example extended to N childs+pipes
View pipeN.c
/* gcc -Wall -Wextra -pedantic pipeN.c -o pipeN
*/
#include <sys/types.h>
#include <sys/wait.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <assert.h>
@Hermann-SW
Hermann-SW / mecanum
Created Aug 18, 2021
Runs on mecanum wheel robot Pi0W, processes gamepad commands received over netcat
View mecanum
#!/bin/bash
if [ ! -f /var/run/pigpio.pid ]; then sudo pigpiod -s 1; sleep 0.5; fi
S=160
D=1
PWMAR=9
AIN1R=10
AIN2R=22