Skip to content

Instantly share code, notes, and snippets.

View laurent-laporte-pro's full-sized avatar
🏠
Working from home at DFYA

Laurent LAPORTE laurent-laporte-pro

🏠
Working from home at DFYA
View GitHub Profile
@laurent-laporte-pro
laurent-laporte-pro / product_model_optionals.py
Last active May 24, 2023 13:03
Pydantic model with optional fields
from enum import Enum
from typing import Optional
import pydantic.main
from pydantic import Field, BaseModel
class AllOptionalMetaclass(pydantic.main.ModelMetaclass):
....
@laurent-laporte-pro
laurent-laporte-pro / id_generator.py
Last active July 6, 2023 08:56
Transform a name into an identifier by replacing consecutive invalid characters by a single white space, and then whitespaces are striped from both ends.
import re
# Invalid chars was taken from Antares Simulator (C++).
_sub_invalid_chars = re.compile(r"[^a-zA-Z0-9_(),& -]+").sub
def transform_name_to_id(name: str, lower: bool = True) -> str:
"""
Transform a name into an identifier by replacing consecutive
invalid characters by a single white space, and then whitespaces
@laurent-laporte-pro
laurent-laporte-pro / big_matrix_benchmark.py
Last active August 30, 2023 07:58
2D-NumPy Matrix Benchmark: Measuring Read/Write Times and Memory Usage
import json
import multiprocessing
import sys
import time
import typing as t
import typing_extensions as te
from pathlib import Path
import numpy as np
import pandas as pd