Skip to content

Instantly share code, notes, and snippets.

View cgsdev0's full-sized avatar
🐻

cgsdev0

🐻
View GitHub Profile
@cgsdev0
cgsdev0 / fizzbuzz.sh
Created October 26, 2026 13:39
fizzbuzz.sh
#!/usr/bin/env bash
seq 100 \
| while read n
do echo $((n % 3)),$((n % 5)) $n
done \
| while read mod n
do
case "$mod" in
0,*) printf Fizz ;;&
@cgsdev0
cgsdev0 / battleship.sh
Created October 9, 2026 02:22
battleship?
#!/usr/local/bin/bash
enable -f accept accept
set -u
shopt -s nullglob
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
STATE_DIR="$PWD/state" # TODO: XDG_STATE or something? :)
GRID_DIR="$STATE_DIR/grid"
@cgsdev0
cgsdev0 / number.js
Last active September 20, 2026 09:18
format number js
function a(b, c = 0) {
d=b.length
if (!d) return ''
n = b[d - 1]
let r = ((n != '-' && c && !(c % 3)) ? ',' : '') + n + a(b.slice(0, d - 1), c + 1)
if (!c) return r.split('').reverse().join('')
return r
}
@cgsdev0
cgsdev0 / idk.cs
Last active September 11, 2026 23:54
int latency = AudioSettings.outputSampleRate / 10;
AudioClip clip = Microphone.Start(device, true, 1, AudioSettings.outputSampleRate);
int last = 0;
int dist(int samples, int start, int end) {
if (end >= start) return end - start;
return (end + samples) - start; // handle wrapping
}
while(true) {
@cgsdev0
cgsdev0 / lol.sh
Created July 29, 2026 05:43
hacking an ereader
i=0
j=0
while [ "$i" -lt 600 ]; do
n=$(((i-60)/2))
if [ "$n" -lt 0 ]; then
n=255
fi
if [ "$n" -gt 255 ]; then
@cgsdev0
cgsdev0 / conway.bash
Created May 19, 2026 20:47
conway's game of life
#!/usr/bin/env bash
tput civis
declare -a arr0
declare -a arr1
idx=0
declare -n cur=arr0
declare -n next=arr1
@cgsdev0
cgsdev0 / interpreter.bash
Created March 31, 2026 15:08
lisp interpreter
#!/usr/bin/env bash
# terrible lisp interpreter
#
# example run:
#
# (first (list 1 (+ 2 3) 9)))
#
# evaluating + 2 3 = 5
# evaluating list 1 5 9 = 1,5,9
@cgsdev0
cgsdev0 / parse.bash
Last active March 30, 2026 18:02
lisp parser
#!/usr/bin/env bash
# basic lisp parser that creates an AST.
# assumes valid input.
#
# it stores this AST using the file system, since
# bash doesn't really have a good way to do trees
output_path=/tmp/parsed
#!/usr/bin/env bash
echo -ne "\033[38;5;$((RANDOM % 255))m"
printf -v hex "%x" "$((RANDOM % 93 + 33))"
printf "\x${hex}"
@cgsdev0
cgsdev0 / 1_to_100.sh
Last active February 11, 2026 08:25
one to one hundred
#/usr/bin/env bash
# solution for https://chrzanowski.me/blog_0003.html
seq $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $(echo $BASH_SUBSHELL))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))