id,tool_id,filename,language,content 11,1,colors.py,py,"#!/usr/bin/env python3 """"""colors — convert between hex, rgb, hsl"""""" import colorsys import re import sys def hex_to_rgb(h: str) -> tuple[int, int, int]: h = h.lstrip(""#"") if len(h) == 3: h = """".join(c * 2 for c in h) return int(h[0:2], 16), int(h[2:4], 16), int(h[4:6], 16) def rgb_to_hsl(r: int, g: int, b: int) -> tuple[int, int, int]: h, l, s = colorsys.rgb_to_hls(r / 255, g / 255, b / 255) return round(h * 360), round(s * 100), round(l * 100) def parse_rgb(text: str) -> tuple[int, int, int]: m = re.match(r""rgb\((\d+),\s*(\d+),\s*(\d+)\)"", text) if m: return int(m[1]), int(m[2]), int(m[3]) raise ValueError(f""cannot parse: {text}"") def main(): inp = sys.argv[1] if len(sys.argv) > 1 else input().strip() if inp.startswith(""#"") or re.match(r""^[0-9a-fA-F]{3,8}$"", inp): r, g, b = hex_to_rgb(inp) elif inp.startswith(""rgb""): r, g, b = parse_rgb(inp) else: print(f""unsupported format: {inp}"", file=sys.stderr) sys.exit(1) h, s, l = rgb_to_hsl(r, g, b) hx = f""#{r:02x}{g:02x}{b:02x}"" print(f""hex: {hx}"") print(f""rgb: rgb({r}, {g}, {b})"") print(f""hsl: hsl({h}, {s}%, {l}%)"") if __name__ == ""__main__"": main() " 12,1,colors.sh,sh,"#!/bin/sh # colors — convert between hex, rgb, hsl hex_to_rgb() { hex=""${1#\#}"" [ ${#hex} -eq 3 ] && hex=""$(echo ""$hex"" | sed 's/./&&/g')"" r=$((16#${hex%????})) g=$((16#$(echo ""$hex"" | cut -c3-4))) b=$((16#${hex#????})) printf 'rgb(%d, %d, %d)\n' ""$r"" ""$g"" ""$b"" } input=""${1:-$(cat)}"" case ""$input"" in \#*|[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]*) hex_to_rgb ""$input"" ;; *) echo ""unsupported format: $input"" >&2 exit 1 ;; esac " 13,2,entropy.c,c,"/* entropy — calculate shannon entropy of input */ #include #include int main(int argc, char *argv[]) { FILE *fp; unsigned long freq[256] = {0}; unsigned long total = 0; int c; double entropy = 0.0; fp = (argc > 1) ? fopen(argv[1], ""rb"") : stdin; if (!fp) { perror(argv[1]); return 1; } while ((c = fgetc(fp)) != EOF) { freq[c]++; total++; } if (fp != stdin) fclose(fp); if (total == 0) { printf(""0.000000\n""); return 0; } for (int i = 0; i < 256; i++) { if (freq[i] == 0) continue; double p = (double)freq[i] / total; entropy -= p * log2(p); } printf(""%.6f\n"", entropy); return 0; } " 14,2,entropy.py,py,"#!/usr/bin/env python3 """"""entropy — calculate shannon entropy of input"""""" import math import sys from collections import Counter def entropy(data: bytes) -> float: if not data: return 0.0 counts = Counter(data) total = len(data) return -sum((c / total) * math.log2(c / total) for c in counts.values()) def main(): if len(sys.argv) > 1: with open(sys.argv[1], ""rb"") as f: data = f.read() else: data = sys.stdin.buffer.read() print(f""{entropy(data):.6f}"") if __name__ == ""__main__"": main() " 15,3,epoch.py,py,"#!/usr/bin/env python3 """"""epoch — convert between unix timestamps and dates"""""" import sys from datetime import datetime, timezone def main(): inp = sys.argv[1] if len(sys.argv) > 1 else input().strip() try: ts = int(inp) dt = datetime.fromtimestamp(ts, tz=timezone.utc) print(dt.isoformat()) except ValueError: dt = datetime.fromisoformat(inp) print(int(dt.timestamp())) if __name__ == ""__main__"": main() " 16,3,epoch.sh,sh,"#!/bin/sh # epoch — convert between unix timestamps and dates if [ -z ""$1"" ]; then read -r input else input=""$1"" fi case ""$input"" in *[!0-9]*) # input is a date string, convert to epoch date -d ""$input"" +%s 2>/dev/null || date -j -f ""%Y-%m-%d %H:%M:%S"" ""$input"" +%s ;; *) # input is epoch, convert to date date -d ""@$input"" --iso-8601=seconds 2>/dev/null || date -r ""$input"" +%Y-%m-%dT%H:%M:%S%z ;; esac " 17,4,resolve.py,py,"#!/usr/bin/env python3 """"""resolve — bulk dns resolver"""""" import socket import sys def resolve(domain: str): for family, type_name in [(socket.AF_INET, ""A""), (socket.AF_INET6, ""AAAA"")]: try: results = socket.getaddrinfo(domain, None, family, socket.SOCK_STREAM) for _, _, _, _, addr in results: print(f""{domain}\t{type_name}\t{addr[0]}"") except socket.gaierror: pass def main(): source = open(sys.argv[1]) if len(sys.argv) > 1 else sys.stdin for line in source: domain = line.strip() if domain: resolve(domain) if __name__ == ""__main__"": main() " 18,4,resolve.sh,sh,"#!/bin/sh # resolve — bulk dns resolver file=""${1:--}"" while IFS= read -r domain; do [ -z ""$domain"" ] && continue dig +short A ""$domain"" 2>/dev/null | while IFS= read -r ip; do printf '%s\tA\t%s\n' ""$domain"" ""$ip"" done dig +short AAAA ""$domain"" 2>/dev/null | while IFS= read -r ip; do printf '%s\tAAAA\t%s\n' ""$domain"" ""$ip"" done done < ""$file"" " 19,5,slugify.py,py,"#!/usr/bin/env python3 """"""slugify — convert text to url-safe slugs"""""" import re import sys import unicodedata def slugify(text: str) -> str: text = unicodedata.normalize(""NFKD"", text).encode(""ascii"", ""ignore"").decode() text = text.lower().strip() text = re.sub(r""[^a-z0-9\s-]"", """", text) text = re.sub(r""[\s_]+"", ""-"", text) text = re.sub(r""-+"", ""-"", text) return text.strip(""-"") def main(): inp = "" "".join(sys.argv[1:]) if len(sys.argv) > 1 else input().strip() print(slugify(inp)) if __name__ == ""__main__"": main() " 20,5,slugify.sh,sh,"#!/bin/sh # slugify — convert text to url-safe slugs if [ -z ""$1"" ]; then read -r input else input=""$*"" fi printf '%s' ""$input"" \ | tr '[:upper:]' '[:lower:]' \ | sed 's/[^a-z0-9 _-]//g' \ | tr ' _' '--' \ | sed 's/--*/-/g; s/^-//; s/-$//' "