Skip to content

Instantly share code, notes, and snippets.

View cgsdev0's full-sized avatar
🐻

cgsdev0

🐻
View GitHub Profile
@cgsdev0
cgsdev0 / twitch_chat.sh
Created January 26, 2022 09:30
Display live twitch chat directly in your terminal
#!/bin/zsh
# depends on 'websocat' https://github.com/vi/websocat
#
# twitch_chat {channel} - opens a websocket for reading chat
twitch_chat () {
rm -f /tmp/twitch_tunnel;
mkfifo /tmp/twitch_tunnel;
clear;
@cgsdev0
cgsdev0 / kenken.cpp
Created March 29, 2020 06:26
(C++) KenKen Puzzle Solver
/*
Program that solves a kenken puzzle and pretty prints the result.
Reading the puzzle as input is not currently supported.
*/
#include <fcntl.h>
#include <locale.h>
#include <iomanip>
#include <iostream>
#include <locale>
@cgsdev0
cgsdev0 / zsh_web_server.md
Last active January 22, 2025 03:18
ZSH Web Server

ZSH Web Server

Have you ever used the command python -m http.server and thought hmm... I really wish this didn't require such a heavy depedency like Python?

Well, now you can accomplish the same goal from the comfort of ZSH! Simply add this line to your zsrhc, then type serve in the folder you'd like to start a HTTP server for.

serve () { rm /tmp/tunnel; mkfifo /tmp/tunnel; echo "Serving $(pwd) on 127.0.0.1:8000..."; while true; do (printf "HTTP/1.0 200 OK\n"; (reqreader() { while IFS= read line;  do [[ $line = $'\r' ]] && break; echo "$line"; done; exit 0; }; var=$(</tmp/tunnel | reqreader); var=$(echo "$var" | grep ^GET | sed 's/GET \(.*\) HTTP\/1\.1.*/\1/'); var=$(echo "$var" | sed 's/^\(.*\)@$/\1/' | sed 's/^\(.*\)\*/\1/'); var=$(echo "<!doctype html><html><head><title>$(pwd)</title></head><body>"; (cat "./$var" 2> /dev/null || (ls -F "./$var" 2> /dev/null | sed 's/\(.*\)/<a href="\1">\1<\/a><br \/>/')); echo "</body></html>"); printf "Content-Length: "; echo "$var" | wc -c; printf "\r\n
@cgsdev0
cgsdev0 / decToInt.cpp
Created May 12, 2019 02:38
Round argv[1] to the nearest integer
/*
This program rounds argv[1] to the nearest integer.
It was tasked as a college programming assignment to one of my friends,
and written by me (in this horrifying way so he couldn't steal it and
turn it in)
*/
#include <iostream>
@cgsdev0
cgsdev0 / fizzbuzz.cpp
Last active January 26, 2024 14:28
FizzBuzz State Machine (C++)
/*
(Dumb) idea to implement the classic FizzBuzz
problem as a state machine with 16 states.
*/
#include <iostream>
#include <vector>
#include <functional>
#include <stdlib.h>