Skip to content

Instantly share code, notes, and snippets.

View mmazzarolo's full-sized avatar
Busy — I'll be slow to respond!

Matteo Mazzarolo mmazzarolo

Busy — I'll be slow to respond!
View GitHub Profile
mmazzarolo / country-codes.ts
Created May 6, 2023 12:09
WIP - Type-safe TypeScript ISO 3166 country codes (names, two-letters codes, and three-letters codes)
// ==========================================
// ==========================================
* Countries data.
* This is the source that should be updated if you want to add/remove new country codes.
const countriesData = [
["Afghanistan", "AF", "AFG"],
mmazzarolo / nativewind+2.0.11.patch
Created February 4, 2023 13:55
Fix Nativewind 2.0.11 stale `colorScheme`
diff --git a/node_modules/nativewind/dist/style-sheet/color-scheme.js b/node_modules/nativewind/dist/style-sheet/color-scheme.js
index c08e40b..0505525 100644
--- a/node_modules/nativewind/dist/style-sheet/color-scheme.js
+++ b/node_modules/nativewind/dist/style-sheet/color-scheme.js
@@ -7,6 +7,16 @@ class ColorSchemeStore {
this.colorSchemeListeners = new Set();
this.colorScheme = react_native_1.Appearance.getColorScheme() || "light";
this.colorSchemeSystem = "system";
+ react_native_1.Appearance.addChangeListener(({ colorScheme }) => {
+ if (this.colorSchemeSystem === "system") {
mmazzarolo / localstorage-error-handling.ts
Created June 29, 2022 16:49
Handling localStorage errors (such as quota exceeded errors)
* 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 April 2, 2023 14:00
Using JavaScript to fill localStorage to its maximum capacity
* 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.
* 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 June 8, 2023 14:27
Find what JavaScript variables are leaking into the global `window` object at runtime (see:
* 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 November 26, 2021 17:31
Deno script to create a reminder from CLI (in Apple's Reminders app)
// 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 October 8, 2021 08:34
Is Chrome enable stylesheets asynchronously?
<p>Hello world</p>
mmazzarolo / bump-npm-dep.ts
Last active June 26, 2021 14:52
Bump the version number of an NPM dependency and commits the changes in a new branch
// 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 April 22, 2024 03:40
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.