snippets

kobo instapaper override in komga nginx proxy
location / {
  proxy_pass http://komga-upstream;

  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-Scheme $scheme;
  proxy_set_header X-Forwarded-Proto $scheme;
  proxy_read_timeout 90s;
  proxy_buffer_size 128k;
  proxy_buffers 4 256k;
  proxy_busy_buffers_size 256k;
}

location ~* "^/kobo/(.+)/v1/initialization$" {
  proxy_pass http://komga-upstream;

  proxy_set_header Host $host;
  proxy_set_header X-Real-IP $remote_addr;
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header X-Scheme $scheme;
  proxy_set_header X-Forwarded-Proto $scheme;
  proxy_read_timeout 90s;
  proxy_buffer_size 128k;
  proxy_buffers 4 256k;
  proxy_busy_buffers_size 256k;

  sub_filter https://www.instapaper.com "https://sub.example.com/instapaper-proxy/instapaper";
  sub_filter_types application/json;
}
kobo instapaper override in komga nginx proxy
bubblewrap it
#!/bin/bash

set -euo pipefail

# ==============================================================================
# 1. Configuration & Constants
# ==============================================================================
SECRETS_FILE=".bubblewrap"
#CURRENT_USER=$(id -un)
CURRENT_UID=$(id -u)
PROJECT_DIR=$(pwd)

# Standard XDG base directories
LOCAL_BIN="$HOME/.local/bin"
LOCAL_SHARE="$HOME/.local/share"
LOCAL_STATE="$HOME/.local/state"
LOCAL_CACHE="$HOME/.cache"

# ANSI Terminal Escape Sequences
ANSI_RED_BOLD="\033[1;31m"
ANSI_RESET="\033[0m"
ANSI_RESTORE_TERMINAL="\033[?1049l\033[?25h\033[2J\033[3J\033[H"

# ==============================================================================
# 2. Input Validation & Agent Mapping
# ==============================================================================
if [[ $# -eq 0 ]]; then
    echo "❌ error: no command provided."
    echo "💡 usage: $0 <command> [args...]"
    echo "   example: $0 pi --prompt 'hello'"
    exit 1
fi

BASE_CMD="$1"
AGENT_TARGETS=("$BASE_CMD")

case "$BASE_CMD" in
    agy)
        AGENT_TARGETS+=("gemini")
        ;;
    claude|gemini|opencode|pi)
        # Direct 1:1 mapping
        ;;
    *)
        echo "❌ error: unsupported agent command '$BASE_CMD'."
        echo "💡 supported commands: agy, claude, gemini, opencode, pi"
        exit 1
        ;;
esac

# ==============================================================================
# 3. Mount Construction
# ==============================================================================

# Global development toolchains and editor runtime directories
GLOBAL_DEV_DIRS=(
    "$HOME/.local/share/mise"
    "$HOME/.config/mise"
    "$HOME/.config/nvim"
    "$HOME/.local/share/nvim"
    "$HOME/.local/state/nvim"
    "$LOCAL_BIN"
    "$LOCAL_SHARE"
)

GLOBAL_BINDS=()
for dir in "${GLOBAL_DEV_DIRS[@]}"; do
    [[ -d "$dir" ]] && GLOBAL_BINDS+=("--bind" "$dir" "$dir")
done

# Dynamic bindings for agent configuration, state, and cache paths
AGENT_BINDS=()
for agent in "${AGENT_TARGETS[@]}"; do
    for path in \
        "$HOME/.$agent" \
        "$HOME/.${agent}.json" \
        "$HOME/.config/$agent" \
        "$LOCAL_STATE/$agent" \
        "$LOCAL_CACHE/$agent" \
        "$LOCAL_SHARE/$agent"
    do
        [[ -e "$path" ]] && AGENT_BINDS+=("--bind" "$path" "$path")
    done
done

# Secret masking: isolate directories via tmpfs and mask files via empty ro-bind
MASK_ARGS=()
declare -A SECRET_BASELINE_INODES=()
EMPTY_MASK_FILE=""
TRIPWIRE_TRIGGER_FILE=$(mktemp /tmp/bwrap_alert.XXXXXX)

if [[ -f "$SECRETS_FILE" ]]; then
    echo "🔍 scanning for secrets..."
    EMPTY_MASK_FILE=$(mktemp /tmp/bwrap_mask.XXXXXX)
    touch "$EMPTY_MASK_FILE"

    while IFS= read -r line || [[ -n "$line" ]]; do
        item=$(echo "$line" | sed 's/#.*//' | xargs)
        [[ -z "$item" ]] && continue

        target="$PROJECT_DIR/$item"
        if [[ -d "$target" ]]; then
            MASK_ARGS+=("--tmpfs" "$target")
            echo "🔒 [masked dir]  $item"
        elif [[ -f "$target" || -L "$target" ]]; then
            MASK_ARGS+=("--ro-bind" "$EMPTY_MASK_FILE" "$target")
            SECRET_BASELINE_INODES["$target"]=$(stat -c "%i" "$target" 2>/dev/null || echo "0")
            echo "🔒 [masked file] $item"
        fi
    done <"$SECRETS_FILE"
fi

# ==============================================================================
# 4. Lifecycle Management & Inode Sentinel
# ==============================================================================
WATCHER_PID=""

# shellcheck disable=SC2329
cleanup() {
    [[ -n "$WATCHER_PID" ]] && kill "$WATCHER_PID" 2>/dev/null || true
    [[ -n "$EMPTY_MASK_FILE" && -f "$EMPTY_MASK_FILE" ]] && rm -f "$EMPTY_MASK_FILE"
    [[ -n "$TRIPWIRE_TRIGGER_FILE" && -f "$TRIPWIRE_TRIGGER_FILE" ]] && rm -f "$TRIPWIRE_TRIGGER_FILE"
    stty sane 2>/dev/null || true
}
trap cleanup EXIT INT TERM

# Background sentinel: detects host-side atomic file saves / inode replacements
if [[ ${#SECRET_BASELINE_INODES[@]} -gt 0 ]]; then
    (
        while true; do
            sleep 0.5
            for path in "${!SECRET_BASELINE_INODES[@]}"; do
                current_inode=$(stat -c "%i" "$path" 2>/dev/null || echo "0")
                if [[ "$current_inode" != "${SECRET_BASELINE_INODES[$path]}" ]]; then
                    echo "$path" > "$TRIPWIRE_TRIGGER_FILE"
                    pkill -9 -P "$$" 2>/dev/null || true
                    exit 0
                fi
            done
        done
    ) &
    WATCHER_PID=$!
    disown "$WATCHER_PID" 2>/dev/null || true
fi

# ==============================================================================
# 5. Sandbox Execution
# ==============================================================================
echo "🛡️ sandbox [activating: $PROJECT_DIR with command: $BASE_CMD]"

set +e
bwrap \
    --unshare-all \
    --share-net \
    --die-with-parent \
    --proc /proc \
    --new-session \
    --dev /dev \
    --tmpfs /tmp \
    \
    --dir "/run/user/$CURRENT_UID" \
		--ro-bind-try "/run/user/$CURRENT_UID/bus" "/run/user/$CURRENT_UID/bus" \
    --dir /var \
    --dir /run/systemd/resolve \
    --dir "$HOME" \
    \
    --ro-bind /usr /usr \
    --ro-bind /bin /bin \
    --ro-bind /lib /lib \
    --ro-bind /lib64 /lib64 \
    --ro-bind /etc /etc \
    --ro-bind /sys /sys \
    --ro-bind-try /run/systemd/resolve/stub-resolv.conf /run/systemd/resolve/stub-resolv.conf \
    \
    --bind "$PROJECT_DIR" "$PROJECT_DIR" \
    "${MASK_ARGS[@]}" \
    "${GLOBAL_BINDS[@]}" \
    "${AGENT_BINDS[@]}" \
    \
		--setenv DBUS_SESSION_BUS_ADDRESS "${DBUS_SESSION_BUS_ADDRESS:-unix:path=/run/user/$CURRENT_UID/bus}" \
    --setenv XDG_RUNTIME_DIR "/run/user/$CURRENT_UID" \
    --setenv XDG_RUNTIME_DIR "/run/user/$CURRENT_UID" \
    --setenv PS1 "bwrap$ " \
    --setenv HOME "$HOME" \
    --setenv PATH "$PATH" \
    --setenv EDITOR "nvim" \
    --setenv LANG "${LANG:-C.UTF-8}" \
    --setenv TERM "$TERM" \
    \
    --chdir "$PROJECT_DIR" \
    \
    "$@"
EXIT_STATUS=$?
set -e

# ==============================================================================
# 6. Tripwire Exit Handling
# ==============================================================================
if [[ -f "$TRIPWIRE_TRIGGER_FILE" && -s "$TRIPWIRE_TRIGGER_FILE" ]]; then
    TRIGGERED_PATH=$(cat "$TRIPWIRE_TRIGGER_FILE")

    stty sane 2>/dev/null || true
    printf "%b" "$ANSI_RESTORE_TERMINAL"
    printf "🚨 %b[SECURITY ALERT]%b Secret modified on host: %s\n" "$ANSI_RED_BOLD" "$ANSI_RESET" "$TRIGGERED_PATH" >&2
    printf "🚨 Terminating sandbox to prevent secret exposure.\n" >&2
    exit 1
fi

echo "🛡️ sandbox [inactive]"
exit "$EXIT_STATUS"
bubblewrap it
functions.css
/**
CSS Extras - A collection of useful CSS custom functions

@author Sindre Sorhus
@license (MIT OR CC0-1.0)
*/

/* ===================================
	 Math & Number Functions
	 =================================== */

/**
Negates a value (returns the negative).

@param {Number} --value - The value to negate.
@returns {Number} The negated value.
@example padding: --negate(1em);
*/
@function --negate(--value) {
	result: calc(-1 * var(--value));
}

/**
Linear interpolation between two values.

@param {Number} --from - Start value.
@param {Number} --to - End value.
@param {Number} --progress - Progress between 0 and 1.
@returns {Number} Interpolated value.
@example width: --lerp(100px, 200px, 0.5);
*/
@function --lerp(--from, --to, --progress) {
	result: calc(var(--from) + (var(--to) - var(--from)) * var(--progress));
}

/**
Maps a value from one range to another.

@param {Number} --value - Input value.
@param {Number} --in-min - Input range minimum.
@param {Number} --in-max - Input range maximum.
@param {Number} --out-min - Output range minimum.
@param {Number} --out-max - Output range maximum.
@returns {Number} Mapped value.
@example font-size: --map-range(50vw, 320px, 1920px, 14px, 24px);
*/
@function --map-range(--value, --in-min, --in-max, --out-min, --out-max) {
	--progress: clamp(0, calc((var(--value) - var(--in-min)) / (var(--in-max) - var(--in-min))), 1);
	result: calc(var(--out-min) + (var(--out-max) - var(--out-min)) * var(--progress));
}

/**
Returns the ratio of two values. Supports values with different units, unlike regular division.

@param {CalcSum} --value - Input value.
@param {CalcSum} --to-value - Another input value.
@returns {Number} The ratio between two values.
@example scale: --ratio(16px, 1em);
*/
@function --ratio(--value, --to-value) {
	result: tan(atan2(var(--value), var(--to-value)));
}

/* ===================================
	 Color Functions
	 =================================== */

/**
Returns a semi-transparent version of any color.

@param {Color} --color - The base color.
@param {Number} --opacity - Opacity value (0-100% or 0-1).
@returns {Color} Color with opacity.
@example background: --opacity(blue, 50%);
*/
@function --opacity(--color, --opacity) {
	result: rgb(from var(--color) r g b / var(--opacity));
}

/**
Lightens a color by mixing with white.

Uses OKLab color space for perceptually uniform mixing.

@param {Color} --color - The base color.
@param {Number} --amount - Amount to lighten (0-100%).
@returns {Color} Lightened color.
@example background: --tint(blue, 20%);
*/
@function --tint(--color, --amount: 10%) {
	result: color-mix(in oklab, var(--color), white var(--amount));
}

/**
Darkens a color by mixing with black.

Uses OKLab color space for perceptually uniform mixing.

@param {Color} --color - The base color.
@param {Number} --amount - Amount to darken (0-100%).
@returns {Color} Darkened color.
@example background: --shade(blue, 20%);
*/
@function --shade(--color, --amount: 10%) {
	result: color-mix(in oklab, var(--color), black var(--amount));
}

/**
Adjusts color saturation.

Uses OKLCH color space for perceptually uniform chroma adjustment. Chroma is clamped to 0.4 for safe display.

@param {Color} --color - The base color.
@param {Number} --amount - Chroma multiplier.
@returns {Color} Adjusted color.
@example color: --saturate(red, 1.5);
*/
@function --saturate(--color, --amount: 1.2) {
	result: oklch(from var(--color) l clamp(0, calc(c * var(--amount)), 0.4) h);
}

/**
Adjusts color lightness.

Uses OKLCH color space for perceptually uniform lightness adjustment. Maintains chroma independently.

@param {Color} --color - The base color.
@param {Number} --amount - Lightness adjustment (-100% to 100%).
@returns {Color} Adjusted color.
@example background: --lighten(blue, 20%);
*/
@function --lighten(--color, --amount: 10%) {
	result: oklch(from var(--color) clamp(0, calc(l + var(--amount) / 100%), 1) c h);
}

/**
Darkens a color by reducing lightness.

Uses OKLCH color space for perceptually uniform lightness adjustment. Unlike `--shade()` which mixes with black, this directly reduces the lightness value.

@param {Color} --color - The base color.
@param {Number} --amount - Lightness reduction (0-100%).
@returns {Color} Darkened color.
@example background: --darken(blue, 20%);
*/
@function --darken(--color, --amount: 10%) {
	result: oklch(from var(--color) clamp(0, calc(l - var(--amount) / 100%), 1) c h);
}

/**
Rotates the hue of a color.

Uses OKLCH color space for perceptually uniform hue rotation.

@param {Color} --color - The base color.
@param {Angle} --degrees - Degrees to rotate hue.
@returns {Color} Color with rotated hue.
@example background: --rotate-hue(blue, 180deg);
*/
@function --rotate-hue(--color, --degrees: 30deg) {
	result: oklch(from var(--color) l c calc(h + var(--degrees)));
}

/**
Returns the complementary color.

Uses OKLCH color space for perceptually accurate complementary colors.

@param {Color} --color - The base color.
@returns {Color} Complementary color.
@example border-color: --complement(blue);
*/
@function --complement(--color) {
	result: oklch(from var(--color) l c calc(h + 180deg));
}

/**
Inverts a color.

@param {Color} --color - The color to invert.
@returns {Color} Inverted color.
@example background: --invert(white);
*/
@function --invert(--color) {
	result: rgb(from var(--color) calc(255 - r) calc(255 - g) calc(255 - b) / alpha);
}

/**
Converts a color to grayscale.

Uses OKLCH color space by setting chroma to 0.

@param {Color} --color - The color to convert.
@returns {Color} Grayscale color.
@example filter: --grayscale(var(--brand-color));
*/
@function --grayscale(--color) {
	result: oklch(from var(--color) l 0 h);
}

/*
Uses HWB color space trick: converts to grayscale in OKLCH, then uses HWB's blackness/whiteness values amplified by a large multiplier to create a binary black/white decision based on brightness. This provides excellent contrast decisions without needing numeric luminance extraction.
*/
/**
Returns black or white text color for optimal contrast on a background.

@param {Color} --bg - Background color.
@returns {Color} Black or white for optimal readability.
@example color: --text-on(var(--bg-color));
*/
@function --text-on(--bg) {
	result: hwb(from oklch(from var(--bg) l 0 0) h calc((b - 50) * 999) calc((w - 50) * 999));
}

/**
Removes transparency from a color, making it fully opaque.

@param {Color} --color - Color with alpha channel.
@returns {Color} Fully opaque version of the color.
@example background: --opaque(var(--semi-transparent-bg));
*/
@function --opaque(--color) {
	result: rgb(from var(--color) r g b / 1);
}

/**
Mixes two colors in OKLab color space.

Uses perceptually uniform OKLab color space for natural-looking color mixing.

@param {Color} --color1 - First color.
@param {Color} --color2 - Second color.
@param {Number} --amount - Amount of second color to mix (0-100%).
@returns {Color} Mixed color.
@example background: --mix(red, blue, 30%);
*/
@function --mix(--color1, --color2, --amount: 50%) {
	result: color-mix(in oklab, var(--color1), var(--color2) var(--amount));
}

/**
Returns a triadic color harmony.

Triadic colors are evenly spaced around the color wheel (120° apart).

@param {Color} --color - Base color.
@param {Number} --index - Which triadic color (1 or 2).
@returns {Color} Triadic color.
@example color: --triadic(blue, 1);
*/
@function --triadic(--color, --index: 1) {
	result: oklch(from var(--color) l c calc(h + 120deg * var(--index)));
}

/**
Returns a tetradic (square) color harmony.

Tetradic colors are evenly spaced around the color wheel (90° apart).

@param {Color} --color - Base color.
@param {Number} --index - Which tetradic color (1, 2, or 3).
@returns {Color} Tetradic color.
@example color: --tetradic(blue, 2);
*/
@function --tetradic(--color, --index: 1) {
	result: oklch(from var(--color) l c calc(h + 90deg * var(--index)));
}

/**
Creates a semi-transparent black.

@param {Number} --opacity - Opacity value (0-100% or 0-1).
@returns {Color} Semi-transparent black.
@example box-shadow: 0 2px 4px --black(20%);
*/
@function --black(--opacity: 50%) {
	result: rgb(0 0 0 / var(--opacity));
}

/**
Creates a semi-transparent white.

@param {Number} --opacity - Opacity value (0-100% or 0-1).
@returns {Color} Semi-transparent white.
@example background: --white(90%);
*/
@function --white(--opacity: 50%) {
	result: rgb(255 255 255 / var(--opacity));
}

/* ===================================
	 Typography Functions
	 =================================== */

/**
Creates fluid typography that scales with viewport.

NOTE: This function is mathematically equivalent to `--responsive-value()` but optimized for typography. Use this for `font-size`, `--responsive-value()` for other properties.

@param {Length} --min - Minimum font size.
@param {Length} --max - Maximum font size.
@param {Length} --min-viewport - Minimum viewport width.
@param {Length} --max-viewport - Maximum viewport width.
@returns {Length} Fluid font size.
@example font-size: --fluid-type(16px, 24px, 320px, 1280px);
*/
@function --fluid-type(--min, --max, --min-viewport: 320px, --max-viewport: 1280px) {
	--slope: calc((var(--max) - var(--min)) / (var(--max-viewport) - var(--min-viewport)));
	--intercept: calc(var(--min) - var(--slope) * var(--min-viewport));
	result: clamp(var(--min), calc(var(--intercept) + var(--slope) * 100vw), var(--max));
}

/**
Creates a modular scale value.

@param {Number} --base - Base size.
@param {Number} --ratio - Scale ratio.
@param {Number} --step - Step in the scale.
@returns {Length} Scaled value.
@example font-size: --modular-scale(1rem, 1.25, 3);
*/
@function --modular-scale(--base: 1rem, --ratio: 1.25, --step: 0) {
	result: calc(var(--base) * pow(var(--ratio), var(--step)));
}

/**
Calculates line height as a length value based on font size.

Returns a length (e.g., 24px) rather than a unitless ratio. Use this when you need an absolute line height value.

@param {Length} --font-size - The font size.
@param {Number} --multiplier - Line height multiplier.
@returns {Length} Line height as a length.
@example line-height: --line-height-length(16px, 1.6);
*/
@function --line-height-length(--font-size, --multiplier: 1.5) {
	result: calc(var(--font-size) * var(--multiplier));
}

/**
Calculates line height as a unitless ratio.

Returns a number (e.g., 1.5) which is recommended for better inheritance in CSS.

@param {Length} --line-height - The desired line height as a length.
@param {Length} --font-size - The font size.
@returns {Number} Unitless line height ratio.
@example line-height: --line-height-ratio(24px, 16px);
*/
@function --line-height-ratio(--line-height, --font-size) {
	result: calc(var(--line-height) / var(--font-size));
}

/**
Creates unitless line height from font size (recommended for better inheritance).

NOTE: Only works correctly with pixel font sizes. For rem/em values, use `--line-height-length()` or `--line-height-ratio()` instead.

@param {Length} --font-size - Font size in pixels.
@param {Number} --multiplier - Line height multiplier.
@returns {Number} Unitless line height.
@example line-height: --line-height-unitless(16px, 1.5);
*/
@function --line-height-unitless(--font-size: 16px, --multiplier: 1.5) {
	result: calc(var(--font-size) * var(--multiplier) / 1px);
}

/* ===================================
	 Layout Functions
	 =================================== */

/**
Creates responsive sidebar layout columns.

@param {Length} --sidebar-width - Width of sidebar.
@param {Length} --content-min - Minimum width of content area.
@returns {Length} Grid template columns value.
@example grid-template-columns: --sidebar-layout(250px, 20ch);
*/
@function --sidebar-layout(--sidebar-width: 20ch, --content-min: 20ch) {
	result: minmax(var(--sidebar-width), 1fr) minmax(var(--content-min), 3fr);
}

/**
Conditional border radius that removes at viewport edges.

@param {Length} --radius - Border radius value.
@param {Length} --edge-dist - Distance from viewport edge.
@returns {Length} Computed border radius.
@example border-radius: --conditional-radius(1rem, 8px);
*/
@function --conditional-radius(--radius, --edge-dist: 4px) {
	/* Multiply by large number to amplify small differences, creating binary 0/radius effect */
	result: clamp(0px, ((100vw - var(--edge-dist)) - 100%) * 1e5, var(--radius));
}

/**
Creates a responsive value that scales between two sizes.

NOTE: This function is mathematically equivalent to `--fluid-type()` but uses a simpler lerp-based approach. Use this for spacing/sizing, `--fluid-type()` for typography.

@param {Length} --small - Minimum value.
@param {Length} --large - Maximum value.
@param {Length} --viewport-min - Minimum viewport width.
@param {Length} --viewport-max - Maximum viewport width.
@returns {Length} Responsive value.
@example padding: --responsive-value(1rem, 2rem, 320px, 1200px);
*/
@function --responsive-value(--small, --large, --viewport-min: 320px, --viewport-max: 1200px) {
	--progress: calc((100vw - var(--viewport-min)) / (var(--viewport-max) - var(--viewport-min)));
	--clamped-progress: clamp(0, var(--progress), 1);
	result: calc(var(--small) + (var(--large) - var(--small)) * var(--clamped-progress));
}

/**
Calculates height from aspect ratio and maximum constraints.

@param {Number} --ratio - Aspect ratio (e.g., 16/9).
@param {Length} --max-width - Maximum width.
@param {Length} --max-height - Maximum height.
@returns {Length} Computed height.
@example height: --aspect-height(16/9, 100vw, 100vh);
*/
@function --aspect-height(--ratio: 1, --max-width: 100%, --max-height: 100%) {
	--computed-height: calc(var(--max-width) / var(--ratio));
	result: min(var(--computed-height), var(--max-height));
}

/**
Calculates width from aspect ratio and maximum constraints.

@param {Number} --ratio - Aspect ratio (e.g., 16/9).
@param {Length} --max-height - Maximum height.
@param {Length} --max-width - Maximum width.
@returns {Length} Computed width.
@example width: --aspect-width(16/9, 100vh, 100vw);
*/
@function --aspect-width(--ratio: 1, --max-height: 100%, --max-width: 100%) {
	--computed-width: calc(var(--max-height) * var(--ratio));
	result: min(var(--computed-width), var(--max-width));
}

/* ===================================
	 Spacing Functions
	 =================================== */

/**
Creates consistent spacing based on a scale.

Recommended range: 0-10. Higher values create exponentially larger spacing.

@param {Number} --level - Spacing level (0-10).
@param {Length} --base - Base spacing unit.
@returns {Length} Computed spacing.
@example margin: --spacing(3);
*/
@function --spacing(--level: 1, --base: 0.25rem) {
	result: calc(var(--base) * pow(2, var(--level)));
}

/**
Creates inset spacing for containers.

@param {Length} --padding - Base padding.
@param {Length} --max-width - Maximum container width.
@returns {Length} Responsive padding.
@example padding: --container-padding(2rem, 1200px);
*/
@function --container-padding(--padding: 1rem, --max-width: 1200px) {
	--available: calc(100vw - var(--max-width));
	--side-space: max(var(--padding), calc(var(--available) / 2));
	result: var(--side-space);
}

/* ===================================
	 Animation Functions
	 =================================== */

/**
Creates a simple easing curve value.

@param {Number} --progress - Animation progress (0-1).
@returns {Number} Eased value.
@example transform: translateY(--ease-out(var(--progress)));
*/
@function --ease-out(--progress) {
	--inverse: calc(1 - var(--progress));
	result: calc(1 - var(--inverse) * var(--inverse));
}

/**
Creates elastic easing.

@param {Number} --progress - Animation progress (0-1).
@param {Number} --amplitude - Amplitude of elasticity.
@returns {Number} Eased value.
@example transform: scale(--elastic-ease(var(--progress), 1.2));
*/
@function --elastic-ease(--progress, --amplitude: 1) {
	--p: calc(var(--progress) * 3.14159);
	result: calc(var(--amplitude) * sin(var(--p) * 10) * exp(calc(-5 * var(--progress))));
}

/* ===================================
	 Utility Functions
	 =================================== */

/**
Converts pixels to rem.

@param {Length} --pixels - Pixel value.
@param {Length} --base - Base font size.
@returns {Length} Rem value.
@example font-size: --px-to-rem(24px);
*/
@function --px-to-rem(--pixels, --base: 16px) {
	result: calc(var(--pixels) / var(--base) * 1rem);
}

/**
Converts rem to pixels.

@param {Length} --rems - Rem value.
@param {Length} --base - Base font size.
@returns {Length} Pixel value.
@example width: --rem-to-px(2rem);
*/
@function --rem-to-px(--rems, --base: 16px) {
	result: calc(var(--rems) / 1rem * var(--base));
}

/* ===================================
	 Grid Functions
	 =================================== */

/**
Creates responsive grid columns.

@param {Number} --min-width - Minimum column width.
@param {Number} --max-cols - Maximum number of columns.
@returns {Grid} Grid template columns value.
@example grid-template-columns: --auto-grid(250px, 4);
*/
@function --auto-grid(--min-width: 250px, --max-cols: 4) {
	result: repeat(
		auto-fit,
		minmax(max(var(--min-width), calc(100% / var(--max-cols))), 1fr)
	);
}

/**
Creates a CSS grid span value.

Ensures the span is an integer value.

@param {Number} --columns - Number of columns to span.
@param {Number} --total - Total columns in grid.
@returns {Span} Grid column span (rounded to integer).
@example grid-column: --grid-span(3, 12);
*/
@function --grid-span(--columns: 1, --total: 12) {
	result: span round(clamp(1, var(--columns), var(--total)));
}

/* ===================================
	 Filter Functions
	 =================================== */

/**
Creates a smooth shadow.

Generates three shadow layers. The spread-factor controls how distributed the shadows are.

@param {Color} --color - Shadow color.
@param {Length} --size - Shadow size.
@param {Number} --spread-factor - Controls shadow distribution (higher = tighter shadows).
@returns {Shadow} Layered box shadow.
@example box-shadow: --smooth-shadow(black, 20px, 3);
*/
@function --smooth-shadow(--color: rgb(0 0 0 / 0.2), --size: 12px, --spread-factor: 3) {
	--step: calc(var(--size) / var(--spread-factor));
	result:
		0 var(--step) calc(var(--step) * 2) rgb(from var(--color) r g b / 0.25),
		0 calc(var(--step) * 2) calc(var(--step) * 3) rgb(from var(--color) r g b / 0.18),
		0 calc(var(--step) * 3) calc(var(--step) * 4) rgb(from var(--color) r g b / 0.12);
}

/**
Creates a glow effect.

@param {Color} --color - Glow color.
@param {Length} --size - Glow size.
@param {Number} --intensity - Glow intensity (0-1).
@returns {Shadow} Glow shadow.
@example box-shadow: --glow(cyan, 10px, 0.5);
*/
@function --glow(--color: white, --size: 10px, --intensity: 0.5) {
	result: 0 0 var(--size) rgb(from var(--color) r g b / var(--intensity));
}

/* ===================================
	 Theme Functions
	 =================================== */

/**
Theme-aware value switcher for light/dark mode.

Uses CSS `if()` with color-scheme query. Requires `color-scheme: light dark` on `:root`.
Works with ANY value type (colors, lengths, etc.), not just colors.

> [!NOTE]
> CSS has a native [`light-dark()`](https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/light-dark) function for colors. The custom `--light-dark()` function is more powerful as it works with any value type, not just colors.

@param {Any} --light - Value for light mode.
@param {Any} --dark - Value for dark mode.
@returns {Any} Theme-appropriate value.
@example color: --light-dark(black, white);
@example background-image: --light-dark(url(light.svg), url(dark.svg));
@example padding: --light-dark(0.75rem, 1rem);
*/
@function --light-dark(--light, --dark) {
	result: if(color-scheme(dark): var(--dark); else: var(--light));
}

/**
Creates a theme-aware color with automatic adjustment.

Uses CSS `if()` with color-scheme query. Requires `color-scheme: light dark` on `:root`.

In light mode, mixes the base color with white (default 85% white).
In dark mode, mixes the base color with black (default 15% black).

@param {Color} --base - Base color.
@param {Number} --light-mix - Percentage of white to mix in light mode.
@param {Number} --dark-mix - Percentage of black to mix in dark mode.
@returns {Color} Theme-adjusted color.
@example background: --theme-color(blue, 80%, 20%);
*/
@function --theme-color(--base, --light-mix: 85%, --dark-mix: 15%) {
	--light-result: color-mix(in oklab, white var(--light-mix), var(--base));
	--dark-result: color-mix(in oklab, black var(--dark-mix), var(--base));
	result: if(color-scheme(dark): var(--dark-result); else: var(--light-result));
}
functions.css
prometheus nlbwmon metric for openwrt
-- nlbwmon.lua (Corrected nlbw command for CSV output)

-- Helper function to read /tmp/dhcp.leases
local function get_mac_to_hostname_map()
  local mac_map = {}
  local leases_file = "/tmp/dhcp.leases"
  local file = io.open(leases_file, "r")

  if not file then
    io.stderr:write("[nlbwmon_collector] ERROR: Could not open DHCP leases file: " .. leases_file .. "\n")
    return mac_map
  end

  for line in file:lines() do
    local _, mac, _, hostname, _ = line:match("^(%d+)%s+([%x:]+)%s+([%d%.]+)%s+([^%s]*)%s+([^%s]*)$")
    if mac and hostname then
      local clean_hostname = (hostname == "*" or hostname == "" or hostname == nil) and "unknown_host" or hostname
      mac_map[string.upper(mac)] = clean_hostname
    elseif mac then
      mac_map[string.upper(mac)] = mac_map[string.upper(mac)] or "unknown_host"
    end
  end
  file:close()
  return mac_map
end

-- Main scrape function
local function scrape()
  -- Define Prometheus metrics local to the scrape function
  local metric_received_bytes = metric("nlbwmon_received_bytes_total", "counter")
  local metric_transmitted_bytes = metric("nlbwmon_transmitted_bytes_total", "counter")

  local mac_host_map = get_mac_to_hostname_map()

  -- Corrected nlbw command to explicitly set comma as separator
  local cmd = "nlbw -c csv -g mac -o mac -n -q -s,"
  local handle = io.popen(cmd)

  if not handle then
    io.stderr:write("[nlbwmon_collector] ERROR: Failed to execute nlbw command: " .. cmd .. "\n")
    return -- Exit scrape if command fails
  end

  local line_num = 0
  for line in handle:lines() do
    line_num = line_num + 1

    -- This header check expects actual commas if "-s," works
    if line_num == 1 and line == "mac,conns,rx_bytes,rx_pkts,tx_bytes,tx_pkts" then
      -- io.stderr:write("[nlbwmon_collector] Correct CSV header found and skipped.\n")
    else
      if line_num == 1 then -- It wasn't the expected comma-separated header
        io.stderr:write(
        "[nlbwmon_collector] WARNING: Unexpected first line from nlbw. Expected 'mac,conns,rx_bytes,rx_pkts,tx_bytes,tx_pkts'. Got: '" ..
        line .. "'\n")
      end

      -- This regex expects comma-separated values
      local mac_addr, conns, rx_bytes_str, rx_pkts, tx_bytes_str, tx_pkts_str = line:match(
      "^([%x:]+),([^,]*),([^,]*),([^,]*),([^,]*),([^%s]*)$")

      if mac_addr then -- At least MAC was parsed (implies commas were present if further fields are needed)
        local current_mac = string.upper(mac_addr)
        local received_val = tonumber(rx_bytes_str)
        local transmitted_val = tonumber(tx_bytes_str)

        if received_val ~= nil and transmitted_val ~= nil then
          local current_host
          if current_mac == "00:00:00:00:00:00" then
            current_host = "unknown_mac_bucket"
          else
            current_host = mac_host_map[current_mac] or "unknown_host"
          end

          local labels = {
            mac = current_mac,
            host = current_host
          }
          metric_received_bytes(labels, received_val)
          metric_transmitted_bytes(labels, transmitted_val)
        else
          io.stderr:write(string.format(
          "[nlbwmon_collector] WARNING: Could not parse byte values to number for MAC: %s. RX_STR: '%s', TX_STR: '%s'. Line: %s\n",
            current_mac, tostring(rx_bytes_str), tostring(tx_bytes_str), line))
        end
      else
        -- Only log this error if it wasn't the (potentially now correctly handled) header line
        if line_num > 1 or (line_num == 1 and line ~= "mac,conns,rx_bytes,rx_pkts,tx_bytes,tx_pkts") then
          io.stderr:write("[nlbwmon_collector] WARNING: Failed to parse nlbw data line structure (expected CSV): " ..
          line .. "\n")
        end
      end
    end
  end
  local close_status, close_err_msg, close_code = handle:close()
  if not close_status then
    io.stderr:write(string.format("[nlbwmon_collector] WARNING: nlbw command close error. Msg: %s, Code: %s\n",
      tostring(close_err_msg), tostring(close_code)))
  elseif type(close_status) == "number" and close_status ~= 0 then
    io.stderr:write(string.format("[nlbwmon_collector] WARNING: nlbw command exited with non-zero status: %s\n",
      tostring(close_status)))
  end
end

-- Return the scrape function
return {
  scrape = scrape
}
prometheus nlbwmon metric for openwrt
openwrt dhcp leases prometheus metric
local function scrape()
  local metric_dhcp_leases = metric("dhcp_leases_total", "gauge")
  local metric_dhcp_lease_info = metric("dhcp_lease_info", "gauge")
  local leases_file = "/tmp/dhcp.leases"
  local leases_count = 0
  local file = io.open(leases_file, "r")
  if file then
    for line in file:lines() do
      local expiry, mac, ip, hostname, client_id = line:match("^(%d+)%s+([%x:]+)%s+([%d%.]+)%s+([^%s]*)%s+([^%s]*)$")
      if ip and mac then
        leases_count = leases_count + 1
        local labels = {
          ip = ip,
          mac = string.upper(mac),
          hostname = (hostname == "*" or hostname == "") and "unknown" or hostname,
          client_id = (client_id == "*" or client_id == "") and "unknown" or client_id
        }
        metric_dhcp_lease_info(labels, 1)
      end
    end
    file:close()
  end
  metric_dhcp_leases({}, leases_count)
end
return { scrape = scrape }
openwrt dhcp leases prometheus metric
cube in a cube algo
# cube in a cube

F L F U' R U F2 L2 U' L' B D' B' L2 U
cube in a cube algo
loop through markdown tables
#!/usr/bin/env fish

set md /path/to/file/with/markdown-table.md

# use miller (https://github.com/johnkerl/miller) to parse markdown tables
# this pattern can be adapted to csv, tsv and other tabular formats that miller supports

mlr --imd cat $md | while read -l line
  set column1 (echo $line | awk -F, '{split($1, a, "="); print a[2]}')
  set column2 (echo $line | awk -F, '{split($2, a, "="); print a[2]}')
  set column3 (echo $line | awk -F, '{split($3, a, "="); print a[2]}')

  # some shell operation involving $column(1,2,3)
end
loop through markdown tables
network etc host swapper
#!/usr/bin/bash

# ------------------------------------------
#
# place in /etc/NetworkManager/dispatcher.d/
#
# ------------------------------------------


CURRENT_INTERFACE=$1
EVENT=$2

# uuid of 'tofu' (nmcli c)
HOME_UUID="xyz"

# Replace with the interface name (e.g., wlp0s20f3)
HOME_INTERFACE="wlp0s20f3"

# Path to your default hosts file
BASE_HOSTS="/etc/hosts.base"

# Path to the hosts file for your home network
HOME_HOSTS="/etc/hosts.home"

if [[ $CURRENT_INTERFACE != "$HOME_INTERFACE" ]] || [[ $EVENT != "up" && $EVENT != "down" ]]
; then
  exit 0
fi

# this environmental variable is set on UP/DOWN events
if [[ $CONNECTION_UUID != "$HOME_UUID" ]]; then
  exit 0
fi

# Function to swap hosts files
if [ "$EVENT" = "up" ]; then
  cat "$BASE_HOSTS" "$HOME_HOSTS" | sudo tee /etc/hosts
  echo "combined home hosts file"
else
  sudo cp /etc/hosts.base /etc/hosts
  echo "back to base hosts file"
fi
network etc host swapper