Skip to content

Instantly share code, notes, and snippets.

View Couapy's full-sized avatar
😎
enjoying the life

Maël Couapy

😎
enjoying the life
View GitHub Profile
@Couapy
Couapy / progress_bar.py
Created February 19, 2025 15:06
Add a progress bar with ETA to your scripts
import sys
import time
def progress(iterable, length=None, bar_length=40):
def format_time(seconds):
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
d, h = divmod(h, 24)
return f"{d}d {h}h {m}m {s:0.0f}s" if d else f"{h}h {m}m {s:0.0f}s" if h else f"{m}m {s:0.0f}s" if m else f"{s:0.0f}s"
from django.db.models import Model
def __get_instances(
self,
instance: Model,
processed_instances: set[Model] = set(),
) -> set[Model]:
"""Get all instances from a model instance.
Recursively get all instances from a model instance, including related objects.
@Couapy
Couapy / install-ingress.sh
Last active February 24, 2025 21:15
Setup alpine linux Kubernetes clsuter
kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v1.2.1/deploy/static/provider/cloud/deploy.yaml
kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.8.2/cert-manager.yaml
@Couapy
Couapy / commit-msg
Last active November 24, 2020 15:52
Git hooks
#!/bin/sh
COMMIT_MSG=$1
COMMIT_MSG_TEMPLATE="type(context): message"
COMMIT_MSG_REGEX="^(build|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-z\-_]+\))?: .+"
egrep "${COMMIT_MSG_REGEX}" $COMMIT_MSG
if [[ $? != 0 ]]; then
echo "The commit message format is not respected."
echo "[FORMAT] ${COMMIT_MSG_TEMPLATE}"
@Couapy
Couapy / launch.json
Created November 22, 2020 10:37
Django debug - live reload - for visual studio code
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/src/manage.py",
"console": "integratedTerminal",
"args": [
@Couapy
Couapy / README.md
Last active October 21, 2020 14:03
Make functions keys enabled by default on Keychron K2 on linux

Make functions keys enabled by default on Keychron K2 on linux

By default on my computers the functions keys are not working.

Run this to install it :

wget https://gist.githubusercontent.com/Couapy/e5cdf2078f5978fd4ddde98d09f1ca24/raw/fea4085a070202a3221c66c1ef370528697fa1eb/keychron.service
sudo cp -r keychron.service /etc/systemd/system/
sudo systemctl enable keychron && sudo systemctl start keychron
install:
@pip3 install .
archive:
@python3 setup.py sdist
upload: archive
@python3 -m twine upload dist/*
clean: