Skip to content

Instantly share code, notes, and snippets.

View cameronpcampbell's full-sized avatar

Cameron Campbell cameronpcampbell

View GitHub Profile
use std::{
fmt::Debug, ops::{Add, Mul, Sub}, rc::Rc, time::{Duration, Instant}, borrow::BorrowMut
};
use gpui::{
AnyElement, App, Bounds, Corners, DevicePixels, Edges, Element, ElementId, Entity, GlobalElementId, Hsla, InspectorElementId, IntoElement, Percentage, Pixels, Point, Radians, Rems, Rgba, Size, Window, colors::{Colors}, linear
};
/// A transition that can be applied to an element.
#[derive(Clone)]
// A helper which outputs a reader to an `onChunk` callback.
// Please note that the data sent to `onChunk` is the total data thus far.
interface StreamBodyCallbackOptions {
chunkSize?: number,
delayMs?: number,
abortSignal?: AbortSignal
}
export const streamBodyCallback = async (
--!strict
--!nolint LocalShadow
--> Table Helpers ----------------------------------------------------------------------
--[=[
Performs a swap remove on a table type.
@category Table
@param input { [any]: any } -- The table value to perform a swap remove on.
--!strict
type function default_nanoid()
return nanoid()
end
export type function nominal(input: type)
local phantom_table = types.newtable()
phantom_table:setwriteproperty(types.singleton("_phantom_nominal_id"), types.singleton(default_nanoid()()))
-- 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)