Skip to content

Instantly share code, notes, and snippets.

View sourceperl's full-sized avatar

l.lefebvre sourceperl

  • Hauts-de-France
View GitHub Profile
@sourceperl
sourceperl / multithreaded_ping.py
Created April 12, 2024 18:51
Basic multithreaded ping with python (on Linux systems)
from dataclasses import dataclass
from datetime import datetime
from queue import Empty, Queue
import re
import subprocess
from threading import Thread
import time
@dataclass
@sourceperl
sourceperl / sendmail.py
Created May 12, 2023 16:36
Send an mail to smtp.free.fr server
#!/usr/bin/env python3
""" Send mail with SMTP protocol. """
import logging
import re
import smtplib
from typing import List, Union
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
@sourceperl
sourceperl / main.py
Last active December 23, 2022 16:18
A micropython example of HTTP (json) data retrieval with handling of wifi connection errors on the Pico W board.
import uasyncio as aio
from machine import Pin
import network
import rp2
import errno
import urequests
import gc
from private_data import WIFI_SSID, WIFI_KEY
@sourceperl
sourceperl / cv_poly.py
Created December 6, 2022 20:08
Fit a polynomial to reflect the Cv curve of a control valve (Cv/position).
#!/usr/bin/env python3
"""Fit a polynomial to reflect the Cv curve of a control valve (Cv/position)."""
import numpy as np
import matplotlib.pyplot as plt
# a list of reference points extracted from the data sheet of the valve
ref_pts_l = [(0, 0), (4, 5), (10, 15), (16, 21), (20, 25), (30, 40), (40, 75),
@sourceperl
sourceperl / net-audit.py
Last active November 17, 2022 17:29
Basic ACL test script tool.
"""
A basic ACL test script tool.
Test under Python 3.10 on Windows 10 Entreprise (64 bits)
home: https://gist.github.com/sourceperl/548b7cfb35629eceee7163e877bb62d7
"""
import logging
import socket
@sourceperl
sourceperl / prometheus_endpoint.py
Created June 11, 2022 19:51
Basic HTTP endpoint for Prometheus
#!/usr/bin/env python3
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
from random import randint
class HandleRequests(BaseHTTPRequestHandler):
"""Custom HTTP handler"""
def version_string(self):
return 'self-service here ;-)'
@sourceperl
sourceperl / flow_coefficient.py
Last active December 5, 2022 11:31
Cv and flow compute for gas process valve
#!/usr/bin/env python3
"""
Some function to deal with Cv flow coefficient of gas valve.
https://www.swagelok.com/downloads/webcatalogs/EN/MS-06-84.pdf
"""
import math
@sourceperl
sourceperl / cam2redis.py
Last active May 3, 2021 09:50
Cast webcam jpeg image via redis DB also provide an example of tkinter client
#!/usr/bin/env python3
from datetime import datetime
import time
import io
import sys
import urllib.request
# sudo pip3 install schedule
import schedule
# sudo apt install python3-pil python3-pil.imagetk
@sourceperl
sourceperl / tk_webcam.py
Last active May 3, 2021 09:50
Display an auto-refresh webcam image (PNG) in a tkinter app
from datetime import datetime
import io
import sys
import urllib.request
import tkinter as tk
# sudo apt install python3-pil python3-pil.imagetk
import PIL.Image
import PIL.ImageTk
@sourceperl
sourceperl / rpi-monitoring.py
Last active December 3, 2020 09:12
Monitoring Raspberry Pi CPU temp + memory + a docker volume size to influxdb series
#!/usr/bin/env python3
import logging
import os
import sys
import time
import traceback
import influxdb