Skip to content

Instantly share code, notes, and snippets.

View plutec's full-sized avatar

Antonio Sánchez plutec

View GitHub Profile
/*********
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp32-cam-video-streaming-web-server-camera-home-assistant/
IMPORTANT!!!
- Select Board "AI Thinker ESP32-CAM"
- GPIO 0 must be connected to GND to upload a sketch
- After connecting GPIO 0 to GND, press the ESP32-CAM on-board RESET button to put your board in flashing mode
Permission is hereby granted, free of charge, to any person obtaining a copy
// -*- c++ -*-
// --------------------------------------
// i2c_scanner (using SoftWire and SoftI2CMaster)
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
from datetime import datetime
import asyncore
from smtpd import SMTPServer
class EmlServer(SMTPServer):
no = 0
def process_message(self, peer, mailfrom, rcpttos, data):
filename = '%s-%d.eml' % (datetime.now().strftime('%Y%m%d%H%M%S'),
self.no)
f = open(filename, 'w')
@plutec
plutec / ESP32_Using_Serial2.ino
Last active November 8, 2019 08:46
Serial 1 and 2 ESP32
/*
* There are three serial ports on the ESP known as U0UXD, U1UXD and U2UXD.
*
* U0UXD is used to communicate with the ESP32 for programming and during reset/boot.
* U1UXD is unused and can be used for your projects. Some boards use this port for SPI Flash access though
* U2UXD is unused and can be used for your projects.
*
*/
#define RXD2 16
@plutec
plutec / dummy_smtp_server.py
Created November 12, 2018 07:11
Simple SMTP server
from datetime import datetime
import asyncore
from smtpd import SMTPServer
class EmlServer(SMTPServer):
no = 0
def process_message(self, peer, mailfrom, rcpttos, data):
filename = '%s-%d.eml' % (datetime.now().strftime('%Y%m%d%H%M%S'),
self.no)
f = open(filename, 'w')
import heapq
import threading
class HeapThreadSafe(object):
def __init__(self):
self.sem = threading.Semaphore(1)
self.heap = list()
def push(self, obj):
self.sem.acquire()
@plutec
plutec / timeout_decorator.py
Last active July 25, 2022 19:59
Decorator to add timeout to a function in python
from functools import wraps
import errno
import os
import signal
import time
#Source: http://stackoverflow.com/questions/2281850/timeout-function-if-it-takes-too-long-to-finish
class TimeoutError(Exception):
pass
@plutec
plutec / Subprocess_class.py
Last active August 22, 2023 02:27
Class to create a subprocess with a watchdog
import time
import subprocess
import datetime
"""
This class is used to execute a subprocess including a watchdog
"""
class Subprocess(object):
def __init__(self, cmd, cwd=None, stdout=None):
self.cmd = cmd