Skip to content

Instantly share code, notes, and snippets.

🍉
Hey there! I am using GitHub.

Matteo Mazzarolo mmazzarolo

🍉
Hey there! I am using GitHub.
Block or report user

Report or block mmazzarolo

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mmazzarolo
mmazzarolo / scale.ts
Last active Dec 23, 2019
React-Native metrics scaling
View scale.ts
import { PixelRatio, Dimensions } from "react-native";
const isTabletLike = () => {
const pixelDensity = PixelRatio.get();
const adjustedWidth = Dimensions.get("screen").width * pixelDensity;
const adjustedHeight = Dimensions.get("screen").height * pixelDensity;
return (
(pixelDensity < 2 && (adjustedWidth >= 1000 || adjustedHeight >= 1000)) ||
(pixelDensity === 2 && (adjustedWidth >= 1920 || adjustedHeight >= 1920))
);
@mmazzarolo
mmazzarolo / SkippableSplash.tsx
Created Dec 7, 2019
Skipping the splash screen in Ordinary Puzzles
View SkippableSplash.tsx
import React, { FC, useRef } from "react";
import { StyleSheet, Animated, TouchableWithoutFeedback } from "react-native";
import { Text } from "pg-common";
import { useAnimation, useOnMount, scale, delay } from "pg-utils";
import { animations, metrics, colors } from "pg-design";
import { credits } from "pg-config";
const asyncAnimationStart = (anim: Animated.CompositeAnimation) =>
new Promise(resolve => anim.start(resolve));
@mmazzarolo
mmazzarolo / colors.ts
Created Dec 1, 2019
Ordinary Puzzles grayscale palette
View colors.ts
import tinycolor from "tinycolor2";
import { useColorScheme } from "react-native-appearance";
const primaryColor = "#171520";
const palette = new Array(10).fill(primaryColor).map((color, index) =>
tinycolor(color)
.brighten(index * 10)
.toString()
);
@mmazzarolo
mmazzarolo / elevations.ts
Last active Nov 21, 2019
React-Native cross platform elevation definitions
View elevations.ts
/**
* 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 / useAnimation.ts
Last active Dec 3, 2019
A basic "useAnimation" hook for React-Native animations
View useAnimation.ts
import { useRef } from "react";
import { Animated, Easing } from "react-native";
export const useAnimation = function(initialValue: number = 0) {
const endValue = initialValue === 0 ? 1 : 0;
const animationValueRef = useRef<Animated.Value>(new Animated.Value(initialValue));
const setup = (config: Partial<Animated.TimingAnimationConfig> = {}) =>
Animated.timing(animationValueRef.current, {
toValue: endValue,
@mmazzarolo
mmazzarolo / useObservableAnimation.js
Created Nov 13, 2019
Animate React-Native components based on MobX observables changes
View useObservableAnimation.js
import { useEffect, useState } from "react";
import { Animated, Text, View } from "react-native";
import { reaction } from "mobx";
import { observer } from "mobx-react";
const defaultCheckObservedValue = observed => observed.visible;
const defaultCreateAnimationIn = animValue =>
Animated.timing(animValue, {
toValue: 1,
@mmazzarolo
mmazzarolo / store.ts
Last active Nov 10, 2019
Puzzle Game logic
View store.ts
import {
LayoutRectangle,
LayoutChangeEvent,
GestureResponderEvent
} from "react-native";
import { createContext, useContext } from "react";
import { observable, action, computed } from "mobx";
import { takeWhile, takeRightWhile, sortBy, intersectionBy } from "lodash";
const isOppositeDirectionOf = (dir1: string, dir2: string) => {
@mmazzarolo
mmazzarolo / watch.js
Created Oct 19, 2019
Develop a browser extension with live-reloading using Create React App without ejecting
View watch.js
#!/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";
View charles-command-line-options.md

Charles command-line options

Charles supports a few command line options out of the box, documented here.
Unfortunately they seem to operate only as parameters for new Charles sessions, so you won't be able to run commands on a running instance of Charles.

Start a specific Charles session

A Charles session contains all of your recorded information. It is represented by the Session window; by default a new session is automatically created when you start Charles.
Sessions can be saved from File → Save Session (+S).
Once saved, if you want you can start Charles from the saved session by running:

@mmazzarolo
mmazzarolo / useKeyboardPress.ts
Created Dec 30, 2018
A React hook for handling keypresses
View useKeyboardPress.ts
import { useState, useEffect, useRef } from "react";
interface Parameters {
key: string;
ctrlKey?: boolean;
shiftKey?: boolean;
metaKey?: boolean;
onKeyDown?: (e: KeyboardEvent) => void;
onKeyUp?: (e: KeyboardEvent) => void;
}
You can’t perform that action at this time.