Skip to content

Instantly share code, notes, and snippets.

@noirbizarre
noirbizarre / profiling.md
Created March 20, 2025 13:22
Python profiling

Standardizing Python tasks management

Abstract

This document is not a PEP but an aggregation of my notes, feedbacks, findings and experiments on this topic. However, it tries to be as close as possible from recent PEPs format for :

  • me to ensure that I give as much as possible information that would be required for a PEP
  • readers, to make it as easy as possible to read this document
@noirbizarre
noirbizarre / no_lifespan_on_APIRouter.py
Created June 22, 2023 12:20
A minimal example showing that APIRouter does not support `lifespan`
from contextlib import asynccontextmanager
from fastapi import FastAPI, APIRouter
def fake_answer_to_everything_ml_model(x: float):
return x * 42
ml_models = {}
@noirbizarre
noirbizarre / gpg-offline-master.md
Created August 31, 2022 22:53 — forked from abeluck/gpg-offline-master.md
GPG Offline Master Key w/ smartcard
@noirbizarre
noirbizarre / Rescue-Arch-LVM-on-LUKS-with-direct-efi-boot.md
Created December 17, 2020 15:29 — forked from schlueter/Rescue-Arch-LVM-on-LUKS-with-direct-efi-boot.md
Rescue Arch LVM on LUKS with direct efi boot system
# Boot off a live usb or similar as if you're installing
# If you're more comfortable with a different keyboard layout
$ loadkeys dvorak
# populate the second argument of the cryptsetup command based on this
$ parted <<<'print'
# the third argument may be anything, it needn't be used later
$ cryptsetup open /dev/sda3 foobar
# check your volume groups to see what to mount
$ ls /dev/vg
import json
from pytezos import pytezos, crypto
CURVES = b'ed', b'sp', b'p2'
for curve in CURVES:
key = crypto.Key.generate(curve=curve)
filename = f'{key.public_key_hash()}.json'
with open(filename) as inf:
@noirbizarre
noirbizarre / .env
Created October 1, 2019 15:12
Dual stack udata demo (Python 2/Python 3)
DOMAIN=data.localhost
@noirbizarre
noirbizarre / export_as_csvs.py
Created April 17, 2019 14:27
Export LibreOffice Calc sheets to individual CSV files
'''
A LibreOffice Calc Python macro exporting each sheet to an individual CSV file.
The CSV will be named <sheet name>.csv and will be sibling the source file.
To use this macro, store this file in your LibreOffice Python Scripts dir,
ie. `~/.config/libreoffice/4/user/Scripts/python/` on Linux
'''
import os
@noirbizarre
noirbizarre / profiling.py
Created March 19, 2019 10:27
udata search index profiling
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, print_function
import logging
import sys
from udata.app import create_app, standalone
from udata.commands import init_logging
from udata.search import es, commands as cmd
@noirbizarre
noirbizarre / deduplicate-users.js
Created November 13, 2018 12:38
Deduplicate users
db.user.aggregate([
{ $sort: { created_at: 1 } },
{
"$group": {
_id: "$email",
dups: { $addToSet: "$_id" } ,
count: { $sum : 1 }
}
},
{