Skip to content

Instantly share code, notes, and snippets.

@yeiichi
yeiichi / eml_viewer.zsh
Last active August 27, 2026 23:25
Read RFC 5322 email message files from the shell
#!/usr/bin/env zsh
# eml_viewer.zsh
#
# Defines `view_eml`, a small helper for reading RFC 5322 email message files
# from the shell.
#
# Usage:
# # Add this file's contents to `.ztools`, then load `.ztools` from `~/.zshrc`:
# source "${HOME}/.ztools"
@yeiichi
yeiichi / parse_eml_string.py
Last active August 17, 2026 00:57
Parse MIME email stored as a Python string, with tolerant charset decoding and mojibake repair
from __future__ import annotations
from email import policy
from email.header import decode_header
from email.message import Message
from email.parser import BytesParser
from typing import Any
def _decode_header(value: str | None) -> str:
@yeiichi
yeiichi / image_metadata_privacy_checker.py
Created August 15, 2026 06:39
Lightweight image metadata privacy checker for GPS and sensitive EXIF fields
"""
Lightweight image metadata privacy checker.
Checks common metadata exposed through Pillow, including GPS and potentially
identifying EXIF fields.
This is not a complete forensic metadata audit. For broader coverage of EXIF,
XMP, IPTC, HEIF, and application-specific metadata, use ExifTool:
https://exiftool.org/
"""
@yeiichi
yeiichi / positive_gaussian_samples.py
Last active July 31, 2026 02:34
Generate positive gaussian samples
import random
from typing import List
def generate_positive_gaussian_samples(
mean: float,
approx_upper_bound: int,
trial_number: int,
) -> List[float]:
if trial_number < 0:
@yeiichi
yeiichi / poisson_histogram_app.html
Created July 31, 2026 02:00
Generate random count values from a Poisson distribution and display the histogram
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Poisson Histogram Generator</title>
<style>
:root {
color-scheme: light;
--bg: #f6f7f9;
@yeiichi
yeiichi / gauss_histogram_app.html
Created July 31, 2026 01:59
Generate random values from a normal distribution and display the histogram
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Gaussian Histogram Generator</title>
<style>
:root {
color-scheme: light;
--bg: #f6f7f9;
@yeiichi
yeiichi / generate_numbers_csv.py
Created May 5, 2026 01:31
Generate a CSV-ready table of number attributes.
from __future__ import annotations
from math import isqrt
# An example for a typical downstream usage is available at the bottom of the page.
def is_prime(n: int) -> bool:
if n < 2:
return False
if n == 2:
@yeiichi
yeiichi / webarchive_to_html.py
Created April 17, 2026 07:56
Extract HTML and resources from an Apple .webarchive file using Python's plistlib
#!/usr/bin/env python3
"""
webarchive_to_html.py
Extract HTML and resources from an Apple .webarchive file using Python's plistlib,
then rewrite common resource links for better offline viewing.
Usage:
python webarchive_to_html.py input.webarchive
python webarchive_to_html.py input.webarchive -o output_dir
@yeiichi
yeiichi / whitespace_removers.py
Created March 30, 2026 09:05
Remove whitespace from text using different strategies
import re
class WhitespaceRemover:
"""Remove whitespace from text using different strategies.
All methods remove *Unicode whitespace* (not just ASCII spaces).
Choose a method based on readability, performance, and workload size.
"""
@yeiichi
yeiichi / zsh-venv-prompt.zsh
Created March 26, 2026 12:07
Configures a dynamic Zsh prompt that displays the current Python virtual environment name without breaking standard formatting
# Set up the prompt
# 1. This MUST be here for the $(...) or ${...} to work
setopt PROMPT_SUBST
# 2. Tell the venv script not to mess with the prompt
export VIRTUAL_ENV_DISABLE_PROMPT=1
# 3. The prompt string (no spaces inside the parentheses)
PROMPT='${VIRTUAL_ENV:+(${VIRTUAL_ENV:t}) }%m:%1~ %# '