Skip to content

Instantly share code, notes, and snippets.

@Anaminus
Anaminus / NthSubPerm.lua
Last active September 29, 2020 01:39
Like a permutation, but also includes subsets
local function NthSubPerm(v, b)
local B = #b
if B <= 1 then return b:rep(v+1) end
local p = math.floor(math.log((v+2)*(B-1))/math.log(B))-1
v = v - math.modf(B*(B^p-1)/(B-1))
local s = {}
for i = 0, p do
local j = math.modf(v / B^i % B)
s[i+1] = b:sub(j+1,j+1)
end
@Anaminus
Anaminus / Interface.lua
Last active September 29, 2020 01:39
Lightweight interfaces.
local Impl
local Is
local Interface
do
local implementedInterfaces = setmetatable({}, {__mode="k"})
local embeddedInterfaces = {}
local nillableInterfaces = {}
-- Impl declares a value to implement zero or more interfaces, which must be
-- strings. A value can be declared only once, and subsequent attempts do
Accessory.BackendAccoutrementState
Accoutrement.BackendAccoutrementState
ArcHandles.MouseButton1DownConnectionCount
ArcHandles.MouseButton1UpConnectionCount
ArcHandles.MouseDragConnectionCount
ArcHandles.MouseEnterConnectionCount
ArcHandles.MouseLeaveConnectionCount
BinaryStringValue.Value
BindableFunction.OnInvoke
BlockMesh.Bevel
@Anaminus
Anaminus / Filter.lua
Last active September 29, 2020 01:39
Concept for Roblox game tree query filters.
--[[
Filter.Property(name, op, value)
Filter.Tag(name)
Filter.DescendantOf(ancestor)
Filter.AncestorOf(descendant)
Filter.ChildOf(parent)
Filter.ParentOf(child)
Filter.Class(name)
Filter.ClassOf(name)
--[[
Core
Contains core functions to be used by the rest of the framework.
]]
local Core = {}
local stringFormat = string.format
@Anaminus
Anaminus / shuffle.lua
Created September 7, 2018 17:06
Correct 1-index Fisher–Yates shuffle
for i = #a, 2, -1 do
local j = math.random(1, i)
a[i], a[j] = a[j], a[i]
end
@Anaminus
Anaminus / UnwrapBase.lua
Last active September 29, 2020 01:40
UnwrapBase unwraps a number to a given base for a given number of digits.
-- UnwrapBase unwraps a number to a given base for a given number of digits.
--
-- Examples:
-- 3-digit decimal: UnwrapBase(42, 10, 3) -- 2, 4, 0
-- 8-bit binary: UnwrapBase(85, 2, 8) -- 1, 0, 1, 0, 1, 0, 1, 0
-- DWORD: UnwrapBase(0xDEADBEEF, 256, 4) -- 249, 190, 173, 222
--
local function UnwrapBase(value, base, length)
if not length then
length = math.ceil(math.log(value+1)/math.log(base))
--[[
Cond
Block threads until a condition is met. Reusable.
]]
local function pack(...)
return {n = select('#', ...), ...}
end
@Anaminus
Anaminus / Signal.lua
Last active September 29, 2020 01:33
--[[
# Signal
API-compatible Roblox events.
Addresses two flaws in previous implementations:
- Held a reference to the last set of fired arguments.
- Arguments would be overridden if the signal was fired by a listener.
@Anaminus
Anaminus / Brute.lua
Created September 25, 2016 20:45
Bruteforce Roblox members.
-- Brute.lua --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--[[
# Instructions
- Create Script in game.ServerStorage, named "Words".
- Fill it with any words that may be a potential instance or member name (one
word per line).
- Exclude words with 3 or less characters (these are generated automatically).
- Run this script via Execute Script.