Skip to content

Instantly share code, notes, and snippets.

View ArthurDelannoyazerty's full-sized avatar

Arthur Delannoy ArthurDelannoyazerty

View GitHub Profile
# IDE
# .vscode/      # commented to share info with others

# MacOS
*.DS_Store

# Virtual env
.venv/
venv/
@ArthurDelannoyazerty
ArthurDelannoyazerty / f_strings.md
Last active July 1, 2025 16:29
Python f strings examples

Center text

heading = "Centered string"
print( f'{heading:=^30}' )      #| = is for the char to print | ^ Is to center the text | 30 is the total length of the final string

'=======Centered string========'

Align text

@ArthurDelannoyazerty
ArthurDelannoyazerty / interface_sql.py
Last active July 1, 2025 12:56
Communicate easily with a sqp database
import psycopg2 # pip install psycopg2-binary
from typing import Optional
class InterfaceSQL:
def __init__(self, database:str, host:str, port:str, user:str, password:str):
conn = psycopg2.connect(
database=database,
host=host,

SSH

Create ssh public & private key (Linux & Windows)

ssh-keygen
  1. You will be asked the location to store the ssh keys (default : ~/.ssh/id_rsa)
  2. You will be asked the ssh passphrase 2 times
  3. Then the keys will be generated (public: id_rsa.pub | private: id_rsa)
@ArthurDelannoyazerty
ArthurDelannoyazerty / prepare_image_for_display.py
Created June 27, 2025 08:57
Take a numpy array or torch tensor and format it to be directly displayed (by matplotlib)
import math
import torch
import numpy as np
def prepare_image_for_display(
data: torch.Tensor|np.ndarray,
channels_selected: list[int] = [0,1,2],
permute_channels: bool = False,
normalize: bool = True,
@ArthurDelannoyazerty
ArthurDelannoyazerty / TableWithCodeTipsAndExamples.md
Created June 20, 2025 13:58 — forked from MarcoEidinger/TableWithCodeTipsAndExamples.md
Master GitHub markdown tables with code blocks

Master GitHub markdown tables with code blocks

  1. Use HTML tags to define the table to get the best layout result
  2. Use either backticks (```) or the HTML pre element with attribute lang
  3. Keep a blank line before and after a code block for correct formatting and syntax highlighting

Good

Example: nice looking table to show HTTP Responses

@ArthurDelannoyazerty
ArthurDelannoyazerty / countries_to_postgis.py
Last active July 1, 2025 12:30
small script to import contries and continents into a postgis table
import requests
import json
from pathlib import Path
from utils_sql import InterfaceSQL # custom psycopg2
from shapely.geometry import shape
if __name__ == '__main__':

Docker

Setup

mkdir docker
mkdir docker/volume
mkdir docker/volume/postgres

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)