Skip to content

Instantly share code, notes, and snippets.

@yeiichi
yeiichi / ruby_remover.py
Created April 15, 2025 08:38
Clean a BeautifulSoup object by removing ruby-related annotations.
#!/usr/bin/env python3
from bs4 import BeautifulSoup
# Constant for ruby-related annotation tags
RUBY_ANNOTATION_TAGS = ['rt', 'rp']
def clean_ruby_annotations(soup: BeautifulSoup) -> BeautifulSoup:
"""
Cleans a BeautifulSoup object by removing ruby-related annotations.
@yeiichi
yeiichi / chardet_ja.py
Created April 15, 2025 07:15
Class for detecting the character encoding of files.
#!/usr/bin/env python3
import subprocess
from argparse import ArgumentParser
from charset_normalizer import from_path
class ChardetJa:
"""Class for detecting the character encoding of files.
@yeiichi
yeiichi / make_labeled_matrix.py
Created April 15, 2025 01:49
Make a labeled matrix with specified rows, columns, and prefix for labels.
#!/usr/bin/env python3
from argparse import ArgumentParser
from pprint import pprint
from typing import List
COLOR_Y = "\033[93m"
COLOR_0 = "\033[0m"
def make_labeled_matrix(num_rows: int, num_cols: int, prefix: str = 'a') -> List[List[str]]:
@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 17, 2025 00:38
Quickstart script for generic project directories with Sphinx documentation.
#!/usr/bin/env python3
"""
Quickstart script for Generic project.
This Python script, `pj_quickstart.py`, automates the creation of a generic
project directory structure. It also integrates Sphinx documentation and
performs additional configuration tasks.
"""
import argparse
import shutil
import subprocess
@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() != '']