Skip to content

Instantly share code, notes, and snippets.

View callumbrieske's full-sized avatar

Callum Brieske callumbrieske

  • Auckland, New Zealand
View GitHub Profile
-- Generic Radio Group Constructor.
local function radio(controls, allowOff)
local handlers = {}
-- Radio logic function.
local function doRadio(control)
local currentIdx = 0
for i, v in ipairs(controls) do
local initialValue = v.Boolean
v.Boolean = v == control and (not allowOff and true or control.Boolean)
@callumbrieske
callumbrieske / File IO.lua
Last active April 29, 2020 11:00
Q-Sys File IO
json = require("rapidjson")
myData = {
valuea = "This is value a",
valueb = "This is value b",
valuec = "This is value c",
}
--
-- We can create/overwrite a file like this:
@callumbrieske
callumbrieske / checksums.lua
Last active February 20, 2024 17:26
Module 256 checksums
data = "\x00\x00\x02\x02\x00"
local function modulo( data )
local checksum = 0
for _, byte in ipairs( table.pack( data:byte( 1, #data ) ) ) do
checksum = ( checksum + byte ) % 256
end
return string.char( checksum )
end
thisCoreSNMP = SNMPSession.New(SNMP.SessionType.V2c)
thisCoreSNMP:setHostName(Network.Interfaces()[1].Address)
thisCoreSNMP:setCommunity("public")
thisCoreSNMP:startSession()
function mySNMPCallback(response)
if response.Error then
error(("There was an SNMP error: %s"):format(d.Error))
else
json = require("rapidjson") -- Load the rapidjson library to parse the responses.
queryTimer = Timer.New()
-- Setup your server details here:
Server = {
Address = "127.0.0.1", -- The address of the server
--Port = 80, -- Optional, the port to connect on. Defaults to 80.
Timeout = 5, -- Time to wait for a responce before throwing an error.
QueryInterval = 10 -- How often to poll the endpoint. This should probably be longer than the timeout.
}
local items = {
"Bacon",
"Lettuce",
"Tomato"
}
Controls.list.Choices = items
Controls.list.EventHandler = function(ctl)
print(ctl.String .. " has been selected!")
@callumbrieske
callumbrieske / IPv4 Address Validation.lua
Last active February 12, 2022 06:54
IPv4 Address Validation
-- Check if 'address' is a valid IPv4 address.
local function check_ip_address(address)
local a, b, c, d = (address or ""):match("^(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)%.(%d%d?%d?)$")
a, b, c, d = tonumber(a), tonumber(b), tonumber(c), tonumber(d)
return
not not (a and b and c and d)
and (a >= 0 and a <= 255)
and (b >= 0 and b <= 255)
and (c >= 0 and c <= 255)
and (d >= 0 and d <= 255)