Skip to content

Instantly share code, notes, and snippets.

View nefftd's full-sized avatar

Anthony Eadicicco nefftd

View GitHub Profile
-- depends on tostringall() https://gist.github.com/nefftd/11382819
-- see: line 15
do
local err_fmt = "bad argument #%d to '%s' (%s expected, got %s)"
local function checktypelist(t,a1,...)
if a1 then
return t == a1 or checktypelist(t,...)
end
end
do
local function _tsa(n,a,...)
if n > 0 then
return tostring(a),_tsa(n-1,...)
end
end
function tostringall(...)
local n = select('#',...)
if n > 0 then
function math.isinf(x)
argcheck(x,1,'number')
return (
x == math.huge and 1 or
x == -math.huge and -1
)
end
function math.isnan(x)
do
local function shallowcopy(tbl)
local new = {}
for k,v in next,tbl do
new[k] = v
end
return new
end
local function deepcopy(tbl)
@nefftd
nefftd / argcheck.moon
Created June 13, 2014 21:44
argcheck (moonscript)
do
checktypelist = (t,a1,...) ->
t == a1 or checktypelist t,... if a1 ~= nil
export argcheck = (val,argn,...) ->
return if checktypelist type(val),...
types = '/'\join tostringall ...
fname = debug.getinfo(2,'n').name or 'unknown'
error "bad argument ##{tonumber(argn) or '?'} to '#{fname}' (#{types} expected, got #{type val})",3
@nefftd
nefftd / tostringall.moon
Created June 13, 2014 21:48
tostringall (moonscript)
do
tsa = (n,a,...) ->
tostring(a),tsa(n-1,...) if n > 0
export tostringall = (...) ->
n = select '#',...
tsa n,... if n > 0
-- lol
setmetatable(myarray,{
__len = function(self)
local n = 0
while self[n+1] do
n = n + 1
end
return n
end
})
@nefftd
nefftd / wowbucket.lua
Created June 22, 2014 16:09
Super simple bucket implementation for World of Warcraft addons, to deal with events which are too spammy for their own good.
-- Here's a super-simple implementation of something like bucket events. The
-- idea is, you want to call some code, but the event you're listening to is
-- very spammy (many times per second!), and it's just not necessary to update
-- that often. So when the event first occurs, we start a timer to call the
-- actual routines. Subsequent occurances of the event simply fail silently
-- until the timer is finished. So your code only runs at most every N seconds
-- see: BUCKET_DELAY. Caveat: even if the event only runs once, there will be a
-- delay of N seconds before your routines get called. Tweak BUCKET_DELAY to
-- your needs. Caveat 2: you can't collect arguments (can be implemented, but
-- not trivially).
local name,realm = UnitName(unit)
if not realm or realm == '' then realm = GetRealmName() end
name = name..'-'..realm
local _,dtype
for i = 1,40 do
_,_,_,_,dtype = UnitAura(unit,i,'HARMFUL')
if dtype == 'Magic' then
return '[M]' -- DOES have magic debuff; change as you see fit
end
end
return '' -- DOESN'T have magic debuff; change as you see fit