Skip to content

Instantly share code, notes, and snippets.

View nefftd's full-sized avatar

Anthony Eadicicco nefftd

View GitHub Profile
local Stack = {}
Stack.__index = Stack
function Stack:push(value)
table.insert(self,value)
end
function Stack:pop()
return table.remove(self)
-- Holy Power
local holypower_colors = {'ffffff','fff880','f5e92f','53ff4a','53ff4a'}
oUF.Tags.Methods["lumen:holypower"] = function(unit)
local hp = UnitPower('player', SPELL_POWER_HOLY_POWER) or 0
if hp > 0 then
return ('|cff%s%d|r'):format((holypower_colors[hp] or 'ffffff'),hp)
end
local MAX_UNPACK_SIZE = 500000
function bigger_cleanear_jenna(len)
local string = {}
local chunk = {}
local n = 1
local chunk_length
repeat
chunk_length = math.min(len,MAX_UNPACK_SIZE)
function big_jenna(len)
local S,s,n,L = {},{},1
repeat
L = math.min(len,10000)
for i = 1,L do
s[i] = math.random(33,126)
end
S[n] = string.char(unpack(s,1,L))
n = n + 1
len = len - L
local function big_jenna(len)
if len < 1 then return '' end
local s = {}
for i = 1,math.min(len,10000) do
s[i] = math.random(33,126) -- change to desired printable range [1,256]
end
return string.char(unpack(s)) .. big_jenna(len - 10000)
end
local function genpass(len)
local amin,amax = unpack(ASCII_PRINTABLE)
local pass = {}
for i = 1,len do
pass[i] = math.random(amin,amax)
end
return string.char(unpack(pass))
end
-- String functions
local tsa_r -- recursion TSA
local tsa_a -- array-based TSA
do
local function _tsa(n,a,...)
if n > 0 then
return tostring(a),_tsa(n-1,...)
end
end
-- In the above we have an interesting tradeoff. Recursion doesn't waste table
-- every invocation, so it's not pushing the GC hard. However, it internally
-- pushes and pops values from the stack every iteration. Whereas the array
-- method only needs to allocate a single stack slot, and after all is really
-- just a standard C array, which ought to be quite efficient. Which is more
-- efficient is not easy to tell.
-- Here, we have a test:
do
local types = {nil,true,0,'string',io.stdout,function()end,print,coroutine.create(function()end),{}}
-- Problem: it appears to be impossible to protect a metatable from being unset
-- while also allowing Lua-side code to read/write metamethods. The solution is
-- to use a proxy.
-- The idea is, we use __metatable so that getmetatable() returns a proxy
-- object which inherits from the real metatable. User code can read/write
-- fields to the real metatable through this proxy.
-- Note: Keep __metatable intact on the proxy to (1) protect user code from
-- changing the behavior of the proxy and (2) protect user code from getting
-- READ ONLY FORM
local mt = {} -- The real metatable
local mt_proxy = {} -- The object returned by getmetatable()
setmetatable(mt_proxy,{
__index = function(self,k) return mt[k] end, -- Allow the proxy to read fields. use a function so it's opaque (user cannot access real metatable)
__newindex = function() end, -- But writing is a nop (__newindex must exist, otherwise we may accidentally barr access to __index fields)
__metatable = false, -- Do not allow user code to overwrite the behavior of the proxy
})