Skip to content

Instantly share code, notes, and snippets.

View Ezbob's full-sized avatar
🧻

Anders Busch Ezbob

🧻
View GitHub Profile
@Ezbob
Ezbob / nodejs_websocket_proxy.js
Created July 25, 2023 19:30
Simple reverse proxy for websockets, created in pure NodeJs
const http = require("http")
const https = require("https")
let proxyEndpoint = "http://localhost:8080"
let isWebsocketUpgrade = (headers) => {
return !headers.upgrade || headers.upgrade.toLowerCase() != "websocket" ||
!headers.connection || headers.connection.toLowerCase() != "upgrade"
}
@Ezbob
Ezbob / pathlib_walk.py
Created October 27, 2019 13:59
The os.walk for pathlib.Paths using generators
import pathlib
def path_walk(top_path):
if not top_path.is_dir(): return top_path
top_queue = [top_path] # using list for a queue here, but any collection with the same offer / pop can do
while len(top_queue) != 0:
current_dir = top_queue[0]
for filepath in current_dir.iterdir():
if filepath.is_dir():
top_queue.append(filepath)
@Ezbob
Ezbob / get_youtube_links_from_favorites_json.py
Last active October 20, 2019 15:42
Get youtube links from favorites takeout json
@Ezbob
Ezbob / spinit.py
Created January 16, 2017 21:45
Like my head, this also keeps spinning..
def spin_it(message, frames=('|', '\\', '-', '/'), delay_scale=1):
"""Decorator for printing a message and then start the spinner"""
def inner(function):
def do_function(*args, **kwargs):
sys.stdout.write(message)
spinner = Spinner(frames=frames, delay=delay_scale)
spinner.start()
with io.StringIO() as strout:
with contextlib.redirect_stdout(strout):
output = function(*args, **kwargs)
@Ezbob
Ezbob / algorithms.lua
Created January 3, 2017 17:44
collision detection 2d rects
local Algorithms = {}
Algorithms.Collision = {}
function Algorithms.Collision.is_colliding_rectangles(reactA, reactB)
local function getMinMax(react)
return {x = {min = math.min(react.upper.x, react.lower.x), max = math.max(react.upper.x, react.lower.x)},
y = {min = math.min(react.upper.y, react.lower.y), max = math.max(react.upper.y, react.lower.y)}}
end