Skip to content

Instantly share code, notes, and snippets.

View Nooshu's full-sized avatar

Matt Hobbs Nooshu

View GitHub Profile
@Nooshu
Nooshu / simplified-wpt-font-injection.js
Created February 23, 2020 03:32
Simplified script for injecting fonts into WebPageTest
(function(){
// this will trigger a font load
var customFont1 = new FontFace('custom font name', 'url([FONT_URL_HERE])', {
display: 'block', // display setting to test here
weight: '700' // font-weight
// other font properties here
});
// IMPORTANT: add the font to the document
document.fonts.add(customFont1);
@Nooshu
Nooshu / wpt-font-injection.js
Created February 20, 2020 00:25
Modify `font-display` settings via WPT script injection
(function(){
// create our custom link tag for the stylesheet
var url = "https://www.example.com/static/app.css"; // IMPORTANT: this is the CSS that contains your @font-face rules
var head = document.getElementsByTagName('head')[0];
var link = document.createElement('link');
link.type = "text/css";
link.rel = "stylesheet"
link.href = url;
// append the stylesheet to the head
@Nooshu
Nooshu / app.js
Last active May 28, 2021 00:01
Webmention code used in the "Implementing Webmentions on this blog" Nooshu blogpost
(function(){
// Check see if browser supports the intersection observer
if ('IntersectionObserver' in window) {
// assume browser supports ES6
var supportsES6 = true;
// check see if browser supports ES6 (https://gist.github.com/DaBs/89ccc2ffd1d435efdacff05248514f38)
var str = 'class ಠ_ಠ extends Array {constructor(j = "a", ...c) {const q = (({u: e}) => {return { [`s${c}`]: Symbol(j) };})({});super(j, q, ...c);}}' +
'new Promise((f) => {const a = function* (){return "\u{20BB7}".match(/./u)[0].length === 2 || true;};for (let vre of a()) {' +
'const [uw, as, he, re] = [new Set(), new WeakSet(), new Map(), new WeakMap()];break;}f(new Proxy({}, {get: (han, h) => h in han ? han[h] ' +
': "42".repeat(0o10)}));}).then(bi => new ಠ_ಠ(bi.rd));';
@Nooshu
Nooshu / cloudfront-test-command.sh
Last active September 7, 2019 14:03
Testing the OCSP stapling of Cloudfront and Fastly
# cloudfront test
# requires: https://github.com/rcoh/angle-grinder
while true; do bash -c 'echo hello | openssl s_client -connect www.digitalmarketplace.service.gov.uk:443 -tls1_2 -tlsextdebug -status -servername www.digitalmarketplace.service.gov.uk 2>&1 | grep -q "OCSP Response Status: successful" ; echo $?'; sleep 0.5; done | agrind '* | parse "*" as code | count by code'
# Is OCSP stapling used?
# code _count
# --------------------------
# 1 (no) 151
# 0 (yes) 49
@Nooshu
Nooshu / latency.markdown
Created December 9, 2018 22:02 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@Nooshu
Nooshu / results.json
Created November 29, 2018 14:05
GOV.UK Pay
{
"userAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/69.0.3497.81 Safari/537.36",
"environment": {
"networkUserAgent": "Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/69.0.3497.81 Mobile Safari/537.36 TreoWorker/3.2.1",
"hostUserAgent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/69.0.3497.81 Safari/537.36",
"benchmarkIndex": 942
},
"lighthouseVersion": "3.2.1",
"fetchTime": "2018-11-29T13:34:25.809Z",
"requestedUrl": "https://www.payments.service.gov.uk/",
@Nooshu
Nooshu / gist:955b5b00adefc49e378fa251b0a67940
Created October 21, 2018 21:10
Speech page FF 62.0.3
This file has been truncated, but you can view the full file.
{
"log": {
"version": "1.1",
"creator": {
"name": "Firefox",
"version": "62.0.3"
},
"browser": {
"name": "Firefox",
"version": "62.0.3"
{"log":{"version":"1.1","creator":{"name":"Firefox","version":"62.0"},"browser":{"name":"Firefox","version":"62.0"},"pages":[{"id":"page_1","pageTimings":{"onContentLoad":5953,"onLoad":32307,"_firstVisualChange":5067,"_lastVisualChange":17500,"_visualComplete85":5200,"_visualComplete95":5200,"_visualComplete99":5200,"_domInteractiveTime":5979,"_domContentLoadedTime":5982},"startedDateTime":"2018-10-11T12:50:33.426+00:00","title":"Spring Statement 2018: Philip Hammond's speech - GOV.UK","_meta":{"connectivity":"3gslow"},"_visualMetrics":{"SpeedIndex":5193,"PerceptualSpeedIndex":5177,"FirstVisualChange":5067,"LastVisualChange":17500,"VisualReadiness":12433,"VisualComplete85":5200,"VisualComplete95":5200,"VisualComplete99":5200,"VisualProgress":{"0":0,"5067":76,"5100":76,"5200":99,"5234":99,"5267":99,"5300":99,"5334":99,"5367":99,"5434":99,"5467":99,"5500":99,"5534":99,"5567":99,"5600":99,"5634":99,"5667":99,"5700":99,"5734":99,"5767":99,"5800":99,"5834":99,"5867":99,"5900":99,"5934":99,"5967":99,"6000":99,"6034
{
"har1": {
"url": "https://govuk-wpt-har-hosting.netlify.com/wpt-har-hosting/past-pm-before-nexus5.har",
"label": "HTTP/1.1"
},
"har2": {
"url": "https://govuk-wpt-har-hosting.netlify.com/wpt-har-hosting/past-pm-after-nexus5.har",
"label": "HTTP/2"
}
}
@Nooshu
Nooshu / example.json
Created October 18, 2018 21:17
GOV.UK before and after HTTP/2
{
"har1": {
"url": "https://sitespeed-performance-before-firefox-native.netlify.com/pages/www.gov.uk/government/history/past-prime-ministers/data/browsertime.har",
"label": "HTTP/1.1"
},
"har2": {
"url": "https://sitespeed-performance-after-firefox-native.netlify.com/pages/www.gov.uk/government/history/past-prime-ministers/data/browsertime.har",
"label": "HTTP/2"
},
"comment": "Notice the large queue of images waiting to be downloaded. Compare that to HTTP/2 waterfall where they all have the same wait time."