Skip to content

Instantly share code, notes, and snippets.

@fl4p
fl4p / processes-cputime-longterm.py
Created September 26, 2025 10:05
Measure cpu time of all running processes over a time span
# note that it only measures processes that exist when measurement is started
import sys
import psutil
import pandas as pd
pd.set_option('display.max_colwidth', 200)
@fl4p
fl4p / diff-pstat-profiles.py
Last active August 29, 2025 20:36
Diff two python profiler .pstat files (cProfile. Pycharm)
# Compare two .pstat files to find out what happened between the two snapshats
# call times from a are reduced by b
# this results profile that ignores every call that happed before b
#
# consider using yappi instead, as it works better with multithreading
# a - b
a = '/Users/me/Library/Caches/JetBrains/PyCharm2024.3/snapshots/jnb5.pstat'
b = '/Users/me/Library/Caches/JetBrains/PyCharm2024.3/snapshots/jnb4.pstat'
"""
Real-time IIR Notch filter.
It remembers the state on subsequent calls so it can filter frames of a signal stream.
Useful to filter e.g. 50 Hz or 60 Hz noise.
"""
from scipy import signal
@fl4p
fl4p / gist:9135a0920fe43313dc956ca3ea45b703
Created December 28, 2024 14:51
Kicad Extensions & Tools
Export PCB 3d models https://github.com/easyw/kicadStepUpMod
KiCost
KiBot https://github.com/INTI-CMNB/KiBot?tab=readme-ov-file
@fl4p
fl4p / batch-cwebp.sh
Created December 24, 2024 10:11
Convert all png files in folder to webp
for f in docs/img/*.png; do cwebp "$f" -q 70 -o "${f%.png}.webp" && rm $f; done
@fl4p
fl4p / influxdb-gzip-write-monkeypatch.py
Last active November 22, 2023 21:00
influxdb-python-compress-writes
# initialize your client object as usual
influxdb_client = influxdb.InfluxDBClient(...)
# monkeypatch request function with a gzip wrapper
def _request_gzip(data, headers, **kwargs):
if headers is None:
headers = {}
if data:
@fl4p
fl4p / HalideGenGen
Last active October 29, 2017 19:57
Generates Halide filter modules
#include "Halide.h"
//#include "Generator.h"
using namespace Halide;
using namespace Halide::Internal;
std::string compute_base_path(const std::string &output_dir,
const std::string &function_name,
const std::string &file_base_name) {
std::vector<std::string> namespaces;
@fl4p
fl4p / semaphore-demo.php
Last active October 5, 2017 10:46
PHP semaphore example. Initiates multiple requests through iframes.
<?php
$concurrency = 9; // how many "threads"?
if(empty($_GET['iframe'])) {
for($i = 0; $i < $concurrency; $i++)
echo "<iframe src='".$_SERVER['PHP_SELF']."?iframe=1'></iframe>";
exit;
}
@fl4p
fl4p / disableOutputBuffer.php
Created October 5, 2017 10:42
Completely disable PHP output buffering for nginx and apache. It makes sure that GZIP is flushed too, by padding a random string of white spaces
<?php
function disableOutputBuffer($dontPad = false)
{
@ini_set('zlib.output_compression', 'Off');
header('X-Accel-Buffering: no');
ob_implicit_flush(true);
$levels = ob_get_level();
for ( $i = 0; $i < $levels; $i ++ ) {
ob_end_flush();
@fl4p
fl4p / energy-meter.py
Created September 27, 2017 12:49
Measure total energy usage on battery powered Linux system
import subprocess
import re
import datetime
import time
import sys
from select import select
def main():
tStart = datetime.datetime.now()
eStart = getBatteryEnergy()