Skip to content

Instantly share code, notes, and snippets.

View ArthurDelannoyazerty's full-sized avatar

Arthur Delannoy ArthurDelannoyazerty

View GitHub Profile
docker run --rm -v "$PWD:/pwd" busybox rm -rf /pwd/<element>
  1. Create a small linux docker (busybox)
  2. Make the current terminal location a volume binded to /pwd in the container
  3. Remove an element from that location (/pwd/<element>)
  4. Erase the launched container (--rm)
@ArthurDelannoyazerty
ArthurDelannoyazerty / pg_dump_pg_restore.md
Created March 26, 2025 11:14
postgres use of pg_dump and pg_restore

General info

  • pg_dump : Database to file
  • pg_restore : file to Database
  • Better if pg_restore --version > pg_dump --version

pg_dump

pg_dump -f /pg_dump.dump -Fc --dbname DB_NAME -U USERNAME

  • -Fc : Format=custom
@ArthurDelannoyazerty
ArthurDelannoyazerty / json_utils.py
Created March 20, 2025 13:55
Extract a json/dict from a string in Python
import logging
logger = logging.getLogger(__name__)
def extract_json_from_string(text:str) -> dict:
"""Convert a text containing a JSON or python dict into a python dict.
:param str text:
:raises ValueError: If the string does not contains a valid json
:return dict:
@ArthurDelannoyazerty
ArthurDelannoyazerty / .bashrc
Last active April 15, 2025 14:52
My .bashrc
alias lps="lps -dF"
alias ls="ls --color"
alias ll="ls -alFhv --group-directories-first"
alias df="df -h"
umask 0002
# UV ------------------------------------------------
. "$HOME/.cargo/env"
@ArthurDelannoyazerty
ArthurDelannoyazerty / nginx_flask_socketio_gunicorn.md
Created March 17, 2025 16:11
Simple Flask socketIO + nginx + gunicorn
@ArthurDelannoyazerty
ArthurDelannoyazerty / Git_auth.md
Last active March 17, 2025 15:45
Notes on git authentification

Clone a repository

git clone <url>

Git config

git config --global user.name "Name"
git config --global user.email [email protected]
@ArthurDelannoyazerty
ArthurDelannoyazerty / current_time.py
Created March 13, 2025 10:41
Python script that get the UTC time from a NTP server. Usefull when the machine clock is wrong.
import time
import ntplib
import logging
logger = logging.getLogger(__name__)
def get_current_utc_time() -> float:
logger.debug('Requesting current UTC time')
response = ntplib.NTPClient().request('pool.ntp.org')
logger.debug(f'UTC time : {response.tx_time} | {time.strftime('%Y-%m-%dT%H-%M-%S',time.gmtime(response.tx_time))}')
@ArthurDelannoyazerty
ArthurDelannoyazerty / argparse.py
Created March 4, 2025 10:12
A basic argparse in python
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('minute_threshold', type=int)
args = parser.parse_args()
minute_threshold:int = args.minute_threshold
@ArthurDelannoyazerty
ArthurDelannoyazerty / tabulate.md
Created February 5, 2025 17:07
Minimal code examples for tabulate

List to table

We transpose the list so that the Nth column is the Nth list of the entire array Column n = l[n-1])

headers = ['Column 1', 'Column 2', 'Column 3']
l = [[1, 2, 3],
     [4, 5, 6],
     [7, 8, 9]]

table = tabulate.tabulate(list(map(list, zip(*l))), headers=headers, tablefmt="github")
@ArthurDelannoyazerty
ArthurDelannoyazerty / Postgresql_liten_notify_while_doing_other_synchronous_job.py
Last active January 28, 2025 15:06
Small code to listen to a postgress NOTIFY while doing a normal function at the same time. No async job (except the actual listener). The NOTIFY listener is launched with asyncio in another thread while the normal job is executed in the main thread
import asyncio
import logging
import os
import psycopg2
import threading
import time
from dotenv import find_dotenv, load_dotenv
def listen_to_notifications():