Skip to content

Instantly share code, notes, and snippets.

View DarkWiiPlayer's full-sized avatar
💭
OwO

Wii DarkWiiPlayer

💭
OwO
View GitHub Profile
#!/bin/lua
local lib = {}
function lib.pair(init)
local variable = init
return function()
return variable
end, function(value)
variable = value
@DarkWiiPlayer
DarkWiiPlayer / 0. Abstract
Last active August 9, 2023 14:10
Lua vararg iteration benchmark
This small benchmark test compares the performance of using `ipairs{...}` vs.
`select('#',<n>)` to iterate over the arguments inside a variadic function.
@DarkWiiPlayer
DarkWiiPlayer / example.html
Last active February 7, 2018 14:52
Weird Chrome Bug
<style>
* {
margin: 0;
padding: 0;
}
svg.template {
height: 0em;
width: 0em;
display: block;
}
@DarkWiiPlayer
DarkWiiPlayer / levenshtein.moon
Created February 27, 2018 09:05
Levenshtein distance in moonscript
import min from math
levenshtein = (a, b) ->
c = {nil, nil, nil, nil, nil}
p = {nil, nil, nil, nil, nil}
for i=1,#a+1
c[i]=i-1 -- Distance to ""
for i=1,#b
p,c = c,p
c[1] = i -- Distance from ""
local mod = {}
local meta = {
__call = function(tab, ...)
if not tab.func then
tab.func = tab.loader()
end
tab.func(...)
end
@DarkWiiPlayer
DarkWiiPlayer / bug.moon
Created July 31, 2018 10:56
Moonscript Bug
env = do
local env
env = _ENV
setmetatable {}, {
__index: (key) =>
env[key] or (...) ->
@.tag(key, ...)
}
@DarkWiiPlayer
DarkWiiPlayer / badge.moon
Last active January 12, 2022 03:38
love2d version badge generator
height = 20
width = 100
split = 6/10
tag = (number, color='#ea316e') ->
buf = require'strbuffer'!
generator = require'moonxml'.xml ->
svg {
xmlns: 'http://www.w3.org/2000/svg'
:width
@DarkWiiPlayer
DarkWiiPlayer / vector_2d.lua
Last active September 16, 2018 18:38
LuaJIT vectors
--- Vector objects with several mathematical operations
-- @author DarkWiiPlayer
-- @license MIT
-- luacheck: ignore 4.1
local transformation, array4 = require "classes.transformation"
local ffi = require "ffi"
local sin, cos = math.sin, math.cos
@DarkWiiPlayer
DarkWiiPlayer / pool.lua
Last active May 17, 2019 20:51
Lua Pool
--- An abstract implementation of an object pool
-- @usage
-- local pool = require("pool"){
-- initialize = function(elem) elem.name = "John Doe"; return elem end;
-- max = 50;
-- }
-- local elem = pool:get() -- Creates a new element because pool is empty
-- print(elem.x) --> John Doe -- pool:put(elem) -- Puts element back into pool --- You know, the thing that this is all about, the pool class -- @type pool
local math = require "math"
@DarkWiiPlayer
DarkWiiPlayer / example.moon
Last active October 20, 2018 15:38
Weird moonscript bug
moonscript = require "moonscript"
moonscript.loadstring('print "\\nHere I am!"', 'string', 't', setmetatable({}, {
__index: (key) =>
print "index", key
for key, value in pairs debug.getinfo 2
print '', key, value
print debug.traceback()
}))()