Skip to content

Instantly share code, notes, and snippets.

@moeriki
moeriki / global-pollution.html
Created July 31, 2024 14:33
Global Pollution
<script>
const PROPERTIES = [
// { names: ['$', 'jQuery'], getVersion: (value) => value().jquery },
{ names: ['_'], getVersion: (value) => value.version },
];
for (let { names, getVersion } of PROPERTIES) {
for (let name of names) {
let scopedValue;
Reflect.defineProperty(globalThis, name, {
configurable: true,
---
import _ from 'https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm';
const unsortedList = ['a', 'c', 'b'];
const sortedList = _.sortBy(unsoredList);
---
Unsorted: {unsortedList}
Sorted: {sortedList}
<script type="module">
/* eslint-env browser */
const globalObjects = {
// JS Prototypes
Array,
Boolean,
Date,
Error,
Function,
@moeriki
moeriki / sync.sh
Created December 7, 2023 17:05
Sync git remotes
#!/bin/bash
# Check if the correct number of arguments is provided
if [ "$#" -lt 3 ]; then
echo "Usage: $0 <source_remote> <destination_remote> <pattern1:ref1> [<pattern2:ref2> ...]"
echo ""
echo "Examples:"
echo " $0 origin github development:master uat 'releases/*'"
echo ""
echo "Notes:"
export function useInnerRef<T>(forwardedRef: ForwardedRef<T>) {
const innerRef = useRef<T | null>(null);
const setInnerRef: RefCallback<T> = (element: T | null) => {
if (typeof forwardedRef === 'function') {
forwardedRef(element);
} else if (forwardedRef) {
forwardedRef.current = element;
}
innerRef.current = element;
};
<script>
!function(){var e,t,n,i,r={passive:!0,capture:!0},a=new Date,o=function(){i=[],t=-1,e=null,f(addEventListener)},c=function(i,r){e||(e=r,t=i,n=new Date,f(removeEventListener),u())},u=function(){if(t>=0&&t<n-a){var r={entryType:"first-input",name:e.type,target:e.target,cancelable:e.cancelable,startTime:e.timeStamp,processingStart:e.timeStamp+t};i.forEach((function(e){e(r)})),i=[]}},s=function(e){if(e.cancelable){var t=(e.timeStamp>1e12?new Date:performance.now())-e.timeStamp;"pointerdown"==e.type?function(e,t){var n=function(){c(e,t),a()},i=function(){a()},a=function(){removeEventListener("pointerup",n,r),removeEventListener("pointercancel",i,r)};addEventListener("pointerup",n,r),addEventListener("pointercancel",i,r)}(t,e):c(t,e)}},f=function(e){["mousedown","keydown","touchstart","pointerdown"].forEach((function(t){return e(t,s,r)}))},p="hidden"===document.visibilityState?0:1/0;addEventListener("visibilitychange",(function e(t){"hidden"===document.visibilityState&&(p=t.timeStamp,removeEventListen
var webVitals=function(e){"use strict";var t,n=function(){return window.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||function(){var e=performance.timing,t=performance.navigation.type,n={entryType:"navigation",startTime:0,type:2==t?"back_forward":1===t?"reload":"navigate"};for(var r in e)"navigationStart"!==r&&"toJSON"!==r&&(n[r]=Math.max(e[r]-e.navigationStart,0));return n}())},r=function(e){if("loading"===document.readyState)return"loading";var t=n();if(t){if(e<t.domInteractive)return"loading";if(0===t.domContentLoadedEventStart||e<t.domContentLoadedEventStart)return"dom-interactive";if(0===t.domComplete||e<t.domComplete)return"dom-content-loaded"}return"complete"},i=function(e){var t=e.nodeName;return 1===e.nodeType?t.toLowerCase():t.toUpperCase().replace(/^#/,"")},a=function(e,t){var n="";try{for(;e&&9!==e.nodeType;){var r=e,a=r.id?"#"+r.id:i(r)+(r.className&&r.className.trim().length?"."+r.className.trim().replace(/\s+/g,"."):"");if(n.length+a.length>(t||100)-
var t,e=function(){return window.performance&&(performance.getEntriesByType&&performance.getEntriesByType("navigation")[0]||function(){var t=performance.timing,e=performance.navigation.type,n={entryType:"navigation",startTime:0,type:2==e?"back_forward":1===e?"reload":"navigate"};for(var r in t)"navigationStart"!==r&&"toJSON"!==r&&(n[r]=Math.max(t[r]-t.navigationStart,0));return n}())},n=function(t){if("loading"===document.readyState)return"loading";var n=e();if(n){if(t<n.domInteractive)return"loading";if(0===n.domContentLoadedEventStart||t<n.domContentLoadedEventStart)return"dom-interactive";if(0===n.domComplete||t<n.domComplete)return"dom-content-loaded"}return"complete"},r=function(t){var e=t.nodeName;return 1===t.nodeType?e.toLowerCase():e.toUpperCase().replace(/^#/,"")},i=function(t,e){var n="";try{for(;t&&9!==t.nodeType;){var i=t,a=i.id?"#"+i.id:r(i)+(i.className&&i.className.trim().length?"."+i.className.trim().replace(/\s+/g,"."):"");if(n.length+a.length>(e||100)-1)return n||a;if(n=n?a+">"+n:a,i.id)bre
console.log('WV init');
var script = document.createElement('script');
script.src = 'https://unpkg.com/web-vitals@3/dist/web-vitals.iife.js';
script.onload = function () {
console.log('WV load');
// webVitals.onCLS(console.log);
webVitals.onFID(console.log);
// webVitals.onLCP(console.log);
/* Find images with missing alt attributes */
img:not([alt]) {
outline: 2px dotted red;
}
/* Potential tabindex problems */
[tabindex]:not([tabindex="0"], [tabindex="-1"]) {
outline: 2px dotted red;
}