Skip to content

Instantly share code, notes, and snippets.

@slavanap
slavanap / check_psnr.py
Created January 8, 2025 06:46
Transcode audio files to MP3 with PSNR check
import numpy as np
from pydub import AudioSegment
# ffmpeg -fflags +genpts -i 008.wma -sample_fmt s16p -b:a 320k 008.mp3
def load_audio(file_path):
"""
Load an audio file and convert it to a NumPy array.
"""
audio = AudioSegment.from_file(file_path)
@slavanap
slavanap / unzip-decode.py
Created January 8, 2025 06:43
Unzip files packed in systems non-standard encoding (shiftjis in particular)
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import datetime
import os
import shutil
import time
import zipfile
@slavanap
slavanap / filesizes.sh
Created January 8, 2025 06:41
Compute file sizes stats in $PWD
#!/bin/bash
LC_ALL=C find . -name '?*.*' -type f -printf '%b.%f\0' | LC_ALL=C gawk -F . -v RS='\0' '
{s[$NF] += $1; n[$NF]++}
END {
PROCINFO["sorted_in"] = "@val_num_asc"
for (e in s) printf "%15d %4d %s\n", s[e]*512, n[e], e
}'
@slavanap
slavanap / slurp.py
Last active January 23, 2025 16:52
Slurp a file into stdout. Disk space is freed as soon as contents are read
#!/usr/bin/env python3
import argparse
import os
import sys
from ctypes import *
FALLOC_FL_KEEP_SIZE = 0x01
FALLOC_FL_PUNCH_HOLE = 0x02