Skip to content

Instantly share code, notes, and snippets.

View lucas1richard's full-sized avatar

Richard lucas1richard

View GitHub Profile
# first, fetch the latest refs for all branches. And be sure we have latest master, etc
git checkout master
git fetch
# If any changes from remote, catch our local version up
git rebase origin/master
# could also be done as
import React from 'React';
import PropTypes from 'prop-types';
import Touchable from 'components/Touchable';
import { View, Animated } from 'react-native';
import Text from 'components/Text';
import { wrapperStyle, titleStyle } from './styled';
class Button extends React.Component {
constructor(props) {
@lucas1richard
lucas1richard / react-navigation-best-practices.md
Last active April 24, 2018 16:08
For react-navigation@1.0.0-beta.19

React Navigation 1.0.0-beta.19 Best Practices

Performance

Never pass the navigation prop to children

The navigation prop is updated with every screen change, and since every screen is mounted, they will all be re-rendered unless you provide a shouldComponentUpdate lifecycle method.

Use the shouldComponentUpdate lifecycle method

Even if you don't think you'll need it, you should use it. Don't let your components updated unless the props you care about change. Combine this with the reselect library for double control.

@lucas1richard
lucas1richard / app;containers;Signup;containers;EmailPassword.jsx
Last active January 9, 2018 11:25
react-navigation stack headings
import React, { Component } from 'react';
import { connect } from 'react-redux';
import Text from 'components/Text';
import { View } from 'react-native';
import { Field, reduxForm } from 'redux-form/immutable';
import { NAV_SCREEN_OPTIONS } from 'constants';
import { FIRST_LAST_NAME } from '../../routes';
export class EmailPassword extends Component {
static navigationOptions = ({ screenProps }) => ({
/** When the function returned by debounce is executed multiple times before a specified time,
* the function passed into debounce is not executed. It is only executed if the time elapsed is greater than specified.
* @param {function} fn - the function to be debounced
* @param {number} time - the time in ms before executing fn
*/
const debounce = (fn, time) => {
let timer;
return function() {
clearTimeout(timer);
const Heap = require('heap');
/**
* Combine sticks, while adding the sums, to get the lowest combined sum possible
* @param {[number]} sticks - array of lengths
* @return {number}
*/
function combineSumSticks(sticks) {
const heap = new Heap();
var totalSum = 0;
/** Print all numbers in a range, except as specified in toPrint
* @param {[{num: number, print: string}]} toPrint - number/print specifications
* @param {string} multAll - message to print when all number is multiple of all numbers in toPrint
* @param {[number, number]} range - range over which to check for multiples
*/
function printRange(toPrint = [], multAll = 'Multiple of All', range = [1, 50]) {
for (let i = range[0]; i <= range[1]; i++) {
console.log(isMultAll(i) || isMultPrint(i));
}