Skip to content

Instantly share code, notes, and snippets.

Avatar
🦩
Hey there!

Matteo Mazzarolo mmazzarolo

🦩
Hey there!
View GitHub Profile
@mmazzarolo
mmazzarolo / localstorage-error-handling.ts
Created Jun 29, 2022
Handling localStorage errors (such as quota exceeded errors)
View localstorage-error-handling.ts
/**
* Determines whether an error is a QuotaExceededError.
*
* Browsers love throwing slightly different variations of QuotaExceededError
* (this is especially true for old browsers/versions), so we need to check
* different fields and values to ensure we cover every edge-case.
*
* @param err - The error to check
* @return Is the error a QuotaExceededError?
*/
@mmazzarolo
mmazzarolo / fill-localstorage.ts
Last active Jun 30, 2022
Using JavaScript to fill localStorage to its maximum capacity
View fill-localstorage.ts
/**
* Fill localStorage to its maximum capacity.
*
* First, we find the highest order bit (the bit with the highest place value)
* that fits in localStorage by storing localStorage an increasingly big
* string of length 2, 4, 8, 16, etc. until it won't fill localStorage anymore.
*
* By working in iterations, starting with very long strings, and storing data
* in different items, we can keep a low memory profile and reduce the number of
* writes — making this process pretty fast.
View globals-debugger.js
/**
* GlobalsDebugger
*
* Inspect the stack when a global variable is being set on the window object.
* Given a global variable name, it proxies the variable name in the window
* object adding some custom code that will be invoked whenever the variable
* is set. The custom code will log the current stack trace and halt the code
* execution to allow inspecting the stack and context in your browser DevTools.
* You can use the "globalsToInspect" query-parameter to set a comma-separated
* list of names of the variables you want to inspect.
@mmazzarolo
mmazzarolo / runtime-globals-checker.js
Last active Sep 28, 2022
Find what JavaScript variables are leaking into the global `window` object at runtime (see: https://mmazzarolo.com/blog/2022-02-14-find-what-javascript-variables-are-leaking-into-the-global-scope/)
View runtime-globals-checker.js
/**
* RuntimeGlobalsChecker
*
* You can use this utility to quickly check what variables have been added (or
* leaked) to the global window object at runtime (by JavaScript code).
* By running this code, the globals checker itself is attached as a singleton
* to the window object as "__runtimeGlobalsChecker__".
* You can check the runtime globals programmatically at any time by invoking
* "window.__runtimeGlobalsChecker__.getRuntimeGlobals()".
*
@mmazzarolo
mmazzarolo / quick-reminder.ts
Last active Nov 26, 2021
Deno script to create a reminder from CLI (in Apple's Reminders app)
View quick-reminder.ts
// Deno CLI script to add reminders to Apple's Reminders app parsing the
// due date with natural language.
// Requires reminders-cli (https://github.com/keith/reminders-cli) to be
// installed in order to run. Uses reminders-cli instead of Applescript/JXA
// because reminders-cli is much faster.
// Uses chrono-node (https://github.com/wanasit/chrono) to parse the date (which
// in my opinion works better than reminders-cli natural lanaguage parser).
//
// Example usage:
// ```
@mmazzarolo
mmazzarolo / test.html
Last active Oct 8, 2021
Is Chrome enable stylesheets asynchronously?
View test.html
<html>
<body>
<link
rel="stylesheet"
href="https://unpkg.com/purecss@2.0.6/build/pure-min.css"
integrity="sha384-Uu6IeWbM+gzNVXJcM9XV3SohHtmWE+3VGi496jvgX1jyvDTXfdK+rfZc8C1Aehk5"
crossorigin="anonymous"
id="purecss"
/>
<p>Hello world</p>
@mmazzarolo
mmazzarolo / bump-npm-dep.ts
Last active Jun 26, 2021
Bump the version number of an NPM dependency and commits the changes in a new branch
View bump-npm-dep.ts
// Just a Deno script that bumps an NPM dependency of the project
// in the current directory.
// Might be helpful if you need to automate the bumping of a
// dependency across multiple repos.
// It:
// - Makes sure you start from a clean state
// - Auto-detects if using yarn or npm
// - Creates, commits, and pushes the changes in a separate branch
import * as Colors from "https://deno.land/std/fmt/colors.ts";
import yargs from "https://deno.land/x/yargs/deno.ts";
@mmazzarolo
mmazzarolo / service-workers.md
Last active Sep 1, 2022
Service Workers Tips
View service-workers.md

Service Workers Tips

Reloading a service worker

Reloading a page won't update/remove the previous version of its service worker. To make sure you're using the latest version of your service worker, make sure to check the "Update on reload" toggle in the "Application" ⭢ "Service Workers" section of the Chrome DevTools.

Simulate a network condition

To simulate a network condition (e.g.: offline, 3g, etc...) in a service worker on Chrome, uncheck the "Update on reload" toggle.

@mmazzarolo
mmazzarolo / ffmpeg_resize.sh
Created Sep 6, 2020
Resize videos keeping the aspect ratio (shows black bar padding where needed)
View ffmpeg_resize.sh
#!/bin/bash
input="input.mp4"
output="output.mp4"
color="black"
while getopts ":i:o:w:h:c:" opt; do
case $opt in
i) input="$OPTARG"
;;
@mmazzarolo
mmazzarolo / disable-people-also-search-for-google.md
Last active Aug 6, 2022
Disabling "People also search for" box in Google search results
View disable-people-also-search-for-google.md