Skip to content

Instantly share code, notes, and snippets.

@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 May 1, 2025 05:35
Helps the user construct a Git commit message interactively.
gitmsg () {
read -r "type?Type (feat/fix/refactor/docs/test/chore/style): "
read -r "desc?Description: "
read -r "file?File name: "
msg="${type}: ${desc} (${file})"
echo "git commit -m '${msg}'"
}
@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.