Skip to content

Instantly share code, notes, and snippets.

Hey there!

Matteo Mazzarolo mmazzarolo

Hey there!
View GitHub Profile
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 / 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 / runtime-globals-checker.js
Last active Sep 28, 2022
Find what JavaScript variables are leaking into the global `window` object at runtime (see:
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 / 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 ( to be
// installed in order to run. Uses reminders-cli instead of Applescript/JXA
// because reminders-cli is much faster.
// Uses chrono-node ( to parse the date (which
// in my opinion works better than reminders-cli natural lanaguage parser).
// Example usage:
// ```
mmazzarolo / test.html
Last active Oct 8, 2021
Is Chrome enable stylesheets asynchronously?
View test.html
<p>Hello world</p>
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 "";
import yargs from "";
mmazzarolo /
Last active Sep 1, 2022
Service Workers Tips

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 /
Created Sep 6, 2020
Resize videos keeping the aspect ratio (shows black bar padding where needed)
while getopts ":i:o:w:h:c:" opt; do
case $opt in
i) input="$OPTARG"
mmazzarolo /
Last active Aug 6, 2022
Disabling "People also search for" box in Google search results