Skip to content

Instantly share code, notes, and snippets.

View ArthurDelannoyazerty's full-sized avatar

Arthur Delannoy ArthurDelannoyazerty

View GitHub Profile
import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from pathlib import Path
import matplotlib.colors as mcolors
# --- Configuration ---
# Define file paths using pathlib

Terminal / Keyboard

localectl list-keymaps
loadkeys fr
# setfont ter-132b
kdbrate -d 500 -r 10

INTERNET

@ArthurDelannoyazerty
ArthurDelannoyazerty / earth_grid.py
Last active July 7, 2025 15:41
Generate a earth grid and display them in a folium intercative HTML page
import folium
import s2geometry as s2
from folium.plugins import Draw
def get_grid_coords(min_lat, max_lat, min_lng, max_lng, level, max_cells=0):
"""Generate S2 cells covering a specified region at a given level."""
region = s2.S2LatLngRect(
s2.S2LatLng.FromDegrees(min_lat, min_lng),
s2.S2LatLng.FromDegrees(max_lat, max_lng)
@ArthurDelannoyazerty
ArthurDelannoyazerty / geometries_to_html.py
Last active July 7, 2025 14:55
Display geojson/geometris on a earth map and save it as html interactive page
import folium
from pathlib import Path
from folium.plugins import Draw
def display_geometries(list_geometries:list, output_filepath:Path, inverse_lat_lon:bool=True):
"""
Save the geometries on a map on a html page with an Earth background.
Args:
list_geometries (list[dict]): List of geometry dicts to plot.
output_filepath (Path): Path to save the output html file.
@ArthurDelannoyazerty
ArthurDelannoyazerty / interface_sql.py
Last active July 28, 2025 14:24
Communicate easily with a sqp database
import psycopg2 # pip install psycopg2-binary
from psycopg2 import sql
from typing import Optional, Any, Tuple, Union, List
class InterfaceSQL:
"""
An interface for building and executing SQL queries against a PostgreSQL database.
Query building and examination are handled by static methods that are connection-independent.
"""
@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