Skip to content

Instantly share code, notes, and snippets.

View DarkWiiPlayer's full-sized avatar
💭
OwO

Wii DarkWiiPlayer

💭
OwO
View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
function setup(root) {
root.parts = {}
root.querySelectorAll("[part-id]").forEach( element => {
root.parts[element.getAttribute("part-id")] = element
})
root.clone = function() { return setup(this.cloneNode(true)) }
return root
}
function template(strings, ...args) {
<style>
form { display: flex; flex-flow: column }
</style>
<form>
<input type="range" min="0" max="100" value="100" id="value">
<input type="range" min="0" max="100" value="100" id="modulus">
<input type="range" min="0" max="100" value="100" id="modulo" disabled>
</form>
local lpeg = require 'lpeg'
local function loader(name, version)
local version = table.concat(version, "_")
return function(module)
return require(module:gsub("[^.]*", function(original)
return original .. "." .. version
end))
end
end
<!doctype html>
<!-- vim: set noexpandtab tabstop=3 :miv -->
<script type="text/javascript">
class BetterHTMLElement extends HTMLElement {
attributeChangedCallback(name, old, value) { this[name+"Changed"](value, old) }
#connected = [];
get connected() {
--- Resolves a missing key in a table to one of its mixins (in order)
local function resolve(tab, key)
local mt = getmetatable(tab)
for i=mt.mixins,0,-1 do
if mt[i][key] then
return mt[i][key]
end
end
end
@DarkWiiPlayer
DarkWiiPlayer / locals.lua
Last active May 5, 2020 06:38
Iterate through all locals at given stack level
local function locals(f)
local f = (f or 1) + 1
return function(state, iter)
iter = iter + 1
local name, value = debug.getlocal(state, iter)
if name then
return iter, name, value
end
end, f, 1
end
#include <lua.h>
#include <stdio.h>
int compare(lua_State *L)
{
const char *first = lua_tostring(L, 1);
const char *second = lua_tostring(L, 2);
for (int i=0; first[i]>0; i++)
{
if (!second[i]) return 0; // Abort if second is shorter than first
local trait = {__call = function(self, new) return self:initialize(new) end}
function trait:initialize(new) return setmetatable(new, self) end
setmetatable(trait, trait)
local class = trait {__call = trait.__call}
function class:__index(key) return self.parent and self.parent[key] end
function class:initialize(new) new = new or {}; new.parent = self; return setmetatable(new, class) end
return {
--[[ Suggestion:
Add syntax sugar for `foo:bar` to be equivalent to `foo.bar, foo`
--]]
local stack = {
1, 2, 3, 4;
pop = function(self) return table.remove(self) end;
push = function(self, val) return table.insert(self, val) end;
}