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 / 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
@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 / co2_view.py
Last active November 15, 2019 14:37
CO2 concentrations view and polynomial predict with matplotlib, pandas and numpy
#!/usr/bin/env python3
# pandas example with CSV data from atmospheric CO2 concentrations (ppm) at Mauna Loa, Observatory, Hawaii
# display current value with matplotlib
# try to predict future values with 2nd order polynomial coefficients auto-adjust
# test with numpy==1.16.2, pandas==0.19.2
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
@sourceperl
sourceperl / pure_py_dft.py
Last active June 21, 2019 14:51
Sample compute of a DFT (Discrete Fourier Transform) with pure python code (without numpy usage)
#!/usr/bin/env python3
# sample compute of a DFT (Discrete Fourier Transform) with pure python code (without numpy usage)
from cmath import exp
from math import pi, sin
import random
def dft(samples):
xl = [0.0] * len(samples)
@sourceperl
sourceperl / surface3d_valve_flow.py
Created June 10, 2019 13:21
3d graph of control valve dynamic (flow vs pressure/valve travel)
#!/usr/bin/env python3
# play with cv ( coefficient of flow) of control valve
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
import numpy as np
# some const (see http://www.idealvalve.com/pdf/Flow-Calculation-for-Gases.pdf)
SG = 0.554
@sourceperl
sourceperl / fly-build-csv
Last active April 11, 2019 14:56
flyspray CSV export tool
#!/bin/sh
# populate pub/ http directory with flyspray CSV export
# copy this script to /etc/cron.weekly
# csv file build name
YEAR=$(date +%Y)
CSV_FILE=export_$YEAR.csv
/usr/local/bin/flyspray2csv > /var/www/html/pub/flyspray/$CSV_FILE
@sourceperl
sourceperl / ttn-build-key
Last active October 30, 2018 10:49
TTN utils
#!/usr/bin/env python3
import random
key8 = ''.join(random.choice('0123456789ABCDEF') for n in range(16))
key16 = ''.join(random.choice('0123456789ABCDEF') for n in range(32))
print("generate 8 bytes key: %s" % key8)
print("generate 16 bytes key: %s" % key16)