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 / 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 / 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 / rotate-8x8-matrix-char_convert-while-rotating.lua
Created June 16, 2016 21:48
http://wp.me/pzoQb-sN shows how to draw to MAX7219 8x8 matrix displays, this gist shows how the convert the numbers while rotating
local numberToTable = function(number, base, minLen)
local t = {}
repeat
local remainder = number % base
table.insert(t, 1, remainder)
number = (number - remainder) / base
until number == 0
if #t < minLen then
-- "pad" table with 0s
for i = 1, minLen - #t do table.insert(t, 1, 0) end
@marcelstoer
marcelstoer / rotate-8x8-matrix-char_traditional.lua
Last active June 16, 2016 21:41
http://wp.me/pzoQb-sN shows how to draw to MAX7219 8x8 matrix displays, this gist shows the maybe "traditional" way of rotating characters
local numberToTable = function(number, base, minLen)
local t = {}
repeat
local remainder = number % base
table.insert(t, 1, remainder)
number = (number - remainder) / base
until number == 0
if #t < minLen then
-- "pad" table with 0s
for i = 1, minLen - #t do table.insert(t, 1, 0) end
@marcelstoer
marcelstoer / validate-email.php
Created May 12, 2016 19:52
How to validate email with PHP
<?php
// inspired by a note at http://php.net/manual/en/function.getmxrr.php
// further inspiration from https://github.com/webdigi/SMTP-Based-Email-Validation
function validateEmail($email)
{
$emailValid = false;
$domain = extractFullyQualifiedDomainFromEmail($email);
$mxHost = findPreferredMxHostForDomain($domain);
@marcelstoer
marcelstoer / net-send-queue.lua
Last active May 16, 2016 19:33
NodeMCU net send queue
------------------------------------------------------------------------------
-- Net send queueing helper
--
-- Created by devsaurus for https://github.com/nodemcu/nodemcu-firmware/pull/1207
--
-- See also
-- https://nodemcu.readthedocs.io/en/dev/en/modules/net/#netsocketsend
--
-- Based on Vladimir Dronnikov's
-- MQTT queuing publish helper
@marcelstoer
marcelstoer / spring-security-logout-without-csrf.xml
Last active March 1, 2016 12:42
Spring Security logout without CSRF protection
...
<!-- http://docs.spring.io/spring-security/site/docs/4.0.x/reference/htmlsingle/#filter-stack -->
<!-- logout w/o CSRF protection if logout filter is placed before the CSRF filter -->
<security:custom-filter before="CSRF_FILTER" ref="logoutFilter" />
</security:http>
<bean id="logoutFilter" class="org.springframework.security.web.authentication.logout.LogoutFilter">
<constructor-arg name="logoutSuccessUrl" value="place-whatever-you-need-here" />
<constructor-arg name="handlers">
<list>
$ ssh <user>@<mac-without-screen>
$ sudo defaults write /var/db/launchd.db/com.apple.launchd/overrides.plist com.apple.screensharing -dict Disabled -bool false
$ sudo launchctl load /System/Library/LaunchDaemons/com.apple.screensharing.plist
/System/Library/LaunchDaemons/com.apple.screensharing.plist: Service is disabled
$ sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.screensharing.plist
@marcelstoer
marcelstoer / wifi-watch.lua
Last active October 24, 2016 21:50
Keep NodeMCU connected to WiFi
-- If you have a recent firmware from the dev branch you could do away with that ugly timer
-- by relying on WiFi events and (re-)acting accordingly. See wifi.sta.eventMonReg() at
-- https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en#wifistaeventmonreg
-- init all globals
...
wifiReady = 0
function configureWiFi()
@marcelstoer
marcelstoer / debounce.lua
Last active October 3, 2018 14:31
Debounce with NodeMCU with two separate functions for down/up trigger
-- inspired by: http://www.esp8266-projects.com/2015/03/buttons-pushbuttons-and-debouncing-story.html
local GPIO14 = 5
local debounceDelay = <however-many-ms-your-sensor-requires>
local debounceAlarmId = <0-6>
gpio.mode(GPIO14, gpio.INT, gpio.PULLUP)
gpio.trig(GPIO14, "down", doorLocked)
function doorLocked()
-- don't react to any interupts from now on and wait 50ms until the interrupt for the up event is enabled
-- within that 50ms the switch may bounce to its heart's content