Skip to content

Instantly share code, notes, and snippets.

@Anaminus
Anaminus / GenerateHashFunc.lua
Last active September 29, 2020 01:40
Generates a function that maps an amount of integers to a single array index. Also generates a function that performs the inverse of the hash function.
--[[GenerateHashFunc
Generates a function that maps an amount of integers to a single array index.
Also generates a function that performs the inverse of the hash function.
Input: The first two arguments indicate the base of the input and the output,
respectively. If not given, they default to 0 for the input, and 1 for the
output.
Each argument afterwards represents one argument to be passed to the generated
@Anaminus
Anaminus / CachedGet.lua
Created October 30, 2013 20:00
Sends a cached HTTP GET request.
--[[
CachedGet ( url, file, bin, exp )
Sends an HTTP GET request, caching the results for subsequent calls.
`url`: The URL to request.
`file`: The name of the cache file.
`bin`: Whether content is binary. Defaults to false.
`exp`: Cache expiration time, in seconds. Defaults to 1 day.
@Anaminus
Anaminus / FetchAPI.lua
Created October 30, 2013 20:06
Retrieves Roblox API data from one or more specified sources.
--[[
function FetchAPI ( force, sources )
Retrieves Roblox API data from one or more specified sources.
Returns two values: The unparsed API dump string, and a table of class
names and their corresponding explorer image indexes.
- `force`: If a source fails, use the next source to retrieve the data.
* Overview
+ We're providing new Data Persistence API, which lets you store some data
between server runs for ROBLOX places
+ Significant improvement over previous API, including:
- Arbitrary global data, not just per-place data
* Allows to subscribe to updates made by other instances!
- Guaranteed saves - as soon as call returns, data will not be lost
- In future, will allow sharing this data between different places
- Saves arbitrary lua tables
@Anaminus
Anaminus / VSFixedFileInfo.lua
Last active September 29, 2020 01:40
Gets VS version info from an executable.
--[[
VSFixedFileInfo( exePath )
returns:
- High-order word of dwFileVersionMS
- Low-order word of dwFileVersionMS
- High-order word of dwFileVersionLS
- Low-order word of dwFileVersionLS
@Anaminus
Anaminus / ArrayDiff.lua
Last active September 29, 2020 01:40
ArrayDiff gets the difference between to arrays, detecting insertions, removals, swaps, and replacements.
--[[ ArrayDiff
Receives two arrays, and gets the difference between them. Returns a list of
steps that will turn the first array into the second.
- Elements in each array should be unique
- Order of elements matters
Ops:
insert: {1, index, value}
// Thanks:
// http://stackoverflow.com/questions/12396665/c-library-to-read-exe-version-from-linux#answer-12486703
package main
import (
"encoding/binary"
"errors"
"os"
)

Lua Templates

Enables the parsing of basic templates.

Also check out slt2, which is about a million times better!

API

  • Template.Parse ( template, data )
@Anaminus
Anaminus / DrawArcs.lua
Last active September 29, 2020 01:40
DrawArcs
-- LOVE2D 0.9.0
-- main.lua
-- Left-click somewhere to add point
-- Left-click and drag green point to move it
-- Right-click green point to remove it
-- Left-click and drag red point to modify starting angle
-- Backspace to remove all points
local Vector2;Vector2 = {
@Anaminus
Anaminus / fastwait.lua
Created August 16, 2014 19:13
Fast wait
function fast(f)
local function run()
if f() ~= false then
Spawn(run)
end
end
Spawn(run)
end
local time = 1