Skip to content

Instantly share code, notes, and snippets.

View plesiecki's full-sized avatar
💭
🔪

Paweł Lesiecki plesiecki

💭
🔪
  • Poland
View GitHub Profile
@rviscomi
rviscomi / web-app-manifest.js
Created May 12, 2021 03:59
WebPageTest custom metric: web app manifest
[web-app-manifest]
const response_bodies = $WPT_BODIES;
const manifestURLs = new Set(Array.from(document.querySelectorAll('link[rel=manifest]')).map(link => {
const base = new URL(location.href).origin;
const href = link.getAttribute('href');
return new URL(href, base).href;
}));
const manifests = response_bodies.filter(har => {
@andydavies
andydavies / cleanPage.js
Created February 9, 2021 15:23
DevTools snippet to remove the document contents and any event handlers on document and window objects
document.documentElement.innerHTML = '';
for (const obj of [document, window]) {
for (const event of Object.values(getEventListeners(obj))) {
for (const {type, listener, useCapture} of event) {
obj.removeEventListener(type, listener, useCapture)
}
}
}
@andydavies
andydavies / index.js
Created January 14, 2021 12:08
Example Cloudflare Worker that removes script preloads
/*
* For more detail see https://andydavies.me/blog/2020/09/22/exploring-site-speed-optimisations-with-webpagetest-and-cloudflare-workers/
* Started from Pat's example in https://www.slideshare.net/patrickmeenan/getting-the-most-out-of-webpagetest
*
* Change site to be site you want to experiment with
*/
const site = 'www.example.com';
async function handleRequest(request) {
@erykpiast
erykpiast / .zshrc
Last active March 4, 2020 11:43
Show aliases available for the last command
# I'm a lame, sorry
FIRST_RUN="true";
function show_aliases_available_for_the_last_command {
if [[ "$FIRST_RUN" == "true" ]]; then
FIRST_RUN="false";
return;
fi
local LAST_COMMAND=$(history | tail -1 | cut -d' ' -f2- | xargs);
local FOUND_ALIASES=$(alias | egrep "^[a-z]+='$LAST_COMMAND .*'$");
@jkrems
jkrems / index.md
Last active November 3, 2023 14:34
JavaScript: Classic Scripts vs. Modules vs. CommonJS

JavaScript File Format Differences

There's the pervarsive notion that all JS is created equal and that there's only minor and easily detectable differences between the various file formats used to author JavaScript. This is correct, from a certain point of view.

A certain point of view?

For many people writing JavaScript that gets passed into build tools,

Module Worker polyfill for Chrome 61+

Chrome 61+ supports dynamic import() within Classic Workers. We can use this to polyfill Module Workers to a reasonable degree of accuracy.

The only trick is that we need to queue up any messages received while we wait for the module tree to load in the Worker, since Module Workers load the entire dependency graph before flushing messages queued during Worker instantiation.

This polyfill comes in two versions:

module-workers-polyfill-inline.js is a single-file polyfill, but creates Workers with an Opaque Origin. If you're only loading dependencies from absolute URLs and not relying on storage like IndexedDB, this option is fine.

@gokulkrishh
gokulkrishh / useful-npx-commands.md
Last active November 24, 2023 04:25
List of useful npx (Node Package Runner) commands (https://git.io/useful-npx-commands)

NPX (NPM Package Runner) Commands

List of useful npx (NPM Package Runner) commands.

What is NPX?

Using NPX we can execute/run node binaries without the need to install it locally or globally.

Commands

@developit
developit / *babel-plugin-dynamic-import-polyfill.md
Created November 12, 2019 19:57
babel-plugin-dynamic-import-polyfill
@zkochan
zkochan / package.json
Last active July 20, 2019 19:22
How to force users of a repository to use pnpm for installation
{
"scripts": {
"preinstall": "node --eval \"!process.env.npm_config_user_agent.startsWith('pnpm/')&&(console.log('Use `pnpm install` to install dependencies in this repository')||true)&&process.exit(1)\""
}
}