Skip to content

Instantly share code, notes, and snippets.

-- 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)
--!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>
@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