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 / main.c
Last active May 2, 2024 20:43
Test code MSP430 I2C LCD
#include <msp430g2211.h>
#define I2C_SDA BIT0 // Serial Data line
#define I2C_SCL BIT6 // Serial Clock line
/* A crude delay function. Tune by changing the counter value. */
void delay( unsigned int n ) {
volatile int i;
for( ; n; n-- ) {
@sourceperl
sourceperl / th_pinger.py
Last active April 12, 2024 18:56
Python script for do multi-threaded ping
#!/usr/bin/env python
# ping a list of host with threads for increase speed
# use standard linux /bin/ping utility
from threading import Thread
import subprocess
try:
import queue
except ImportError:
import Queue as queue
@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 / weather_math.py
Last active November 3, 2023 11:54
Compute frost and dew point (Python function)
import math
def get_frost_point_c(t_air_c, dew_point_c):
"""Compute the frost point in degrees Celsius
:param t_air_c: current ambient temperature in degrees Celsius
:type t_air_c: float
:param dew_point_c: current dew point in degrees Celsius
:type dew_point_c: float
@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 / propfind_request.py
Last active January 10, 2023 13:49
Python custom WebDAV PROPFIND on an owncloud server with requests HTTP library
#!/usr/bin/env python3
from xml.dom import minidom
import requests
# some consts
HTTP_MULTI_STATUS = 207
PROPFIND_REQUEST = '''<?xml version="1.0" encoding="utf-8" ?>
<d:propfind xmlns:d="DAV:">
<d:prop xmlns:oc="http://owncloud.org/ns">
<d:getlastmodified/>
@sourceperl
sourceperl / detect_tones.py
Last active January 9, 2023 05:37
Display sound spectral view with scipy FFT and matplotlib
#!/usr/bin/python3
# detect tones in sound spectrum with scipy FFT
# here sound source is a USB microphone with ALSA (channel 1)
from collections import deque
import struct
import sys
import time
import threading
@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 / 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