Skip to content

Instantly share code, notes, and snippets.

View stravant's full-sized avatar

Mark Langen stravant

  • Beamdog
  • Edmonton AB, Canada
View GitHub Profile
@stravant
stravant / DatastoreBytes.lua
Created October 24, 2023 04:50
Module which packs a sequence of variable length integers into a Datastore safe string at maximal density
local DS_INT_TO_INT = {} :: {[number]: number}
local INT_TO_DS_INT = {} :: {[number]: number}
local INT_TO_DS_CHAR = {} :: {[number]: string}
local DS_INT_MAX;
do
-- All characters under this are control characters, must avoid them because
-- they get expanded out into control sequences.
local MIN_DS_VALUE = 0x20
local MAX_DS_VALUE = 0x7E
for i = 1, 5 do
local part = game.ReplicatedStorage.FogPart:Clone()
part.Parent = workspace
part.Position = Vector3.new(0, i * 10, 0)
end
workspace.Checkpoints.ChildAdded:Connect(function(checkpoint)
if checkpoint.Name == "100" then
checkpoint.Touched:Connect(function(hit)
... same touched stuff
end)
end
end)
@stravant
stravant / createSharedToolbar.lua
Created August 15, 2022 07:48
createSharedToolbar Module
local CoreGui = game:GetService("CoreGui")
export type SharedToolbarSettings = {
ButtonName: string,
ButtonIcon: string,
ButtonTooltip: string,
ToolbarName: string,
CombinerName: string,
ClickedFn: () -> (),
@stravant
stravant / createSharedToolbar.lua
Created June 23, 2022 07:02
Module that manages a toolbar shared by multiple plugins in a way that supports reloading.
local CoreGui = game:GetService("CoreGui")
export type SharedToolbarSettings = {
ButtonName: string,
ButtonIcon: string,
ButtonTooltip: string,
ToolbarName: string,
CombinerName: string,
ClickedFn: () -> (),
@stravant
stravant / fetch_masterduel_info.py
Created February 14, 2022 05:32
Fetch info from masterduelmeta.com to compute relative value of SRs / URs.
import requests
import json
import urllib.parse
import re
top_decks_url = "https://www.masterduelmeta.com/api/v1/top-decks?limit=0"
included_cards = {
"Lightning Storm": 1,
"Solemn Judgment": 1,
@stravant
stravant / SignalTypes.bench
Created August 15, 2021 20:55
Benchmark for different types of signal
local ASignal = require(game:GetService("ServerStorage").ASignal)
local FSignal = require(game:GetService("ServerStorage").FSignal)
local function FireMany(sig)
sig:Connect(function() end)
sig:Connect(function() end)
sig:Connect(function() end)
sig:Connect(function() end)
sig:Connect(function() end)
sig:Connect(function() end)
@stravant
stravant / ArrayGoodSignal.lua
Created August 15, 2021 20:52
Array based GoodSignal (not as good as the field based one)
--------------------------------------------------------------------------------
-- Batched Yield-Safe Signal Implementation --
-- This is a Signal class which has effectively identical behavior to a --
-- normal RBXScriptSignal, with the only difference being a couple extra --
-- stack frames at the bottom of the stack trace when an error is thrown. --
-- This implementation caches runner coroutines, so the ability to yield in --
-- the signal handlers comes at minimal extra cost over a naive signal --
-- implementation that either always or never spawns a thread. --
-- --
-- API: --
@stravant
stravant / DictVsArrayVector.bench.lua
Created August 15, 2021 20:32
Comparison of dict vs array vector performance in Roblox Lua
local ArrayVector1 = {1, 2, 3, 4}
local ArrayVector2 = {1, 2, 3, 4}
local ArrayVector3 = {1, 2, 3, 4}
local ArrayVector4 = {1, 2, 3, 4}
local DictVector1 = {x = 1, y = 2, z = 3, w = 4}
local DictVector2 = {x = 1, y = 2, z = 3, w = 4}
local DictVector3 = {x = 1, y = 2, z = 3, w = 4}
local DictVector4 = {x = 1, y = 2, z = 3, w = 4}
@stravant
stravant / Upvalue.bench.lua
Created August 15, 2021 20:23
Showing the cost of not caching the upvalue
local upValueArray = {1}
return {
ParameterGenerator = function()
end;
Functions = {
["Empty loop"] = function()
for i = 1, 10000 do