Skip to content

Instantly share code, notes, and snippets.

--[[
Cond
Block threads until a condition is met. Reusable.
]]
local function pack(...)
return {n = select('#', ...), ...}
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))
@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
--[[
Core
Contains core functions to be used by the rest of the framework.
]]
local Core = {}
local stringFormat = string.format
@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)
Accessory.BackendAccoutrementState
Accoutrement.BackendAccoutrementState
ArcHandles.MouseButton1DownConnectionCount
ArcHandles.MouseButton1UpConnectionCount
ArcHandles.MouseDragConnectionCount
ArcHandles.MouseEnterConnectionCount
ArcHandles.MouseLeaveConnectionCount
BinaryStringValue.Value
BindableFunction.OnInvoke
BlockMesh.Bevel
@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
@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 / dlasset.bat
Created June 20, 2019 15:58
Use rbxmk to download a Roblox asset to a file.
:: dlasset [asset id] [output file]
@echo rbxmk.delete{rbxmk.output{"%2"}};rbxmk.map{rbxmk.input{format="rbxm","rbxassetid://%1"},rbxmk.output{"%2"}} | rbxmk
@Anaminus
Anaminus / shrink-partition.md
Created July 28, 2019 16:31
How to shrink a Windows partition

How to shrink a Windows partition

First a shrink with the Disk Management tool is tried, which will hopefully be all that is needed. If that fails, then ntfsresize is used on linux to move otherwise unmovable files to clear the way. diskpart is then used to extend the file system back to the original size, which resolves corruption issues. Even though it is now back at the original size, the files themselves have not been moved back, so it is now possible to do a shrink the normal way.

  1. Use Disk Management to shrink to desired size.
  2. If partition cannot be shrinked to desired size, continue.