A tiny zero-dependency compression middleware for polka (& express!) with native Brotli support.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
((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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:
- Static module syntax is beneficial in lots of ways – code is easier to write (you get better linting etc) and easier to optimise (tree-shaking and other things that are only really possible with static syntax), and most importantly, faster to load (it's trivial for a module loader to load multiple dependencies concurrently when they're declared with a static syntax – not so with imperative statements like
require(...)
orawait import(...)
). - App startup time is perhaps when performance is most critical. (You already know this, I don't need to cite the studies.)
- If you're in favour of constructs that jeopardise app startup time, you are anti-user. Top-level
await
is such a construct.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Copyright 2016 Jeremie Miserez <[email protected]> | |
// | |
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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} && |
NewerOlder