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 / 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 / big-images-in-android-rn.js
Created December 1, 2018 13:59
Image decoding limit workaround for RN (Android)
export default class CroppedImage extends Component {
state = {
croppedImageSources: []
};
async componentDidMount() {
const crops = 4;
const croppedImageHeight = imHeight / crops;
const croppedImageSources = [];
for (let i = 0; i <= crops; i++) {
@mmazzarolo
mmazzarolo / MainActivity.java
Created December 13, 2018 20:49
Fresco/Picasso comparison on images with a dimension > 2048px
package com.example.matteomazzarolo.imagetest;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
@mmazzarolo
mmazzarolo / run-scrcpy.sh
Created December 18, 2018 10:57
Run scrcpy
if pgrep scrcpy; then
osascript -e 'tell application "System Events" to tell process "scrcpy"' \
-e 'set frontmost to true' \
-e 'if windows is not {} then perform action "AXRaise" of item 1 of windows' \
-e 'end tell'
else
/usr/local/bin/scrcpy
fi
@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 / charles-command-line-options.md
Last active June 7, 2024 09:55
Charles Proxy Automation

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 / 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 / store.ts
Last active November 10, 2019 14:38
Puzzle Game logic
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 / useObservableAnimation.js
Created November 13, 2019 13:08
Animate React-Native components based on MobX observables changes
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 / useAnimation.ts
Last active May 20, 2023 01:53
A basic "useAnimation" hook for React-Native animations
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,