Skip to content

Instantly share code, notes, and snippets.

@yeiichi
yeiichi / display-running-apps.sh
Created November 12, 2025 22:36
Lists currently running GUI apps on macOS (like Command–L App Switcher)
#!/bin/zsh
# display-running-apps.sh
# Lists currently running GUI apps on macOS (like Command–L App Switcher)
osascript <<'EOF' | tr ',' '\n' | sed 's/^ *//; s/ *$//'
tell application "System Events"
set app_list to (name of every process whose background only is false)
end tell
return app_list
EOF
@yeiichi
yeiichi / make_django_docker_template_kit.sh
Created November 9, 2025 05:37
Automates the creation of a reusable Django + Docker Compose template kit
#!/usr/bin/env bash
# ==============================================================================
# make_django_docker_template_kit.sh
# ------------------------------------------------------------------------------
# PURPOSE:
# Automates the creation of a reusable **Django + Docker Compose** template kit.
# Generates all directories and placeholder files needed to start a new
# containerized Django project, including Docker, Compose, Makefile, and docs.
#
# USAGE:
@yeiichi
yeiichi / Makefile.django-docker-helper.mk
Created November 9, 2025 01:04
Helper Makefile for Django + Docker Compose development
# language: Makefile
# ==============================================================================
# Makefile.django-docker-helper
# ------------------------------------------------------------------------------
# Helper Makefile for Django + Docker Compose development.
#
# PURPOSE:
# - Simplify common Django and Docker workflows.
# - Provide short aliases for build, run, migrate, backup, test, and more.
# - Encourage consistent developer operations across environments.
@yeiichi
yeiichi / knapsack_simple.py
Created October 1, 2025 02:06
Compute the maximum achievable subset sum not exceeding `capacity` (0/1 subset sum)
from typing import List, Tuple
def _reconstruct_subset(items: List[int], reachable_history: List[int], target_sum: int) -> List[int]:
"""
Reconstruct one subset of `items` that achieves `target_sum` using the
saved DP snapshots in `reachable_history`.
"""
subset: List[int] = []
cur_sum = target_sum
@yeiichi
yeiichi / infer_csv_schema.py
Created September 11, 2025 00:03
Analyze and infer SQL types for columns in CSV files
#!/usr/bin/env python3
"""
This module provides a class and utility functions to analyze and infer SQL
types for columns in CSV files via statistical and datatype examination.
It handles various datatypes like integers, floats, booleans, dates, and
timestamps while accommodating dialect-specific SQL type mappings. Additional
functionality includes updating statistics across data chunks, robustness
against missing or invalid data, and generation of NULL/NOT NULL constraints.
"""
@yeiichi
yeiichi / csv_classifier.py
Created September 7, 2025 22:05
Classify CSV files by strict header match and move them to mapped destinations
#!/usr/bin/env python3
"""
A tool for classifying and moving CSV files based on column headers.
This script processes CSV files by matching their headers against predefined
layouts. Depending on the matched layout, the files are moved to their
corresponding destination directories. The script supports both file-based
and directory-based classification and offers options for dry-run execution,
recursion, and verbose output.
@yeiichi
yeiichi / excel_concatenator.py
Created August 24, 2025 03:36
Combine all `.xlsx` files present in a specified directory
#!/usr/bin/env python3
"""
A program to concatenate Excel files in a directory.
This script combines all `.xlsx` files present in a specified directory, ensuring
they each have identical and consistent columns (order-sensitive). The combined
data is written into a single output Excel file. Additionally, duplicate rows are
dropped from the final result, and the index is reset. An output file name can
either be provided via the command-line arguments or auto-generated based on
the current timestamp.
@yeiichi
yeiichi / excel_table_inserter.py
Created August 23, 2025 06:14
Insert an Excel Table covering the contiguous data range in the worksheet
#!/usr/bin/env python3
from __future__ import annotations
import argparse
from pathlib import Path
from openpyxl import load_workbook
from openpyxl.utils import get_column_letter
from openpyxl.workbook.workbook import Workbook
from openpyxl.worksheet.table import Table, TableStyleInfo
@yeiichi
yeiichi / cron-safe-runner.bash
Last active August 10, 2025 13:27
Bash wrapper to run a Python script using a virtual environment.
#!/usr/bin/env bash
# shellcheck shell=bash
# Bash wrapper to run Python scripts using a virtual environment.
set -Eeuo pipefail
# Constants
readonly HOME_DIR="${HOME}"
readonly VENV_DIR="${HOME_DIR}/path/to/venv"
readonly VENV_BIN="${VENV_DIR}/bin"
@yeiichi
yeiichi / normalize_missing.py
Created July 26, 2025 12:50
Normalize missing-like values to Python None for PostgreSQL or general use
#!/usr/bin/env python3
import pandas as pd
import numpy as np
def normalize_missing(
df: pd.DataFrame,
targets=None,
columns=None,
output_dtype="object"
) -> pd.DataFrame: