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 / runonios.sh
Created March 8, 2017 09:05
Start React-Native app on IOS device by CLI
# 1. Make sure to globally install the npm ios-deploy module first:
npm i -g ios-deploy
# 2. Run the following command:
react-native run-ios --device
# Hint - You can also specify the device name if needed:
react-native run-ios --device "Paul's iPhone"
@mmazzarolo
mmazzarolo / FirebaseRecyclerAdapter.java
Last active February 22, 2018 03:55
RecyclerView adapter that handles a Firebase location listener
package com.example.matteo.firebase_recycleview;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.ViewGroup;
import com.firebase.client.ChildEventListener;
import com.firebase.client.DataSnapshot;
import com.firebase.client.FirebaseError;
@mmazzarolo
mmazzarolo / FloatingActionMenuBehavior.java
Last active April 10, 2018 04:47
Floating Action Menu like Inbox
import android.content.Context;
import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPropertyAnimatorListener;
import android.util.AttributeSet;
import android.view.View;
import com.github.clans.fab.FloatingActionMenu;
@mmazzarolo
mmazzarolo / mostaza-corso-async.md
Last active June 2, 2018 11:24
mostaza-corso-async

Async/Await, Promises, callbacks

Event driven architecture, event loop

Callback
  • Come funzionano (esempio)
const fs = require('fs');
export function* signup (action) {
const { email, password } = action
try {
const user = yield call(parseService.signup, email, password)
yield put({ type: authActionTypes.SIGNUP_SUCCESS, user })
yield call(loginSuccess, user)
} catch (err) {
const error = err.message || err
yield put({ type: authActionTypes.SIGNUP_FAILURE, error })
}
@mmazzarolo
mmazzarolo / dev.sh
Created June 28, 2018 16:36
React-Native development script
#!/bin/bash
# Starts the metro bundler and runs react-native in a single terminal (à la Expo).
# CTRL + C kills the metro bundler.
# Arguments:
# -p Development platform [ios (default), android].
# -s Starts scrcpy too. Android only. (https://github.com/Genymobile/scrcpy)
COLOR_RED='\033[0;31m'
COLOR_CYAN='\033[0;36m'
COLOR_PURPLE='\033[0;35m'
@mmazzarolo
mmazzarolo / App.tsx
Created September 28, 2018 09:25
src/screens/LoginScreen.tsx
import * as React from "react";
import { StyleSheet, Text, View } from "react-native";
class LoginScreen extends React.Component<{}> {
render() {
return (
<View style={styles.container}>
<Text>Welcome to the login screen!</Text>
</View>
);
@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