Skip to content

Instantly share code, notes, and snippets.

@yeiichi
yeiichi / column_contract_typA.csv
Created January 7, 2026 00:58
Semantic contract for long-format datasets (Type A)
Column Type Meaning Rules
entity string Thing being measured Stable label, not human prose
variable string What is measured Atomic, no units
value numeric Measured value Float/decimal only
unit string Measurement unit %, g/100g, mg/L, etc.
basis string Unit basis w/w, w/v, dry, as_is
method string Measurement method Optional
source string Source name File/site/report
source_id string Stable source key URL, DOI, hash
observed_at string/date When observed ISO-8601
@yeiichi
yeiichi / mdtable2csv.sh
Created January 7, 2026 00:49
Convert Markdown tables to CSV
#!/usr/bin/env bash
set -euo pipefail
# mdtable2csv: Convert Markdown tables to CSV.
# Handles alignment rows, trims cells, escapes CSV safely, and respects escaped pipes (\|).
mdtable2csv() {
local in out
if [[ $# -lt 1 || $# -gt 2 ]]; then
@yeiichi
yeiichi / django-bootstrap_type_a.sh
Created January 6, 2026 05:46
Create a Django-ish repo (Type_A)
#!/usr/bin/env bash
# Create a Django-ish repo (Type_A)
set -euo pipefail
IFS=$'\n\t'
# --- Config ---
PARENT="${HOME}/name_of_parent_directory"
ROOT="${PARENT}/name_of_django_project"
ENV_DIR="${ROOT}/env"
@yeiichi
yeiichi / makefile_tmpl.mk
Last active December 20, 2025 01:34
Make file template
# ==============================================================================
# PROJECT: [Insert Project Name Here]
# PURPOSE: Standardized Makefile for Python projects using a virtual environment.
# This file defines common commands for setting up, running, and
# cleaning the project.
# USAGE: Type 'make' or 'make help' to see available targets.
# REQUIRES: make, python3, pip (to be run in a shell environment)
# ==============================================================================
# Define variables for the virtual environment and its executables.
@yeiichi
yeiichi / gaussian_generator.py
Created November 19, 2025 00:36
Generate Gaussian-distributed random floats strictly within [a, b] using rejection sampling (no clipping)
import numpy as np
def gaussian_random_reject(a, b, mean=None, std=None, size=1):
"""
Generate Gaussian-distributed random floats strictly within [a, b]
using rejection sampling (no clipping).
Parameters:
a, b : float
@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.
"""