Skip to content

Instantly share code, notes, and snippets.

View SylvanG's full-sized avatar

Sylvan SylvanG

View GitHub Profile
@SylvanG
SylvanG / dedup.py
Created January 5, 2025 09:40
A Python script for identifying and managing duplicate files in a directory, specifically targeting files with patterns like filename(1).ext. The script safely handles duplicates by comparing file sizes, respecting macOS tags, and moving files to a trash directory instead of permanent deletion. It includes error handling and logging to ensure sa…
#!/usr/bin/env python3
import re
from collections import defaultdict
from pathlib import Path
import shutil
from typing import Generator
import logging
import xattr
@SylvanG
SylvanG / extract_thumbnail.py
Created December 25, 2024 03:38
Extract thumbnails from broken images (images that cannot be downloaded but can be viewed from Quicklook)
#!/usr/bin/env python
# This script is to extract existing thumbnail from a picture
# file. (rather than create a new thumbnail)
from collections.abc import Iterable
from pathlib import Path
import subprocess
@SylvanG
SylvanG / cli_helper.py
Created November 4, 2024 03:57
CliHelper facilitates create commands that require a class instance and command on its method. It uses Typer as underlying CLI library. Typer provides infer arguments & options from Python Typing Annotaion. However, there is no good way to get rid of the object initialization and self instance pass. It will be redundant to write all arguments tw…
import functools
import inspect
from collections import OrderedDict, defaultdict
from collections.abc import Mapping
from inspect import Parameter
from typing import Callable, get_type_hints
import typer