Skip to content

Instantly share code, notes, and snippets.

View cgsdev0's full-sized avatar
🐻

sarah schulte cgsdev0

🐻
View GitHub Profile
@brimonk
brimonk / fizzbuzz_machine.c
Created May 7, 2019 03:51
Doing Fizz Buzz with a State Machine
/*
* Brian Chrzanowski
* Mon May 06, 2019 23:41
*
* This was a meme. A friend of mine thought about how you could do fizz-buzz
* as a 15(ish) state machine.
*
* I think my thing is closer to a circular linked list with function pointers,
* but that's whatever.
*/
@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>
@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 / zsh_web_server.md
Last active March 18, 2020 20:28
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
@ianpaul
ianpaul / pandoc-helper.sh
Created April 15, 2020 11:14
Convert markdown to HTML in Bash
#!/bin/bash
# A simple Bash script to create HTML in stdout from a markdown file
# This script requires pandoc. On Ubuntu use `sudo apt install pandoc` to install.
# Check to see if the user included a filename. If not, ask them for one.
if [ -z "$1" ]; then
read -p "Please provide a filename (include the path if not in this directory): " file
else file=$1