Skip to content

Instantly share code, notes, and snippets.

View digitaltembo's full-sized avatar

Nolan Hawkins digitaltembo

View GitHub Profile
@digitaltembo
digitaltembo / minimalWsServer.ts
Last active March 17, 2024 13:31
Minimal WebSocket Server in NodeJS/TypeScript, no dependencies
import { createHash } from "crypto";
import { createServer, IncomingMessage } from "http";
import { Duplex } from "stream";
type WsFn = (val: string | Uint8Array) => void;
// Create this object whenever a websocket connection has been established
type WebSocket = {
write: WsFn;
addListener: (listener: WsFn) => void;
@digitaltembo
digitaltembo / text_box.py
Created March 19, 2019 01:50
Drawing within a Text Box in Python Pillow (PIL fork)
"""
Draws the text <text> on the ImageDraw <image_draw> in the box (specified as a 4-ple of [x,y,width,height])
with the font <font> and the allignments as given. Passes other arguments to the ImageDraw.text function
(for example, fill is a good one to use here).
Can be used to center text horizontally and vertically, as well as right-align and bottom-allign (although it defaults to
left- and top-allignment). Nothing is done to prevent overflow, but the y and height values from the box will be used for vertical
allignment
Example usage: