Skip to content

Instantly share code, notes, and snippets.

@yeiichi
yeiichi / add_fiscal_year_to_csv.py
Created April 24, 2025 06:48
Add a fiscal year column to a CSV file based on dates.
#!/usr/bin/env python3
"""
Add a fiscal year column to a CSV file based on dates,
supporting both US and Japanese fiscal calendar systems.
"""
import argparse
from datetime import datetime
from pathlib import Path
import pandas as pd
@yeiichi
yeiichi / char_name_displayer.py
Last active April 24, 2025 03:32
Display Unicode information for input string.
#!/usr/bin/env python3
"""Display Unicode information for input string."""
import sys
import unicodedata
from argparse import ArgumentParser
from dataclasses import dataclass
from typing import List, TextIO
@dataclass
@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..."