Polkompress
A tiny zero-dependency compression middleware for polka (& express!) with native Brotli support.
const puppeteer = require('puppeteer'); | |
const { createCanvas, loadImage } = require('canvas') | |
const mustache = require('mustache') | |
var fs = require('fs'); | |
const fsExtra = require('fs-extra') | |
let MAX_URLS = 50; | |
let TEMPLATE = fs.readFileSync('template.html', 'utf8'); |
A tiny zero-dependency compression middleware for polka (& express!) with native Brotli support.
// Idea and some code stemming from https://michaljanaszek.com/blog/test-website-performance-with-puppeteer#cacheAndServiceWorker | |
const puppeteer = require('puppeteer'); | |
const devices = require('puppeteer/DeviceDescriptors'); | |
const {URL} = require('url'); | |
var fs = require('fs'); | |
var sw_scope; | |
let NETWORK_PRESETS = { | |
'GPRS': { | |
'offline': false, |
((name, context = window, func) => { context[name] = func() }) | |
('CpuMeter', this, () => { | |
const isEmptyObject = object => Object.keys(object).length === 0 | |
const getProcessorUsage = (usage, oldUsage) => | |
Math.floor((usage.kernel + usage.user - oldUsage.kernel - oldUsage.user) / (usage.total - oldUsage.total) * 100) | |
class CpuMeter { | |
constructor() { | |
if (!chrome || !chrome.system || !chrome.system.cpu) { | |
throw new Error(`No access to chrome.system.cpu! |
import * as fs from "fs"; | |
import { createSession } from "chrome-debugging-client"; | |
createSession(async (session) => { | |
let browser = await session.spawnBrowser("canary"); | |
let api = await session.createAPIClient("localhost", browser.remoteDebuggingPort); | |
let tabs = await api.listTabs(); | |
let tab = tabs[0]; | |
let client = await session.openDebuggingProtocol(tab.webSocketDebuggerUrl); | |
await client.send("Profiler.enable"); |
Follow-up to Top-level await is a footgun – maybe read that first
Here are some things I believe to be true:
require(...)
or await import(...)
).await
is such a construct.javascript:(function(){(function printStats(){var loadTimes=window.chrome.loadTimes();firstPaint=loadTimes.firstPaintTime*1000;firstPaintTime=firstPaint-(loadTimes.startLoadTime*1000);console.info('First paint took',firstPaintTime,'ms');console.info('Load took',performance.timing.loadEventStart-performance.timing.navigationStart,'ms');var instances=0;if(parseFloat(Polymer.version)<1){instances=[].slice.call(document.querySelectorAll('html /deep/ *')).filter(function(el){return el.localName.indexOf('-')!=-1||el.getAttribute('is');}).length;}else{instances=Polymer.telemetry.instanceCount;}console.info('Custom element instances:',instances);var reflectCount=0;if(Polymer.telemetry){console.info('=== Properties set to reflectToAttribute ===');Polymer.telemetry.registrations.forEach(function(el){for(var prop in el.properties){if(el.properties[prop].reflectToAttribute){console.log(el.is+'.'+prop);reflectCount++;}}});}else{console.info('=== Properties set to reflect ===');Polymer.elements.forEach(function(el){for(var |
// Copyright 2016 Jeremie Miserez <jeremie@miserez.org> | |
// | |
// MIT License | |
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | |
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF O |
let tee = (a) => {console.log(String(a)); return a} | |
// our applicator | |
let $_ = (n) => { | |
let args = new Array(n); | |
for (let i = 1; i <= n; i++) { | |
args[i-1] = `$${i}` | |
} | |
return (raw, ...values) => | |
Function(...args.concat(tee('return ' + raw.reduce( |
# npm publish with goodies | |
# prerequisite: `npm install -g trash` | |
# `np` with an optional argument `patch`/`minor`/`major`/`<version>` | |
# defaults to `patch` | |
np() { | |
trash node_modules &>/dev/null; | |
git pull --rebase && | |
npm install && | |
npm test && | |
npm version ${1:-patch} && |