Skip to content

Instantly share code, notes, and snippets.

View SiddharthShyniben's full-sized avatar
🎯
Focusing

Siddharth SiddharthShyniben

🎯
Focusing
View GitHub Profile
import socket
import threading
import argparse
HOST = "0.0.0.0" # Server binds here (0.0.0.0 = all interfaces)
PORT = 5000 # Default port
def handle_client(conn, addr, clients):
"""Handle incoming messages from a single client and broadcast to others."""
# lab_blackjack.py
# Multiplayer "no-dealer" Blackjack over a shared E: drive.
# Everyone runs the same script; state is coordinated via E:\<session_id>.json
# [Tech: shared-file state machine, cooperative polling, Windows file lock, Fisher–Yates shuffle,
# blackjack evaluator (soft/hard aces), turn arbitration]
import json, os, sys, time, random, tempfile, getpass
from datetime import datetime
from typing import List, Dict, Any
@SiddharthShyniben
SiddharthShyniben / sysexits.md
Created February 13, 2022 13:55
System Exit Codes

As in sysexits.h, but in a (sometimes) more accessible place. Formatted painlessly in Vim


According to style(9), it is not a good practice to call exit(3) with arbitrary values to indicate a failure condition when ending a program. Instead, the pre-defined exit codes from sysexits should be used, so the caller of the process can get a rough estimation about the failure class without looking up the source code.

The successful exit is always indicated by a status of 0, or EX_OK. Error numbers begin at EX__BASE to reduce the possibility of clashing with other exit statuses that random programs may already return. The meaning of the codes is approximately as follows:

Exit Code Description
@SiddharthShyniben
SiddharthShyniben / golfs.md
Last active April 30, 2024 04:31
Golfing

A router in 108 89 83 bytes

(a,b,c=_=>(a.find(p=>b=p.path.exec(location.hash))?.render(b),c))=>onhashchange=c()

Shortened with inspiration from @Posandu

const route = (a,b,c=_=>(a.find(p=>b=p.path.exec(location.hash))?.render(b),c))=>onhashchange=c();
@SiddharthShyniben
SiddharthShyniben / classify.js
Last active August 13, 2023 05:47
Lots of handy code golf. Mostly ported from 140byt.es but modernized
// add or remove classes. classify(element, '+class-to-add -class-to-remove other-class-to-add')
(a,b)=>b.split` `.map(c=>c[0]=='-'?['remove',c.slice(1)]:['add',c[0]=='+'?c.slice(1):c]).map(([d,e])=>a[d](e))

Unix wars

If you know who originally wrote this, please tell me so that I can credit them. I found this in an old hard disk.


A long time ago, at an installation far, far away...

It is a time of intra-system war, as forces of the User Alliance struggle to break the iron grip of the evil Admin Empire. Now, striking from a

@SiddharthShyniben
SiddharthShyniben / backtracking.js
Created April 15, 2023 06:07
Maze algorithms in JavaScript
class Backtracking {
constructor(height, width) {
if (width % 2 === 0) {
width += 1;
}
if (height % 2 === 0) {
height += 1;
}
this.width = width;
@SiddharthShyniben
SiddharthShyniben / ninja-code.md
Last active October 25, 2022 09:35
Ninja Code from javascript.info. For my self reference.

Ninja code

Learning without thought is labor lost; thought without learning is perilous.

— Confucius

Programmer ninjas of the past used these tricks to sharpen the mind of code maintainers.
Code review gurus look for them in test tasks.
Novice developers sometimes use them even better than programmer ninjas.
Read them carefully and find out who you are – a ninja, a novice, or maybe a code reviewer?

@SiddharthShyniben
SiddharthShyniben / Gist name here
Last active December 1, 2021 21:41
Testing gist names
‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎‎
@SiddharthShyniben
SiddharthShyniben / index.html
Created November 24, 2021 06:50
Drag and Drop API
<div class="drop">
<div id="drag" draggable="true" ondragstart="event.dataTransfer.setData('text/plain', null)">
Drag me!
</div>
</div>
<div class="drop"></div>
<div class="drop"></div>
<div class="drop"></div>