Skip to content

Instantly share code, notes, and snippets.

View DarkWiiPlayer's full-sized avatar
💭
OwO

Wii DarkWiiPlayer

💭
OwO
View GitHub Profile
@DarkWiiPlayer
DarkWiiPlayer / benchmark.html
Last active May 30, 2023 08:59
A simple benchmark to compare full re-render of a large table vs. updating individual text contents vs. updating them selectively.
<!doctype html>
<!-- Set type to one of "full", "all" or "selective" -->
<fun-matrix type="selective">
</fun-matrix>
<script type="module">
import {html} from "https://darkwiiplayer.github.io/js/skooma.js"
import element from "https://darkwiiplayer.github.io/js/element.js"
local based = require 'based.32.crockford'
local basexx = require 'basexx'
local function bench(name, fn, vector)
local before = os.clock()
for _, input in ipairs(vector) do
fn(input)
end
local after = os.clock()
print(string.format("%-10s %1.6f seconds", name..":", after-before))
@DarkWiiPlayer
DarkWiiPlayer / hijack.js
Created March 1, 2022 12:01
Proof of concept of hijacking individual keys directly in an object and assigning them change callbacks
values = Symbol("values")
hijack = (object, callbacks) => {
const val = object[values] ||= Object.create(null)
Object.entries(callbacks).forEach(([key, callback]) => {
Object.defineProperty(object, key, {
get() { return val[key] },
set(value) {
callback(value)
val[key] = value
return true
@DarkWiiPlayer
DarkWiiPlayer / timer.html
Created August 3, 2021 14:33
HTML Timer
<script type="module">
import {Better} from "/better.js"
class ConstantInterval extends Better {
#timer
static attributes = {
interval: { get: Number },
onTick: {
get: Function,
set: e => `(${e.toString()})()`
@DarkWiiPlayer
DarkWiiPlayer / Collisions.md
Created February 15, 2021 12:55
Thoughs on how to implement 2D collision handling

Polygon-Polygon collision

let A and B be polygons

let a and b be vectors representing the movement of said polygons within a game tick

let c be the movement of A relative to B a-b

calculate the transformation matrix Ta that transforms c into the vector (1, 0)

local fun = require 'fun' ()
local function avg(...)
local sum, count = 0, 0
for i=1,select('#', ...) do
count = count + 1
sum = sum + select(i, ...)
end
return sum / count
end
local tableview = require 'tableview'
local pegasus = require 'pegasus'
local print = function(...)
print(...)
io.stdout:flush()
end
local function serve(tab)
local server = pegasus:new {
@DarkWiiPlayer
DarkWiiPlayer / glass.js
Created February 1, 2021 09:22
A somewhat nicer frosted glass effect using SVG filters
let template = document.createElement("template")
template.innerHTML = `
<svg>
<defs>
<filter id="zoom">
<feTurbulence type="turbulence" baseFrequency="0.05" numOctaves="2" />
<feGaussianBlur in="distorted" stdDeviation="2" result="turbulence" />
<feDisplacementMap in2="turbulence" in="SourceGraphic" scale="10" xChannelSelector="R" yChannelSelector="G" result="distorted"/>
<feGaussianBlur in="distorted" stdDeviation="2" />
local function time(times, fn)
local before = os.clock()
for i=1,times do
fn()
end
local after = os.clock()
return after - before
end
local function bench(name, times, fn)
local t = setmetatable({}, {__name="foobar"})
print(type(t)) --> foobar
print(rawtype(t)) --> table