Skip to content

Instantly share code, notes, and snippets.

View dolegi's full-sized avatar

Dom Ginger dolegi

View GitHub Profile
@dolegi
dolegi / fen_parser.js
Created November 20, 2019 14:04
Fen Parser
// const fen = 'k1K5/8/8/8/8/8/8/1Q6'
const fen = '2r3k1/1q1nbppp/r3p3/3pP3/pPpP4/P1Q2N2/2RN1PPP/2R4K'
const rows = fen.split('/')
const board = []
let i = 0
rows.forEach(row => {
const squares = row.split('')
board[i] = []
@dolegi
dolegi / main.go
Created November 20, 2019 15:35
FEN parser
package main
import (
"fmt"
"strconv"
"strings"
)
func main() {
fen := "2r3k1/1q1nbppp/r3p3/3pP3/pPpP4/P1Q2N2/2RN1PPP/2R4K"
@dolegi
dolegi / serve.sh
Created February 13, 2020 16:41
Static file server in bash with netcat
#!/bin/bash
RESP=/tmp/server-response && rm -rf $RESP && mkfifo $RESP
while true; do
cat $RESP | nc -l 9090 | (
REQ=$(while read -r line && [[ $line != Host* ]]; do echo "$line" ; done)
url="${REQ% HTTP/*}"
filedata=$(<"$(pwd)${url#* }")
cat >$RESP <<EOF
HTTP/1.1 $([ -z "${#filedata}" ] && echo '200 OK' || echo '404 NOT FOUND')
Content-Length: ${#filedata}