Skip to content

Instantly share code, notes, and snippets.

Avatar

Hermann Stamm-Wilbrandt Hermann-SW

View GitHub Profile
@Hermann-SW
Hermann-SW / gist:5b487ece9d62cf669caf
Created November 1, 2015 23:15
Measuring >40k interrupts per second by DS3231 32K and 8kHz enabled SQW lines on pins 2+3 of Arduino
View gist:5b487ece9d62cf669caf
// needed for RTC.set(_, _), see bottom as well
#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>
// from http://www.pjrc.com/teensy/td_libs_DS1307RTC.html
long lcnt=0;
void fcnt(void) { ++lcnt; }
@Hermann-SW
Hermann-SW / Germany.html
Created June 18, 2015 02:23
Google geochart sample at provinces resolution (Germany)
View Germany.html
<!--
Google geochart of Germany at provinces resolution
https://stamm-wilbrandt.de/en/github/Germany.html
https://google-developers.appspot.com/chart/interactive/docs/gallery/geochart
-->
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
@Hermann-SW
Hermann-SW / hextoppm.c
Created November 3, 2015 10:20
Convert Arduino ILI9341_due library "tft.screenshotToConsole()" Serial console output to .ppm picture file
View hextoppm.c
/*
hex2ppm.c -- this is a hack.
(Arduino ILI9341_due library ILIScreenshotViewer is Windows only)
Just copy the hex line from Serial console to eg. "scr.hex" file.
Then "hex2ppm src.hex > src.ppm" (followed by ppmtojpeg if needed).
Sample "tft.screenshotToConsole();" output in serial console window:
==== PIXEL DATA START ====
0000000002 ... 1D4D0D4013F000015B8
@Hermann-SW
Hermann-SW / collatz_async.py
Created November 20, 2018 23:00
65 concurrent uasyncio worker threads on 28KB free RAM ESP-01s module MicroPython
View collatz_async.py
import uasyncio as asyncio
N = 65
loop = asyncio.get_event_loop(runq_len = N+1)
def collatz(x):
yield x
while x!=1:
x = 3*x+1 if x%2==1 else x//2
yield x
@Hermann-SW
Hermann-SW / mp.js
Last active November 30, 2018 08:21
Node.js script allowing for remote MicroPython command execution
View mp.js
#!/usr/bin/env node
[scpt,pwd,host] = process.argv.slice(1);
cmd = process.argv.slice(4).join(" ");
out = 0;
last = "";
if (process.argv.length < 5) {
console.log((require("path")).basename(scpt) + " pwd host cmd [...]");
process.exit(1);
@Hermann-SW
Hermann-SW / local2gw
Created August 10, 2019 21:05
Reroute traffic for eg. eth0 IP address so that traffic goes through gateway instead of localhost (based on https://unix.stackexchange.com/a/128428 with one correction, one additon, and automatic determination of ip and gw; start eg. with "sudo ./local2gw eth0")
View local2gw
#!/bin/bash
if=$1
gw=`ip route show | grep "^default" | grep $if | cut -f3 -d\ `
vip=`ip route show table local | grep ^local | grep $if | cut -f2 -d\ `
# from https://unix.stackexchange.com/a/128428
ip route add local $vip dev lo table 10 proto kernel scope host
ip rule add to $vip lookup 10 prio 1
#
@Hermann-SW
Hermann-SW / stepperPTcamera.scad
Last active December 10, 2019 08:55
stepper Pan Tilt camera system: superglue connection of two 28BYJ-48 stepper motors
View stepperPTcamera.scad
// stepper Pan Tilt camera system: superglue connection of two 28BYJ-48 stepper motors
//
// based on https://www.thingiverse.com/thing:204734 by RGriffoGoes
// https://forum.arduino.cc/index.php?topic=647703.0
//
module StepMotor28BYJ()
{
difference(){
union(){
color("gray") cylinder(h = 19, r = 14, center = true, $fn = 32);
View camera_preview_on_two_displays.py
# Live camera preview on main DPI display as well as HDMI0 monitor.
#
# Works only after running "rpi-update" until this commit will be available:
#
# https://github.com/raspberrypi/userland/commit/2549c149d8aa7f18ff201a1c0429cb26f9e2535a
#
# Values are Dispmanx display enums, therefore predominantly
# 0 = DSI/DPI LCD
# 2 = HDMI0
# 3 = SDTV
@Hermann-SW
Hermann-SW / img_type_size.py
Created January 25, 2020 15:07
pipeable "file" command replacement for gif/jpeg/png (https://www.raspberrypi.org/forums/viewtopic.php?f=32&t=262967)
View img_type_size.py
#!/usr/bin/env python3
'''
Pipeable "file" command replacement for gif/jpeg/png images.
Outputs three lines (type, width, height), followed by copy of input.
'''
import struct
import sys
def get_image_type_size(fhandle):
@Hermann-SW
Hermann-SW / test.txt
Last active January 26, 2020 16:28
learn about revisions
View test.txt
foo
Aa (Orchidaceae)
Aaronsohnia (Compositae)
Abacopteris (Thelypteridaceae)
Abarema (Leguminosae)
Abatia (Salicaceae)
Abdominea (Orchidaceae)
Abdulmajidia (Lecythidaceae)
Abelia (Caprifoliaceae)
Abeliophyllum (Oleaceae)