Skip to content

Instantly share code, notes, and snippets.

View DarkWiiPlayer's full-sized avatar
💭
OwO

Wii DarkWiiPlayer

💭
OwO
View GitHub Profile
@DarkWiiPlayer
DarkWiiPlayer / resty-install.sh
Last active February 3, 2024 11:39
Openresty installation script
#!/bin/bash
# This script installs OpenResty on an ubuntu-like system.
if [ "$(id -u)" -ne 0 ]
then
echo 'must run as root 😖'
exit
fi
umask a+rx
@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 / 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 / bench.lua
Last active April 30, 2022 13:54
Lua benchmark: closures vs. coroutines
local times = 100000
local start = os.clock()
for i=1,times do
local closure = function()
print("test")
end
end
print(os.clock() - start)
@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 / 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
local function locals(n)
n = n + 1
local result = {}
for i=1,math.huge do
name, value = debug.getlocal(n, i)
if not name then break end
result[name] = {value}
end
return result
end
@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)