Skip to content

Instantly share code, notes, and snippets.

View cameronpcampbell's full-sized avatar

Cameron Campbell cameronpcampbell

View GitHub Profile
-- The equality operator `==` is really strict with unions and intersections,
-- where the order of their components needs to be the same.
type function sort_type(input: type)
local input_tag = input.tag
if input_tag == "union" or input_tag == "intersection" then
local components = input:components()
table.sort(components, function(a: type, b: type): boolean
local a_tag, b_tag = a.tag, b.tag
--!strict
--!nolint LocalShadow
export type TrieNode = {
is_end: boolean,
children: { [number]: TrieNode }
}
local function table_is_empty(tble: { [any]: any })
for _ in tble do return false end
@cameronpcampbell
cameronpcampbell / StringToPascal.luau
Created February 19, 2025 14:39
StringToPascal.luau
--!strict
type function _safeIs(input: any, isType: any)
if typeof(input) ~= "userdata" then return false end
local is = input.is
if not is then return false end
return is(input, isType)
end
--!strict
--!nolint LocalUnused
--!nolint LocalShadow
local task = nil -- Disable usage of Roblox's task scheduler
--[[
A special key for property tables, which parents any given descendants into
an instance.
]]
--!strict
--!nolint LocalUnused
--!nolint LocalShadow
local task = nil -- Disable usage of Roblox's task scheduler
--[[
A special key for property tables, which applies any given tags onto
an instance.
]]
@cameronpcampbell
cameronpcampbell / mock_web_framework.luau
Last active December 15, 2024 04:00
mock_web_framework.luau
--!strict
type AppRunConfig = {
port: number
}
type function _stringSplitOnce(str: string, delimiter: string)
local start, finish = string.find(str, delimiter, 1, true)
if start then
local before = string.sub(str, 1, start - 1)
--[[
Copyright 2024 Cameron Campbell
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE U
--!strict
--> Modules -------------------------------------------------------------------------------------------
local Fusion = require(Packages.Fusion) -- Make sure to put path to Fusion here.
-------------------------------------------------------------------------------------------------------
--> Functions -----------------------------------------------------------------------------------------
local function ComputeUDim(scope: Fusion.Scope<typeof(Fusion)>, scale: Fusion.UsedAs<number>, offset: Fusion.UsedAs<number>)
@cameronpcampbell
cameronpcampbell / init.luau
Created August 22, 2024 20:47
Component Helper (Fusion)
--!strict
--> Modules -------------------------------------------------------------------------------------------
local Fusion = require(script.Parent.Fusion) -- Replace with path to fusion.
-------------------------------------------------------------------------------------------------------
--> Types ---------------------------------------------------------------------------------------------
type Scope = Fusion.Scope<typeof(Fusion)>
--[[
Copyright 2024 Cameron Campbell
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE U