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 / ContainerExample1.js
Created August 3, 2016 07:34
Authentication duck example
// ACTIONCREATORS USAGE EXAMPLE 1
// When the action needed are all in a single duck (in this case authReducer)
import React, { Component, PropTypes } from 'react'
import { connect } from 'react-redux'
import { bindActionCreators } from 'redux'
import { actionCreators } from '../reducers/authReducer'
const mapStateToProps = (state, ownProps) => ({
// blablabla
})
@mmazzarolo
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 "https://deno.land/std/fmt/colors.ts";
import yargs from "https://deno.land/x/yargs/deno.ts";
@mmazzarolo
mmazzarolo / MyTextInput.js
Last active June 15, 2021 11:57
A simple wrapper on the React Native TextInput that fixes its ugly default Android style
import * as React from "react";
import { StyleSheet, TextInput } from "react-native";
const BLUE = "#428AF8";
const LIGHT_GRAY = "#D3D3D3";
class MyTextInput extends React.Component {
state = {
isFocused: false
};
@mmazzarolo
mmazzarolo / RadioButton.js
Last active May 26, 2021 15:29
Simple animated stateless React-Native radio button
import React, { PropTypes } from 'react'
import { StyleSheet, TouchableOpacity } from 'react-native'
import { View } from 'react-native-animatable'
const DEFAULT_SIZE_MULTIPLIER = 0.7
const DEFAULT_OUTER_BORDER_WIDTH_MULTIPLIER = 0.2
const RadioButton = ({ size, innerColor, outerColor, isSelected, onPress, ...props }) => {
const outerStyle = {
borderColor: outerColor,
@mmazzarolo
mmazzarolo / ffmpeg_resize.sh
Created September 6, 2020 13:05
Resize videos keeping the aspect ratio (shows black bar padding where needed)
#!/bin/bash
input="input.mp4"
output="output.mp4"
color="black"
while getopts ":i:o:w:h:c:" opt; do
case $opt in
i) input="$OPTARG"
;;
@mmazzarolo
mmazzarolo / mobxLogger.js
Created May 30, 2016 13:10
While waiting for React-Native MobX devtools...
import mobx from 'mobx'
const DEFAULT_STYLE = 'color: #006d92; font-weight:bold;'
// Just call this function after MobX initialization
// As argument you can pass an object with:
// - collapsed: true -> shows the log collapsed
// - style -> the style applied to the action description
export const startLogging = ({ collapsed, style } = {}) => {
mobx.spy(event => {
@mmazzarolo
mmazzarolo / CircleAnimation.js
Created January 28, 2017 18:19
Super simple circle animation overlay for React-Native
/* @flow */
import React, { Component } from 'react'
import { View } from 'react-native-animatable'
import metrics from 'src/config/metrics'
type Props = {
isVisible: boolean,
backgroundColor: string,
animationTiming?: boolean
}
@mmazzarolo
mmazzarolo / NavBar.android.js
Last active June 7, 2020 14:46
React-Native toolbar on Navigation-Experimental (for both Android and iOS)
import React, { Component } from 'react'
import { StyleSheet } from 'react-native'
import Icon from 'react-native-vector-icons/Ionicons'
export default class NavBar extends Component {
static propTypes = {
title: React.PropTypes.string,
onLeftPress: React.PropTypes.func,
showDrawer: React.PropTypes.bool
}
@mmazzarolo
mmazzarolo / Default (Linux).sublime-keymap
Last active January 23, 2020 23:32
My Sublime3 settings
[
{ "keys": ["f12"], "command": "reindent", "args": {"single_line": false} },
{ "keys": ["ctrl+space"], "command": "auto_complete" },
{ "keys": ["ctrl+space"], "command": "replace_completion_with_auto_complete", "context":
[
{ "key": "last_command", "operator": "equal", "operand": "insert_best_completion" },
{ "key": "auto_complete_visible", "operator": "equal", "operand": false },
{ "key": "setting.tab_completion", "operator": "equal", "operand": true }
]
},
@mmazzarolo
mmazzarolo / scale.ts
Last active December 23, 2019 14:51
React-Native metrics scaling
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))
);