Skip to content

Instantly share code, notes, and snippets.

View keuv-grvl's full-sized avatar

Keuv Grvl keuv-grvl

  • Bordeaux, France
View GitHub Profile
@keuv-grvl
keuv-grvl / singleton.py
Created May 14, 2025 14:04
Singleton pattern
class Singleton(type):
_instances = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs)
return cls._instances[cls]
class MyClass(metaclass=Singleton):
@keuv-grvl
keuv-grvl / Makefile
Created May 13, 2025 15:46
Makefile for simple python project dev
# TODO: replace black&isort by ruff
# TODO: how does this work with pre-commit?
# TODO: autopep/autoflake, bumpversion, docker build/push
SRC_DIR = my_project # CHANGE THIS
all: setup format lint-quick
@keuv-grvl
keuv-grvl / _version.py
Created March 13, 2025 15:26
Versioning schema somewhere between [SemVer](https://semver.org/) and [CalVer](https://calver.org/)
"""Versioning schema somewhere between [SemVer](https://semver.org/) and [CalVer](https://calver.org/).
Schema: MAJOR.MINOR.PATCH
where:
- MAJOR is manually incremented when breaking changes are introduced
- MINOR is the release year ("25" when we are in 2025)
- PATCH is the number of the day of the year (between 1 and 365)
Hence :
@keuv-grvl
keuv-grvl / python.json
Created August 5, 2024 12:30
VSCode python snippets
{
"if __name__ == \"__main__\":": {
"body": [
"if __name__ == \"__main__\":\n\t$0"
],
"prefix": [
"__name__",
"__main__",
]
},
@keuv-grvl
keuv-grvl / README.md
Last active April 18, 2023 09:55
Pytorch activation function speed

Performance for activation function

timeit applied to various Pytorch activation function on CPU and GPU, on a tensor of shape (20000,)

You must run this in a IPython session. Pytorch version is 2.0.0+cu117.

See run.py.

Results

@keuv-grvl
keuv-grvl / hf_dataset.py
Created April 12, 2023 12:33
Wrap a HF `datasets.Dataset` into `torch.utils.data.Dataset`
import torch
import datasets
class HFDataset(torch.utils.data.Dataset):
def __init__(self, dset: datasets.Dataset):
self.dset = dset
def __getitem__(self, idx):
return self.dset[idx]
@keuv-grvl
keuv-grvl / cap_screen.ipy
Last active February 21, 2023 14:09
Capture android screen from Python
%pip install pure-python-adb imageio
from ppadb.client import Client as AdbClient
# plug your android device with USB debugging
client = AdbClient(host="127.0.0.1", port=5037)
device = client.devices()[0]
screencap = device.screencap()
@keuv-grvl
keuv-grvl / bench.md
Created February 21, 2023 09:02
Benchmark device (write) speed

Benchmark write speed

Write zeros to a device (using a mountpoint).

Command

# Choose one
FOLDER="$HOME"
FOLDER="/tmp"
@keuv-grvl
keuv-grvl / demo.md
Last active February 9, 2023 16:34
(parallel) gzip qith a tqdm progress bar

gzip with tqdm progress bar

Prereq

pip install tqdm

Minimalistic

@keuv-grvl
keuv-grvl / README.md
Created February 2, 2023 09:19
Lock and turn off your screen on Pop!_OS

(properly) Lock and turn off your screen on Pop!_OS 22.04 LTS

Pop!_OS does not turn off your screen when you lock your screen. Where you hit tue Super+L shortcut, it seems to start some screensaver which display a black image and coincidently lock your session. But the screen itself does not go to its standby mode.

Here is my solution:

  1. Nuke the <Super>l shortcut occurences:
    • List conf keys: {dconf dump / ; gsettings list-recursively } | less
  • Use dconf-editor to unset them