- llm: Local LLM wrapper for llama-swap - homelab-status: Quick K8s/cluster health check - calc: Python/JS REPL for quick calculations - transcribe: Whisper audio transcription wrapper Added to fish PATH.
77 lines
1.5 KiB
Bash
Executable File
77 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Quick code execution for calculations and data processing
|
|
# Usage: calc "expression"
|
|
# calc -p "python code"
|
|
# calc -j "javascript code"
|
|
|
|
set -e
|
|
|
|
MODE="python"
|
|
CODE=""
|
|
|
|
show_help() {
|
|
echo "Usage: calc [options] \"code\""
|
|
echo ""
|
|
echo "Options:"
|
|
echo " -p, --python Python mode (default)"
|
|
echo " -j, --js JavaScript mode (Node.js)"
|
|
echo " -h, --help Show this help"
|
|
echo ""
|
|
echo "Examples:"
|
|
echo " calc \"2 + 2\" # Quick math"
|
|
echo " calc \"sum([1,2,3,4,5])\" # Python functions"
|
|
echo " calc -p \"import math; math.pi\" # Python with imports"
|
|
echo " calc -j \"[1,2,3].map(x => x*2)\" # JavaScript"
|
|
echo ""
|
|
echo "Python mode has these pre-imported:"
|
|
echo " math, json, re, datetime, random, statistics"
|
|
}
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case $1 in
|
|
-p|--python)
|
|
MODE="python"
|
|
shift
|
|
;;
|
|
-j|--js)
|
|
MODE="js"
|
|
shift
|
|
;;
|
|
-h|--help)
|
|
show_help
|
|
exit 0
|
|
;;
|
|
*)
|
|
if [[ -z "$CODE" ]]; then
|
|
CODE="$1"
|
|
else
|
|
CODE="$CODE $1"
|
|
fi
|
|
shift
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [[ -z "$CODE" ]]; then
|
|
show_help
|
|
exit 1
|
|
fi
|
|
|
|
case $MODE in
|
|
python)
|
|
python3 -c "
|
|
import math, json, re, sys
|
|
from datetime import datetime, date, timedelta
|
|
from random import random, randint, choice
|
|
from statistics import mean, median
|
|
from collections import Counter, defaultdict
|
|
result = $CODE
|
|
if result is not None: print(result)
|
|
"
|
|
;;
|
|
|
|
js)
|
|
node -e "console.log($CODE)"
|
|
;;
|
|
esac
|