Skip to content

Instantly share code, notes, and snippets.

@bytejon
bytejon / reuse_thread.luau
Last active January 8, 2026 21:33
Luau utility for general purpose thread reuse with a more efficient approach than standard. This can be made more efficient if applied to specific domains, like signaling.
-- jonbyte, 2026
local queue = {} :: array<{
fn: callback,
args: argpack
}>
local active = false
local index = 1
local epoch = 0
local thread: thread?
@bytejon
bytejon / multi_split.luau
Last active January 9, 2026 18:03
Luau utility for string.split behavior with support for more than one delimiter
-- jonbyte, 2026
local function split(
input: string, -- string to be split
sep: { string }, -- array of separator strings
include: true? -- if separators should be included in result
)
if #sep == 0 then
-- early exit: there is nothing to split the string
return { input }
@bytejon
bytejon / fastDequeue.luau
Last active August 30, 2025 21:06
A small utility for dequeuing items from an array (FIFO) but with the speed of a stack-based O(1) removal. Shifting is avoided with swaps. The queue is assumed to not add anymore items.
-- queue: (assumed to not add anymore items mid-dequeue)
-- length: the initial length of the queue
local function fastDequeue(queue, length)
local k = #queue
local i = math.min(k, length - k + 1)
queue[i], queue[k] = queue[k], queue[i]
local v = queue[k]
queue[k] = nil
return v
end
--!strict
-- jonbyte, 2025
-- types
type Int = number
type i53 = Int
type Type = Int
type Index = Int
type Map<K, V> = { [K]: V }
type Array<V> = Map<Int, V>
-- jonbyte, 2024
-- approximate a kelvin temperature as RGB
-- the result of messing around with equations and seeing the results
local R, G, B = 560, 530, 420 -- sample wavelengths
local c = 299792458 -- speed of light (m/s)
local h = 6.62607015e-34 -- planck constant
local k = 1.380649e-23 -- boltzmann constant
local vec0 = vector.create(0, 0, 0)