Skip to content

Instantly share code, notes, and snippets.

@charlespwd
charlespwd / exploit.js
Last active January 10, 2024 19:35
exploit.js
console.log(top);
console.log(top.opener);
# This code is a vectorized R version of the Lighthouse scoring code
# that you can find here:
# https://github.com/GoogleChrome/lighthouse/blob/9e0e9dfb67a3dd38b611b02d1129b197da8a2b0c/lighthouse-core/lib/statistics.js#L75-L97
INVERSE_ERFC_ONE_FIFTH <- 0.9061938024368232
erf <- function(x) {
s <- sign(x)
x <- abs(x)
a1 <- 0.254829592
#!/usr/bin/env bash
file=$1
n=$2
if [[ $# -lt 2 ]]; then
cat <<- EOD
Usage: $0 <path> <number_of_files>
EOD
fi
addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event.request))
})
const sleep = ms => new Promise(r => setTimeout(r, ms));
async function handleRequest(request) {
const url = new URL(request.url)
// Disallow crawlers
@charlespwd
charlespwd / sh
Created October 19, 2020 19:58
Save Blob URL to File
# How it works: They're just base64'd with a small header at the start
# Trim the header + decode and there you have it!
# (just make sure you're using the appropriate file type)
# macOS
pbpaste | sed 's#data[^,]+,##' | base64 -d > image.png
open image.png
# Linux (IIRC)
xclip -sel clipboard -o | sed 's#data[^,]+,##' | base64 -d > image.png
@charlespwd
charlespwd / gs-optims.js
Created October 9, 2020 13:46
Cloudflare Worker Performance Optimizations
/* Started from https://andydavies.me/blog/2020/09/22/exploring-site-speed-optimisations-with-webpagetest-and-cloudflare-workers */
const site = 'www.gymshark.com'
addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const url = new URL(request.url)
@charlespwd
charlespwd / make-mp4-from-profile
Last active November 1, 2020 09:19
Make a mp4 from a Chrome DevTools Performance Profile
#!/usr/bin/env bash
set -eou pipefail
profile=$1
frameRate=${2:-10}
timeline='timeline.json'
cat $profile \
| jq '.[] | select(.args.snapshot | . and (type == "string") and contains("/9j"))' \
| jq -s . \
> $timeline
(function trackOnClickFPS() {
window.dataLayer = window.dataLayer || [];
var start = performance.now();
var end = start;
var diff = 0;
var page = "";
var frameCount = 0;
var frcurr = start;
var frprev = start;
var frdiff = 0;
@charlespwd
charlespwd / 4clojure-p50
Created January 19, 2015 17:24
4clojure Problem 50. Split by Type Solution
#(vals (group-by type %))