Skip to content

Instantly share code, notes, and snippets.

View noamr's full-sized avatar

Noam Rosenthal noamr

  • Google
  • United Kingdom
  • 07:10 (UTC +01:00)
  • X @nomsternom
View GitHub Profile
@noamr
noamr / whynp.js
Last active October 10, 2023 04:32
Diagnose INP issues by correlating event timing & long animation frames
(function init() {
function processAndFilterLoAFs(entries) {
function floorObject(o) {
return Object.fromEntries(Array.from(Object.entries(o)).map(([key, value]) => [key, typeof value === "number" ? Math.floor(value) :
value
]))
}
function processEntry(entry) {
const startTime = entry.startTime;
@noamr
noamr / pending-beacon.js
Last active May 16, 2023 17:58
PendingBeacon on top of fetchLater
class UserlandPendingBeacon {
#abortController = null;
// Let's imagine it's a list of plain objects.
#pendingEntries = [];
// URL, headers, defer options etc
#requestInit;
constructor(requestInit) {
@noamr
noamr / script-parsing.js
Last active August 23, 2023 16:34
A polyfill for script element loading (for illustration purposes)
function parseHTML(getNextElement) {
let doneParsing = null;
const whenDoneParsing = new Promise(resolve => { doneParsing = resolve; });
while (const element = getNextElement()) {
if (element.tagName !== "SCRIPT") {
// parse everything else...
continue;
}
addEventListener("fetch", e => {
if (e.request.destination !== "image" || // Only do this when requesting an image
request.mode === "no-cors") // We don't know the status of no-cors images
return;
e.respondWith((async () => {
try {
const response = await fetch(e.request);
if (response.ok)
return response;
export function supportsExifResolution() {
return new Promise((resolve, reject) => {
const image = new Image();
image.src = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAGAAkAAD/4QCwRXhpZgAATU0AKgAAAAgABQEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAAITAAMAAAABAAEAAIdpAAQAAAABAAAAWgAAAAAAAAAYAAAAAQAAACQAAAABAAaQAAAHAAAABDAyMzKRAQAHAAAABAECAwCgAAAHAAAABDAxMDCgAQADAAAAAf//AACgAgADAAAAAQADAACgAwADAAAAAQACAAAAAAAA/9sAQwABAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB/9sAQwEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB/8AAEQgAAQABAwERAAIRAQMRAf/EABQAAQAAAAAAAAAAAAAAAAAAAAr/xAAUEAEAAAAAAAAAAAAAAAAAAAAA/8QAFAEBAAAAAAAAAAAAAAAAAAAAAP/EABQRAQAAAAAAAAAAAAAAAAAAAAD/2gAMAwEAAhEDEQA/AH8A/9k="
image.onload = () => {
if (image.naturalWidth === 3 && image.naturalHeight === 2)
resolve()
else
reject("EXIF resolution is not supported")
}
This file has been truncated, but you can view the full file.
[
{"computedWidth":188,"computedHeight":50,"naturalWidth":188,"naturalHeight":50,"src":"http://ak2.imgaft.com/images/new_logo_GDTrans.png","htmlWidth":null,"htmlHeight":null,"styleWidth":"","styleHeight":"","website":"http://techbays.com/2008/03/10/why-is-redtube-popular/"},
{"computedWidth":240,"computedHeight":134,"naturalWidth":240,"naturalHeight":134,"src":"http://ak2.imgaft.com/images/feature-illu-dot-com-domain.png","htmlWidth":null,"htmlHeight":null,"styleWidth":"","styleHeight":"","website":"http://techbays.com/2008/03/10/why-is-redtube-popular/"},
{"computedWidth":244,"computedHeight":19,"naturalWidth":244,"naturalHeight":19,"src":"http://parked-content.godaddy.com/images/99C_code.png","htmlWidth":null,"htmlHeight":null,"styleWidth":"","styleHeight":"","website":"http://techbays.com/2008/03/10/why-is-redtube-popular/"},
{"computedWidth":1,"computedHeight":1,"naturalWidth":1,"naturalHeight":1,"src":"http://techbays.com/img.aspx?q=L3MkWGAkBQt0AGR5ZmHmZGL5ZmL1ZmR1AlHlAzpyZ3R1ZQNkWGV2MFHmpFHlAz4yZ3RjWGV2
This file has been truncated, but you can view the full file.
[{"computedWidth":88,"computedHeight":31,"naturalWidth":88,"naturalHeight":31,"src":"https://www.wikidata.org/static/images/poweredby_mediawiki_88x31.png","website":"https://www.wikidata.org/wiki/Q35127"},
{"computedWidth":88,"computedHeight":31,"naturalWidth":88,"naturalHeight":31,"src":"https://www.wikidata.org/static/images/wikimedia-button.png","website":"https://www.wikidata.org/wiki/Q35127"},
{"computedWidth":220,"computedHeight":260,"naturalWidth":220,"naturalHeight":260,"src":"https://upload.wikimedia.org/wikipedia/commons/thumb/d/de/Www.wikipedia.org_screenshot.png/220px-Www.wikipedia.org_screenshot.png","website":"https://www.wikidata.org/wiki/Q35127"},
{"computedWidth":110,"computedHeight":58,"naturalWidth":110,"naturalHeight":58,"src":"https://upload.wikimedia.org/wikipedia/commons/thumb/0/0e/Wiki_Loves_Women_South_Asia_Logo-pa.png/110px-Wiki_Loves_Women_South_Asia_Logo-pa.png","website":"https://pa.wikipedia.org/wiki/%E0%A8%AA%E0%A9%8D%E0%A8%B0%E0%A8%B8%E0%A8%BF%E0%A9%B1%E0%A8%A7_%E0%
#include <AxisJoystick.h>
// these constants won't change:
const int piezo1 = A0; // the piezo is connected to analog pin 0
const int piezo2 = A1; // the piezo is connected to analog pin 0
const int piezo3 = A2; // the piezo is connected to analog pin 0
const int piezo4 = A3; // the piezo is connected to analog pin 0
const int minValue = 384; // threshold value to decide when the detected sound is a knock or not
const int maxValue = 1024;
@noamr
noamr / eval.js
Last active December 26, 2017 20:14
await page.evaluate((x, y) => window.scrollBy(x, y), x, y)