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
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
<!-- | |
See JSFiddle: | |
http://jsfiddle.net/cowboy/6asBw/ | |
--> | |
<!-- unminified --> | |
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> |
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
function multiply(a, b) { | |
return a * b; | |
} | |
function divide(a, b) { | |
if (b === 0) { | |
throw "Don't try to divide by zero!"; | |
} | |
return Math.round(a / b); |
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'); |
The BBC has a server-side image service which provides developers with multiple sized versions of any image they request. It works in a similar fashion to http://placehold.it/ but it also handles the image ratios returned (where as placehold.it doesn't).
The original BBC News process (and my re-working of the script) follows roughly these steps...
- Create new instance of ImageEnhancer
- Change any
div
s within the page (which have a class ofdelayed-image-load
) into a transparent GIF using a Base64 encoded string.- We set the
width
&height
HTML attributes of the image to the required size - We know what size the image needs to be because each
div
has customdata-attr
set server-side to the size of the image - We then set a class of
image-replace
onto each newly created transparent image
- We set the
- We use a 250ms
setTimeout
to unblock the UI thread and which calls a functionresizeImages
which enhances theimage-replace
images so their source is now set to a URL whe
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"); |
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
function cloneObject(object) { | |
return extendObject({}, object); | |
} | |
function extendObject(base, object) { | |
var visited = [object]; | |
// http://en.wikipedia.org/wiki/Adjacency_list_model | |
var set = [{value: base}]; |
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
<!DOCTYPE html> | |
<html> | |
<head>...</head> | |
<body> | |
... | |
<script src="load.js"></script> | |
</body> | |
</html> |