Skip to content

Instantly share code, notes, and snippets.

View ArthurDelannoyazerty's full-sized avatar

Arthur Delannoy ArthurDelannoyazerty

View GitHub Profile

RAM

Free RAM

free -h

               total        used        free      shared  buff/cache   available
Mem:           125Gi        12Gi       109Gi       186Mi       4.9Gi       113Gi
Swap: 4.0Gi 154Mi 3.8Gi
def stream_download(url:str, output_filepath:Path, desc:str='Item Download'):
response = requests.get(url, stream=True)
total = int(response.headers.get('content-length', 0))
with open(output_filepath, 'wb') as f, tqdm(desc=desc,total=total,unit='iB',unit_scale=True,unit_divisor=1024,) as bar:
for data in response.iter_content(chunk_size=1024):
size = f.write(data)
bar.update(size)
@ArthurDelannoyazerty
ArthurDelannoyazerty / display_geometries.py
Last active July 7, 2025 14:55
Display geojson/geometris on a earth map and save it as png/jpg
import geoplot
import contextily as cx
import geopandas as gpd
import matplotlib.pyplot as plt
from pathlib import Path
from shapely.geometry import shape
def display_geometries(list_geometries:list[dict], output_filepath:Path):
@ArthurDelannoyazerty
ArthurDelannoyazerty / dataloader_benchmark.py
Created May 23, 2025 09:46
Pyotrchdataloader benchmark
import time
import torch
from torch.utils.data import Dataset, DataLoader
from tqdm import tqdm
import pandas as pd
import matplotlib.pyplot as plt
from fourm.data.dummy_dataset import DummyDataset
def check_dataloader_speed(dataset:Dataset,
@ArthurDelannoyazerty
ArthurDelannoyazerty / linux_folder_size.md
Last active May 19, 2025 09:51
See the size of files & folders at your current location
du -sh ./* | sort -h
  • -s Gives only the total of each element
  • -h Human readable values
  • ./* all element in your current location (you can change that part for a specific location
  • sort -h Sort the element by size (bottom = largest)
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 / 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 / nginx_flask_socketio_gunicorn.md
Last active July 1, 2025 12:27
Simple Flask socketIO + nginx + gunicorn
@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