Skip to content

Instantly share code, notes, and snippets.

@yeiichi
yeiichi / apt-repair-clean.mk
Created February 13, 2026 01:06
Repair and clean apt installed packages
# 1. Configures unpacked packages
# 2. Fixes broken dependencies
# 3. Removes unused packages
# 4. Clears out the local repository of retrieved package files
repair-clean: ##
@sudo dpkg --configure -a && \
sudo apt install -f && \
sudo apt autoremove -y && \
sudo apt autoclean
@yeiichi
yeiichi / Makefile_rsync.mk
Last active February 7, 2026 07:06
Selective JSON/JSONL sync with preserved directory structure
# --- Configuration ---
SOURCE_DIR := /path/to/src/
DEST_HOST := host_name_in_ssh_config
DEST_PATH := /path/to/dest
# --- Flags ---
# -a: Archive (preserve permissions/times)
# -v: Verbose (see what's happening)
# -z: Compress (faster over network)
# -R: Relative (ensures directory structure is preserved)/Don't use -> redundant in this context
@yeiichi
yeiichi / Mekefie_mysql.mk
Created January 29, 2026 08:19
FreeBSD-friendly Makefile for mysql
# --- Configuration Constants ---
DB_HOST ?= mysql.example.com
DB_NAME ?= dbname
DB_USER ?= dbuser
BACKUP_DIR ?= ./backups
DATE := $(shell date +%Y-%m-%d_%H-%M-%S)
# Restore settings
# Usage: make restore RESTORE_FILE=./backups/xxx.sql.gz
RESTORE_FILE ?=
@yeiichi
yeiichi / dataframe_stripper.py
Created January 15, 2026 07:17
Strip leading and trailing whitespace from DataFrame string cells, leaving other types unchanged
def strip_df(df):
"""Strip leading and trailing whitespace from DataFrame string cells, leaving other types unchanged."""
return df.map(lambda s: s.strip() if isinstance(s, str) else s)
@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