Skip to content

Instantly share code, notes, and snippets.

View Zebartin's full-sized avatar
:octocat:
Vegetable - Verified by GitHub

Zebartin

:octocat:
Vegetable - Verified by GitHub
View GitHub Profile
@Zebartin
Zebartin / resize-image.py
Created July 29, 2023 13:18
Python: resize image to specified file size
from io import BytesIO
from pathlib import Path
from PIL import Image
def resize_image(image_path: Path, max_size: int=3*1024*1024):
if image_path.stat().st_size <= max_size:
return image_path.read_bytes()
img = Image.open(image_path)
@Zebartin
Zebartin / extract_7z.py
Last active September 25, 2024 12:33
Python: extract files using 7z
import shutil
import subprocess
from pathlib import Path
def extract_file(file_path: Path, target_path: Path, password=None, remove_original=False):
if isinstance(password, str):
password = [password]
for pwd in password:
cmd = [shutil.which('7z'), 'x',
Python 18 hrs 30 mins β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 48.8%
JavaScript 11 hrs 9 mins β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 29.4%
Other 3 hrs 32 mins β–ˆβ–‰β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 9.3%
YAML 2 hrs 37 mins β–ˆβ–β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 6.9%
TOML 1 hr 39 mins β–‰β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ 4.4%