Skip to content

Instantly share code, notes, and snippets.

@paulirish
paulirish / Code.gs
Created Mar 4, 2022
finding most common senders in gmail - apps script
View Code.gs
// this is pretty quick and rough.. but it works
// script.google.com
// settings to allow editing the appscript.json
// set these two files
// then hit Run with function 'run'
const all = {};
function run() {
@paulirish
paulirish / InteractionsEventTiming.js
Last active Dec 9, 2021 — forked from anniesullie/InteractionsEventTiming.js
This gist pokes around with interactions in the EventTiming API. It tries to get the interaction latency, delay, processing time breakdown, type, and target.
View InteractionsEventTiming.js
const interactionMap = new Map();
function logInteraction(interaction) {
const clamp = val => Math.round(val * 100) / 100; // clamp to 2 decimal places
console.groupCollapsed(`${interaction.type} interaction`, clamp(interaction.latency));
console.log(`total latency`, clamp(interaction.latency));
console.log('delay:', clamp(interaction.delay));
console.groupCollapsed(`processing time in ${Object.entries(interaction.processingTimes).length} entries:`, clamp(interaction.processingTime));
for (const [e, t] of Object.entries(interaction.processingTimes)) {
@paulirish
paulirish / background-lh.js
Created Nov 17, 2021
run lighthouse headlessly
View background-lh.js
'use strict';
import fs from 'fs';
import puppeteer from 'puppeteer';
import {navigation} from 'lighthouse/lighthouse-core/fraggle-rock/api.js';
// Run Lighthouse headlessly, just Performance
(async function() {
const browser = await puppeteer.launch({headless: true});
@paulirish
paulirish / asciiify-the-canvas.js
Last active Oct 5, 2021
ascii rendering of a canvas
View asciiify-the-canvas.js
// works great on about:dino
// 1. save this file to your snippets.
// 2. load about:dino
// 3. evaluate the snippet
// 4. hit up arrow to trigger the game.
// 5. profit
(function() {
perfnow = performance.now;
View localhost_2018-03-12_17-55-45.lighthouse.report.json
{"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3358.0 Safari/537.36","environment":{"networkUserAgent":"Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5 Build/MRA58N) AppleWebKit/537.36(KHTML, like Gecko) Chrome/66.0.3359.30 Mobile Safari/537.36","hostUserAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3358.0 Safari/537.36","benchmarkIndex":1000},"lighthouseVersion":"4.3.1","fetchTime":"2018-03-13T00:55:45.840Z","requestedUrl":"http://localhost:10200/dobetterweb/dbw_tester.html","finalUrl":"http://localhost:10200/dobetterweb/dbw_tester.html","runWarnings":[],"audits":{"is-on-https":{"id":"is-on-https","title":"Does not use HTTPS","description":"All sites should be protected with HTTPS, even ones that don't handle sensitive data. HTTPS prevents intruders from tampering with or passively listening in on the communications between your app and your users, and is a prerequisite for HTTP/2 and man
@paulirish
paulirish / thing.js
Created May 7, 2018
log the clipboard contents
View thing.js
document.body.innerHTML = 'Paste or drop items onto this page. View results in console.';
function getPayload(item) {
const kind = item.kind;
switch (kind) {
case 'string': return new Promise(res => item.getAsString(res));
case 'file': return Promise.resolve(item.getAsFile());
default: throw new Error('unknown item kind! ' + kind);
}
@paulirish
paulirish / generate_report.js
Last active May 8, 2022
hacking on lighthouse report
View generate_report.js
'use strict';
/* eslint-disable */
const fs = require('fs');
const path = require('path');
const ReportGenerator = require('../../lighthouse-core/report/report-generator');
const jsonPath = __dirname + '/../_json/';
@paulirish
paulirish / eqt.js
Last active Apr 26, 2020
Expected Queueing Time metric
View eqt.js
// Expected Queueing Time
// https://docs.google.com/document/d/1Vgu7-R84Ym3lbfTRi98vpdspRr1UwORB4UV-p9K1FF0/edit
// Initial impl by Nicolás Peña (npm), Tim Dresser (tdresser)
// Usage:
// var eqt = EQT.begin();
// // ...
// const {expectedQueueingTime} = EQT.end();
class EQT {
constructor() {
View genesis_public_key
0459bbe48fa3e4591000459ccc8f6a6e0b046f51acbfacd862e9d402b5379d3ff00a6569b94f838772e0362eba4af38f9a856d177b9b8f936615f21cc5607a803e
@paulirish
paulirish / log-the-datatransfer-data.js
Created Feb 15, 2018
log paste and copy event payloads
View log-the-datatransfer-data.js
document.body.innerHTML = 'Paste or drop items onto this page. View results in console.';
function getPayload(item) {
const kind = item.kind;
switch (kind) {
case 'string': return new Promise(res => item.getAsString(res));
case 'file': return Promise.resolve(item.getAsFile());
default: throw new Error('unknown item kind! ' + kind);
}