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
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
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
mmazzarolo / MyTextInput.tsx
Last active January 20, 2023 10:21
A simple wrapper on the React Native TextInput that fixes its ugly default Android style
import * as React from "react";
import {
NativeSyntheticEvent,
StyleSheet,
TextInput,
TextInputFocusEventData,
TextInputProps
} from "react-native";
interface State {
@mmazzarolo
mmazzarolo / watch.js
Created October 19, 2019 21:24
Develop a browser extension with live-reloading using Create React App without ejecting
#!/usr/bin/env node
// A script for developing a browser extension with live-reloading
// using Create React App (no need to eject).
// Run it instead of the "start" script of your app for a nice
// development environment.
// P.S.: Install webpack-extension-reloader before running it.
// Force a "development" environment in watch mode
process.env.BABEL_ENV = "development";
@mmazzarolo
mmazzarolo / elevations.ts
Last active June 1, 2022 15:12
React-Native cross platform elevation definitions
/**
* React-Native cross-platform elevations.
* Based on https://ethercreative.github.io/react-native-shadow-generator/
*
* Usage:
* 1. Import "elevations" from this file
* import { elevations } from "config/elevations";
* 2. Use it. Assuming you need an elevation of 2 (based on the Android
* elevation standard), doing the following will cast the same shadow
* on both platforms:
@mmazzarolo
mmazzarolo / CustomModal.js
Created May 25, 2016 15:35
React-Native animated modal (supports dismiss on backdrop touch and Android back button )
import React, { Component, PropTypes } from 'react'
import { Dimensions, Modal, StyleSheet } from 'react-native'
import { View } from 'react-native-animatable'
const DEVICE_WIDTH = Dimensions.get('window').width
const DEVICE_HEIGHT = Dimensions.get('window').height
const DEFAULT_COLOR = '#001a33'
export default class CustomModal extends Component {
static propTypes = {
@mmazzarolo
mmazzarolo / authSagas.js
Created August 3, 2016 07:51
Saga example
import { call, put } from 'redux-saga/effects'
import * as parseService from '../services/parseService'
import { actionTypes as authActionTypes } from '../reducers/authReducer'
import { actionTypes as navigationActionTypes } from '../reducers/navigationReducer'
import * as routes from '../config/routes'
export function* autoLogin (action) {
const user = yield call(parseService.currentUser)
if (user) {
yield call(loginSuccess, user)
@mmazzarolo
mmazzarolo / useKeyboardPress.ts
Created December 30, 2018 22:09
A React hook for handling keypresses
import { useState, useEffect, useRef } from "react";
interface Parameters {
key: string;
ctrlKey?: boolean;
shiftKey?: boolean;
metaKey?: boolean;
onKeyDown?: (e: KeyboardEvent) => void;
onKeyUp?: (e: KeyboardEvent) => void;
}
@mmazzarolo
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 (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 October 8, 2021 08:34
Is Chrome enable stylesheets asynchronously?
<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>