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 / 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 / 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 / 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()
}))()
#!/usr/bin/env luajit
local c = require 'ansicolors'
local pegasus = require 'pegasus'
local http = require 'socket.http'
local ip = http.request('http://darkwiiplayer.com/api/ip')
math.randomseed(os.time())
@DarkWiiPlayer
DarkWiiPlayer / bench.lua
Last active May 16, 2019 12:16
Benchmark for memoization of a simple index translation function
local ffi = require 'ffi'
local intidx_fnc do
if ffi.abi('le') then
function intidx_fnc(n)
if n<1 or n>4 then
error("wrong index", 2)
end
return n-1
end
@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"