Skip to content

Instantly share code, notes, and snippets.

View Da-Juan's full-sized avatar
🛠️

Nicolas Rouanet Da-Juan

🛠️
View GitHub Profile
@Da-Juan
Da-Juan / prometheus_flask_exporter.py
Created August 23, 2023 08:43
Prometheus exporter in Python with background metrics gathering
"""Prometheus exporter with background metrics gathering."""
import signal
import threading
import time
from typing import TYPE_CHECKING
import schedule
from flask import Flask
from prometheus_client import Gauge, make_wsgi_app
from werkzeug.middleware.dispatcher import DispatcherMiddleware
@Da-Juan
Da-Juan / run_pgtuner.sh
Created March 1, 2022 16:12
Run postgresqltuner.pl on each database and keep 3 copies of each database's report
#!/usr/bin/env bash
# This script requires postgresqltuner.pl:
# apt install libdbd-pg-perl libdbi-perl perl-modules
# wget -O /usr/local/bin/postgresqltuner.pl https://postgresqltuner.pl
# chmod +x /usr/local/bin/postgresqltuner.pl
OUTPUT_DIR="/var/lib/postgresqltuner"
# Max number of files to keep for each database
MAX_COPIES=3
@Da-Juan
Da-Juan / get_certificate_dates.sh
Created June 24, 2021 15:00
Get certificates validity dates for a list of domains
#!/usr/bin/env bash
#
# Get certificates validity dates for a list of domains
#
while read -r domain; do
echo "$domain"
echo | openssl s_client -connect "$domain":443 -status 2>&1 | openssl x509 -dates -noout
done < domains
@Da-Juan
Da-Juan / opnsense_add_OCSP_stapling.md
Last active February 21, 2024 15:00
opnsense/haproxy: add OCSP stapling support

Here is a work around to automate OCSP stapling on Opnsense with HAproxy plugin.

Hope it helps :)

I created a script based on acme.sh's haproxy deploy hook.

As /tmp is emptied on reboot you need to regenerate ocsp files on startup so I put the script as a startup script: /usr/local/etc/rc.syshook.d/start/99-ocsp (symoblic links in rc.syshook.d don't work).

#!/bin/sh                          
@Da-Juan
Da-Juan / secret_santa.py
Last active December 5, 2018 12:30
Radomize secret santa pairings
#!/usr/bin/python3
import random
people = [
"Foo",
"Bar",
"Baz",
"Qux",
"Quux",
"Corge",
@Da-Juan
Da-Juan / progressbar.py
Last active August 12, 2019 16:52
Simple progress bar in Python 3.6
#!/usr/bin/env python3
"""Display a progressbar."""
import sys
import time
def progressbar(
progress: int, total: int,
percentage: bool = True, bar_width: int = 40,
todo: str = ' ', done: str = '=',
@Da-Juan
Da-Juan / percentage_output.py
Created November 7, 2018 14:53
Write growing percentage on standard output
#!/usr/bin/env python3
"""Percentage output."""
count = 0
items_nb = 500000
while True:
# You can replace .0f by .2f to output decimals
print(f'{count * 100 / items_nb:.0f}%', end='\r')
count += 1

ffmpeg cheat sheet

Re-encode mkv to h264 keeping audio and subtitles tracks

ffmpeg -i input.mkv -map 0:1 -map 0:a -map 0:s -c:a copy -c:s copy -c:v libx264 output.mkv

Explanations:

  • -map 0:1 select first video stream
@Da-Juan
Da-Juan / rm_exclusion.sh
Created June 6, 2018 08:39
Remove all files except some
#!/bin/bash
# Enable Extended Globbing
shopt -s extglob
# Simple version
rm !(a|b|c)
# Scriptable version
function join_by {
@Da-Juan
Da-Juan / bash_docker.sh
Created June 4, 2018 11:20
Run bash in background in a Docker image
docker run --name debian9 --hostname debian9 -d debian:9 /bin/bash -c "trap : TERM INT; sleep infinity & wait"