Skip to content

Instantly share code, notes, and snippets.

View lebrice's full-sized avatar

Fabrice Normandin lebrice

View GitHub Profile
@lebrice
lebrice / conditional_fields.py
Last active November 23, 2023 18:12
Conditional dataclass fields. The default_factory can now take as an argument the value of other fields on the dataclass.
from __future__ import annotations
import inspect
from dataclasses import dataclass, field, Field, fields
from typing import Any, Callable, TypeVar, overload
from logging import getLogger as get_logger
logger = get_logger("conditional_fields")
T = TypeVar("T")
@lebrice
lebrice / arxiv_id_to_name.py
Last active September 13, 2023 06:55
A simple tool to add the name of downloaded paper pdf's in front of the id. Also removes duplicate downloads of the same arxiv paper.
"""A simple tool to add the name of downloaded paper pdf's in front of the id.
(Written by fabrice.normandin@gmail.com)
If there are multiple downloads of same paper, replaces the original with the
latest download. This can be useful in a downloads folder filled with copies.
For instance:
"""
import glob