Skip to content

Instantly share code, notes, and snippets.

View marcelstoer's full-sized avatar
👨‍👩‍👧‍👧
The Earth was made round so that we would not see too far down the road - K.B.

Marcel Stör marcelstoer

👨‍👩‍👧‍👧
The Earth was made round so that we would not see too far down the road - K.B.
View GitHub Profile
@marcelstoer
marcelstoer / rotate-8x8-matrix-char_convert-while-rotating-no-matrix.lua
Created June 16, 2016 21:55
http://wp.me/pzoQb-sN shows how to draw to MAX7219 8x8 matrix displays, this gist shows how the convert the numbers while rotating without the use of a 0|1 matrix
local rotate = function(char, rotateleft)
local tab = {}
local newTable = {}
local numberToString = function(number, base, minLen)
local s = ""
repeat
local remainder = number % base
s = remainder .. s
number = (number - remainder) / base
@marcelstoer
marcelstoer / so-38990950.lua
Last active September 6, 2023 07:39
SO 38990950
-- https://stackoverflow.com/questions/38990950/simulating-esp8266-server-multithreading
someint = 5
a = 1
srv:listen(8080,function(conn)
conn:on("receive", function(client,request)
client:send(someint);
client:close(); -- btw, you should wait for 'sent' event before closing, see http://nodemcu.readthedocs.io/en/latest/en/modules/net/#example_6
end)
end)
@marcelstoer
marcelstoer / nodemcu-execution-time.lua
Created April 15, 2017 21:05
How to measure the execution time of a NodeMCU Lua function
-- all credits go to http://www.esp8266.com/viewtopic.php?p=64968#p64968
function profile(name)
local start = tmr.now()
_G[name]()
local delta = tmr.now() - start
print(name .. " needs " .. (delta / 1000) .. " ms")
end
function longTime()
local sum = 0
@marcelstoer
marcelstoer / publish-bme280-data-from-raspberry_pi-to-thingspeak.py
Last active July 24, 2020 21:26
Publish BME280 data from Raspberry Pi to ThingSpeak
import thingspeak # from https://thingspeak.readthedocs.io/en/latest/
import bme280 # from https://www.raspberrypi-spy.co.uk/2016/07/using-bme280-i2c-temperature-pressure-sensor-in-python/
# return the Pi CPU/GPU temperature in degree Celcius; it's a SoC and thus there's no need to read both, see
# https://www.cyberciti.biz/faq/linux-find-out-raspberry-pi-gpu-and-arm-cpu-temperature-command/#comment-796904
def get_temp():
with open('/sys/class/thermal/thermal_zone0/temp', 'r') as infile:
return float(infile.read()) * 1e-3
ch = thingspeak.Channel(275145, "*********", "*********")
@marcelstoer
marcelstoer / HtmlPopupTransientWindow.py
Created September 19, 2017 06:30
wxPython transient window with HTML support, selectable text and clickable links
# coding=utf-8
import wx
import wx.html
import webbrowser
class HtmlPopupTransientWindow(wx.PopupTransientWindow):
def __init__(self, parent, style, html_body_content, bgcolor, size):
@marcelstoer
marcelstoer / Arduino-uint64ToString.c
Created April 9, 2018 20:37
Arduino uint64ToString
// source: https://github.com/markszabo/IRremoteESP8266/blob/master/src/IRutils.cpp#L48
String uint64ToString(uint64_t input) {
String result = "";
uint8_t base = 10;
do {
char c = input % base;
input /= base;
if (c < 10)
@marcelstoer
marcelstoer / init.lua
Created June 3, 2018 19:00
NodeMCU Lua initializer with DNS & internet connectivity testing
WIFI_SSID = "--your-value-here--"
WIFI_PASSWORD = "--your-value-here--"
wifi_got_ip_event = function(T)
local site = "wikipedia.org"
-- Note: Having an IP address does not mean there is internet access!
-- Internet connectivity can be determined with net.dns.resolve().
print("WiFi connection is established! IP address is: " .. T.IP)
print("DNS server 1: " .. net.dns.getdnsserver(0))
print("DNS server 2: " .. net.dns.getdnsserver(1))
# see https://frightanic.com/web-authoring/website-hosting-with-git-a-tutorial/ for the full picture
#
# create remote repository
ssh user@host.com
mkdir repos
cd repos
mkdir example.git
cd example.git
git --bare init
# create local clone on development machine
@marcelstoer
marcelstoer / ref-parser-bundler-overwrite.js
Last active January 13, 2022 20:33
Ugly way to redefine remap() function for SwaggerParser#bundle() from APIDevTools
// *********************************************************************************************************************
// I needed to redefine the remap() function invoked at
// https://github.com/APIDevTools/json-schema-ref-parser/blob/master/lib/bundle.js#L25 due to
// https://github.com/APIDevTools/swagger-parser/issues/127
//
// I'm not versed enough with JavaScript and Node.js to understand if there would be a less invasive way to have my own
// remap(). As far as I understand SwaggerParser (or JSON Schema $Ref Parser for that matter) is not built in a way that
// allows to easily extend it. The only option I found was to redefine the bundle() prototype function and to copy a lot
// of code from bundle.js.
//
@marcelstoer
marcelstoer / SamlAssertionExtractor.java
Created September 7, 2020 13:50
SamlAssertionExtractor.java
import com.google.common.base.Preconditions;
import lombok.extern.slf4j.Slf4j;
import net.shibboleth.utilities.java.support.xml.ParserPool;
import net.shibboleth.utilities.java.support.xml.XMLParserException;
import org.apache.commons.lang3.StringUtils;
import org.opensaml.core.config.InitializationException;
import org.opensaml.core.config.InitializationService;
import org.opensaml.core.xml.config.XMLObjectProviderRegistrySupport;
import org.opensaml.core.xml.io.Unmarshaller;
import org.opensaml.core.xml.io.UnmarshallerFactory;