Skip to content

Instantly share code, notes, and snippets.

View ThomasParistech's full-sized avatar
🚴

Thomas Rouch ThomasParistech

🚴
View GitHub Profile
@ThomasParistech
ThomasParistech / players_info.py
Last active January 14, 2022 20:18
Secret Santa: players info
# /usr/bin/python3
"""Players info."""
import json
from dataclasses import dataclass, field
from typing import Iterator, List
@dataclass
class PlayerInfo:
email: str
@ThomasParistech
ThomasParistech / email_sender.py
Last active January 14, 2022 21:04
Secret Santa: email sender
# /usr/bin/python3
"""Email sender."""
import smtplib
from dataclasses import dataclass
from email.mime.text import MIMEText
from typing import Tuple, List
from players_info import ListOfPlayerInfo
@dataclass
class EmailSender:
@ThomasParistech
ThomasParistech / _init_possible_recipients.py
Created January 15, 2022 09:07
Secret santa _init_possible_recipients
from players_info import ListOfPlayerInfo
from typing import List
def _init_possible_recipients(players: ListOfPlayerInfo) -> List[List[int]]:
"""
Apply inclusion and exclusion lists
to get all possible recipients for each player.
"""
all_names = [player.name for player in players]
possible_ids: List[List[int]] = [
@ThomasParistech
ThomasParistech / _refine_possible_recipients.py
Created January 15, 2022 09:21
Secret santa _refine_possible_recipients
from typing import List
from players_info import ListOfPlayerInfo
def _refine_possible_recipients(possible_ids: List[List[int]]) -> List[List[int]]:
"""
Find players with a single possible recipient
and remove this recipient from the possibilities of the other players
"""
known_players = [idx for idx, list_ids in enumerate(possible_ids)
if len(list_ids) == 1]
@ThomasParistech
ThomasParistech / backtracking.py
Last active January 15, 2022 09:55
Secret santa: backtracking
from typing import List, Optional
from players_info import ListOfPlayerInfo
def _backtrack(possible_ids: List[List[int]],
current_id_chain: List[int]) -> bool:
"""
Explore all possible paths by iterating over players' possibilities.
"""
if len(current_id_chain) == len(possible_ids):
@ThomasParistech
ThomasParistech / secret_santa.py
Created January 15, 2022 10:13
Secret santa final
import fire
from email_sender import EmailSender
from players_info import ListOfPlayerInfo
def main(players_json: str,
mail_address: str,
mail_pwd: str,
mail_txt: str):
"""
import json
from typing import Dict
from typing import List
from typing import Union
def export_profiling_events(output_path: str):
"""
Dump profiling events into a JSON file that can be provided
to the Chrome Tracing Viewer
# /usr/bin/python3
"""Profile Image rotation"""
import cv2
import numpy as np
from profiler import export_profiling_events
from profiler import profile
@profile
import math
import multiprocessing
from typing import Optional
import imagesize
import psutil
from psutil._common import bytes2human
def bytes_of_uint8_img(img_path: str, colored: bool) -> int:
# /usr/bin/python3
"""Process files in parallel."""
import math
from typing import Callable
from typing import Dict
from typing import List
from typing import Optional
from typing import Union
import numpy as np