Skip to content

Instantly share code, notes, and snippets.

@yeiichi
yeiichi / csvbookconv.py
Created May 22, 2025 08:59
Combine multiple CSV files into a single Excel workbook.
#!/usr/bin/env python3
# Combine multiple CSV files into a single Excel workbook.
import re
from dataclasses import dataclass
from pathlib import Path
import pandas as pd
from openpyxl import Workbook
from openpyxl.workbook.views import BookView
@yeiichi
yeiichi / days-since.sh
Last active May 19, 2025 00:32
Echo how many calendar days have passed between the REFERENCE_DATE and today.
#!/usr/bin/env sh
# Echo how many calendar days have passed between the REFERENCE_DATE and today.
readonly REFERENCE_DATE='2025-01-01'
readonly SECONDS_PER_DAY=86400
error_exit() {
echo "$1" >&2
exit "${2:-1}"
}
@yeiichi
yeiichi / gpg_json_reader.py
Last active May 5, 2025 02:27
Read, decrypt, and parse JSON data from a GPG-encrypted JSON file.
#!/usr/bin/env python3
import json
import os
import shutil
import subprocess
from pathlib import Path
class GPGJSONReaderError(Exception):
@yeiichi
yeiichi / gnupg_wrapper.py
Created May 2, 2025 00:27
A class that provides a simplified interface for common GPG operations.
#!/usr/bin/env python3
"""
A class that provides a simplified interface for common GPG operations
like encryption, decryption, signing, and key management. `GPGWrapper`
"""
from functools import wraps
from pathlib import Path
from typing import Optional, List, Dict, Any, Callable
import gnupg
@yeiichi
yeiichi / git_commit_helper.zsh
Last active December 25, 2025 05:17
Helps the user construct a Git commit message interactively.
gitmsg() {
local allowed="init feat fix refactor chore docs test ci build"
echo "Allowed types: $allowed"
read -r "type?Type: "
if ! echo "$allowed" | grep -qw "$type"; then
echo "Invalid type: '$type'"
echo "Allowed: $allowed"
return 1
@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]]: