Skip to content

Instantly share code, notes, and snippets.

@yeiichi
yeiichi / convert_to_link.zsh
Created April 9, 2025 02:15
Sphinx: regex for converting list items into hyperlinks.
@yeiichi
yeiichi / gz_smart_cat.zsh
Created April 7, 2025 06:20
sed & awk for gzip-ed text files.
#!/usr/bin/env zsh
# sed & awk for gzip-ed text files.
# The `zsmartcat` function reads the contents of a file, but it intelligently
# handles files that are either:
# 1. Gzip-compressed files (e.g., `.gz` files).
# 2. Regular text files (uncompressed files).
# The function decides whether to use `zcat` (to extract and display
# a gzip-compressed file) or the standard `cat` command (to display
# an uncompressed text file), based on the file type.
@yeiichi
yeiichi / pj_quickstart.py
Last active April 30, 2025 08:56
Quickstart script for generic project directories with Sphinx documentation.
#!/usr/bin/env python3
"""
Quickstart script for a Generic project.
This Python script automates the creation of a generic project directory structure
with Sphinx documentation integration.
"""
import argparse
import shutil
import subprocess
from dataclasses import dataclass
@yeiichi
yeiichi / concat_any_csv.py
Last active March 27, 2025 11:06
Handles concatenation of multiple CSV files in a specified directory into a single CSV file.
#!/usr/bin/env python3
from datetime import datetime
from pathlib import Path
import pandas as pd
class ConcatCSV:
"""
Handles concatenation of multiple CSV files in a specified directory into a single CSV file.
@yeiichi
yeiichi / app_menu_tmpl.zsh
Created March 12, 2025 00:29
Interactive app menu for zsh
#!/usr/bin/env zsh
# Interactive app menu for zsh.
# Define colors
YELLOW="\033[93m"
RESET="\033[0m"
# Function to execute App. A, B, and C
do_something_A() {
echo "Doing something A..."
@yeiichi
yeiichi / gauss_dist_checker.py
Created March 7, 2025 08:11
Check N(mu, sigma) distribution visually.
#!/usr/bin/env python3
import matplotlib.pyplot as plt
from random import gauss
NUM_SAMPLES = 128
def plot_gaussian_distribution(mu: float, sigma: float) -> None:
"""Check N(mu, sigma) distribution visually."""
@yeiichi
yeiichi / split_n_strip.py
Created March 5, 2025 05:10
Split a string into a list of non-empty, stripped substrings.
#!/usr/bin/env python3
def split_n_strip(str_in: str, sep: str = ';') -> list[str]:
"""
Split a string into a list of non-empty, stripped substrings.
"""
return [s.strip() for s in str_in.split(sep) if s.strip() != '']
@yeiichi
yeiichi / create_blank_png.py
Created February 16, 2025 04:25
Create a blank PNG image with a test string—A code written by ChatGPT o3-mini-high.
#!/usr/bin/env python3
from PIL import Image, ImageDraw, ImageFont
"""
Create a blank PNG image with a test string—A code written by ChatGPT o3-mini-high.
This script is created by ChatGPT o3-mini-high with the following prompt:
Objective: Write a Python code that creates a PNG file.
Specification:
- Ask the user for the dimension of the image.
@yeiichi
yeiichi / find_dup_files.py
Last active February 12, 2025 06:16
Class for detecting duplicate files based on their hash values.
#!/usr/bin/env python3
import csv
from collections import Counter
from datetime import datetime
from pathlib import Path
from list_files_sha256 import hash_by_256, list_fpaths_in_dir
class FindDupFile:
@yeiichi
yeiichi / list_files_sha256.py
Last active February 13, 2025 05:59
Create a filename / sha256 checksum list and save as a CSV file.
#!/usr/bin/env python3
import csv
from hashlib import sha256
from pathlib import Path
def hash_by_256(fpath):
"""
Computes a SHA-256 hash of a file using variable chunk sizes based on file size.