This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- A cool autocomplete demo | |
-- @author Validark | |
-- Strings are stored in a lexigraphically sorted array, which can be binary searched for the first and last element which matches a query | |
-- Please note the "groupings" functionality is an unvalidated afterthought which may or may not work properly, but overall this code has some nice gems: | |
-- I was originally thinking that https://github.com/evaera/Cmdr could use this to get O(log n) autocompletes (old algo uses O(n)) | |
-- However, Cmdr is designed in such a way that it creates a new autocomplete function on-demand each time, | |
-- which means we'd have to sort (or at least verify the sortedness) of the most recent data each time (for changing data at least, like a Player list). | |
-- Sorting at run-time takes O(n*log n) time, making it hard to compete with the old algorithm where the pre-processing step just gets the data in the right format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local R1 = 2^10 | |
local R2 = 2^11 -- the size of strings you want to test | |
local find = string.find | |
local sub = string.sub | |
local gsub = string.gsub | |
local match = string.match | |
local gmatch = string.gmatch | |
local byte = string.byte | |
local candidates = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Takes in a number or a string coercible to a number, and returns a string where every 3rd digit from the decimal point is separated by sep (default = ",") | |
-- e.g. 1000 -> 1,000 and 1234567 -> 1,234,567 | |
-- scales linearly, basically O(2n), and doesn't create any unnecessary intermediary strings | |
-- @author Validark | |
local function commify(num, sep) | |
local t = type(num) | |
if t == "number" then | |
num = string.format("%f", num) | |
elseif t ~= "string" then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const HttpService = game.GetService("HttpService"); | |
export async function getRequest(...[url, nocache, headers]: Parameters<HttpService["GetAsync"]>) { | |
return HttpService.GetAsync(url, nocache, headers); | |
} | |
export interface ReferenceData { | |
readonly owner: string; | |
readonly repository: string; | |
readonly branch?: string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ugh.lua | |
local function foo1(...) | |
local result = {} | |
for i = 1, select("#", ...) do | |
result[i] = (select(i, ...)) .. "b" | |
end | |
return result | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local RunService = game:GetService("RunService") | |
local delay do | |
-- uses a sorted singly linked list (queue) to achieve O(1) remove operations and O(n) for insert | |
local first -- the initial node in the linked list | |
local connection -- the Heartbeat `RBXScriptConnection | nil` | |
function delay(seconds, resolve) | |
assert(type(seconds) == "number", "Bad argument #1 to delay, must be a number.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface BinaryOperation { | |
symbols: ReadonlyArray<string>; | |
call: (a: number, b: number) => number; | |
precedence: number; | |
leftAssociative: boolean; | |
} | |
// function* parseStr(str: string) { | |
// let lastIndex = 0; | |
// const reg = /(?<whitespace>\s+)|(?<hex>0x[0-9A-Fa-f]+\.?[0-9A-Fa-f]*)|(?<octal>0o[0-7]+\.?[0-7]*)|(?<binary>0b[01]+\.?[01]*)|(?<decimal>\d+\.?\d*)|(?<binaryOperator>[-\+\*/])/gu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- From Wikipedia @https://en.wikipedia.org/wiki/Xiaolin_Wu's_line_algorithm | |
-- Xiaolin Wu's line algorithm | |
local StarterGui = game:GetService("StarterGui") | |
StarterGui:ClearAllChildren() | |
local Screen = Instance.new("ScreenGui", StarterGui) | |
local Triangle = Instance.new("Frame", Screen) | |
Triangle.BackgroundColor3 = Color3.fromRGB(255, 255, 255) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- code compiled by Roblox-TS | |
local _exports; | |
local getSignificantDigits = function(n) | |
local str = tostring(n); | |
if tonumber(str) == n then | |
return str; | |
end; | |
for i = 15, 99 do | |
str = ("%." .. tostring(i) .. "g"):format(n); | |
if tonumber(str) == n then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- The lightest Event library ever | |
-- @author Validark | |
-- Micro-optimizations | |
local coroutine_yield = coroutine.yield | |
local coroutine_resume = coroutine.resume | |
local coroutine_create = coroutine.create | |
local coroutine_running = coroutine.running | |
local Event = {} |