Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ 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; | |
} |