Skip to content

Instantly share code, notes, and snippets.

View koenbok's full-sized avatar

Koen Bok koenbok

View GitHub Profile
import React from "react"
export function TestComponent() {
return React.createElement("div", {}, "Hello World")
}
export function memoize<R, T extends (...args: any[]) => R>(f: T): T {
const cache = new Map<string, R>();
return ((...args: any[]) => {
const key = JSON.stringify(args);
if (!cache.has(key)) cache.set(key, f(...args));
return cache.get(key);
}) as T;
}
@koenbok
koenbok / duplicate-css.js
Created November 27, 2021 17:06
Find duplicate styles
const rules = Array.from(document.getElementsByTagName("style"))
.map((el) => el.innerText.split("}"))
.flat()
.map((rule) => rule.trim())
.filter((rule) => rule && !rule.startsWith("@"))
.map((rule) => {
return {
selector: rule.split("{")[0].trim(),
style: rule.split("{")[1].trim(),
};
<script>
function onPathChange(callback) {
let path;
// Only reliable way seems polling across browsers :-(
setInterval(() => {
if (window.location.pathname !== path) {
path = window.location.pathname;
callback(path);
}
}, 1000);
@koenbok
koenbok / framer-pageview.js
Created January 11, 2023 11:59
Track page views in Framer
// https://stackoverflow.com/a/64927639
function addPushStateListener(listener) {
if (!Proxy) return;
window.history.pushState = new Proxy(window.history.pushState, {
apply: (target, thisArg, argArray) => {
target.apply(thisArg, argArray);
listener();
},
});
}
s3.put invalidation-speed-test/9jxb7yu7hVk4p3jiuXDlyHuBNbBsG0DK
s3.put invalidation-speed-test/9jxb7yu7hVk4p3jiuXDlyHuBNbBsG0DK done
YUL62-P2 Miss from cloudfront 189
DUB56-P2 Miss from cloudfront 454
FRA56-P5 Miss from cloudfront 519
SFO53-P6 Miss from cloudfront 419
GRU3-P3 Miss from cloudfront 607
BOM78-P5 Miss from cloudfront 908
SIN2-P3 Miss from cloudfront 1012
NRT57-P4 Miss from cloudfront 729