Skip to content

Instantly share code, notes, and snippets.

View mmocny's full-sized avatar

Michal Mocny mmocny

View GitHub Profile
@mmocny
mmocny / shadowQuerySelectorAll.js
Created October 6, 2022 16:43
shadowQuerySelectorAll. Like querySelectorAll, but which works across shadowRoots
// Inspiration: https://www.abeautifulsite.net/posts/querying-through-shadow-roots/
/*
* Acts like querySelectorAll, except you can pass a list of selectors...
* Each selector is evaluated within the shadowRoot of the previous NodeList
*/
function* shadowQuerySelectorsAll(selectors, rootNode = document, depth = 0) {
const nodes = rootNode?.querySelectorAll(selectors[depth]);
if (depth >= selectors.length - 1) {
yield* nodes;
import firstOnly from './Promise.firstOnly.polyfill.js';
// Always unblocks next-render... but can leave main thread idle time while waiting for next frame.
function doubleRaf(cb) {
requestAnimationFrame(() => {
requestAnimationFrame(cb);
});
}
// Always unblocks next-render... but gets scheduled at the back of the main thread task queue
/* Usage:
await Promise.firstOnly([
(signal) => {
return new Promise((resolve, reject) => {
// ...do work and resolve();
signal.addEventListener("abort", () => {
// ...cancel and reject();
});
});
},
@mmocny
mmocny / po2it.md
Last active February 4, 2021 16:10
Performance Observer to Async Iterator

Performance Observer to Async Iterator

Background: Iterators, Performance Observer, and Async Iterators

function* range() {
   yield 1;
   yield 2;
   yield 3;
}
@mmocny
mmocny / CheckMobileViewport.js
Last active February 2, 2021 17:08
Re-Implement Chrome conventions for mobile viewport test in JS.
/*
* Re-implement based on conventions from:
* https://source.chromium.org/chromium/chromium/src/+/master:cc/trees/layer_tree_host_impl.cc;l=160-176
*
* With help from github.com/dontcallmedom and his library:
* https://github.com/dontcallmedom/metaviewport-parser (MIT https://github.com/dontcallmedom/metaviewport-parser/blob/master/LICENSE)
*/
function HasFixedPageScale() {
// Simpler variant:
@mmocny
mmocny / CumulativeLayoutShiftBookmarklet.js
Last active January 20, 2021 20:23 — forked from anniesullie/CumulativeLayoutShiftBookmarklet.js
Bookmarklet for showing Cumulative Layout Shift
/**
* A bookmarklet for viewing shifted elements while debugging
* Cumulative Layout Shift (web.dev/cls). Works in Chrome 84+
* Shows the previous position of shifted elements in yellow,
* and the new position in red.
*
* To install:
* 1. Copy the code starting from the line beginning `javascript:`
* 2. Add a new bookmark in Chrome, and paste the code in as the URL.
**/
Verifying that +mmocny is my blockchain ID. https://onename.com/mmocny
var cordova = require('cordova-lib');
var INPUT_WEBAPP = 'path/to/my/project/dist/app';
var CDV_CONFIG = 'path/to/my/project/src/config.xml';
var OUTPUT_CDVROOT = 'path/to/my/project/dist/cordova';
var platforms = [
require(‘cordova-android’),
require(‘cordova-ios’),
// ...
function foo() {
  return "bar";
}
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "ant.properties", and override values to adapt the script to your
# project structure.
# Indicates whether an apk should be generated for each density.