Skip to content

Instantly share code, notes, and snippets.

View nicolas-amabile's full-sized avatar

Nicolas Amabile nicolas-amabile

View GitHub Profile
@nicolas-amabile
nicolas-amabile / WatchOutsideTap.js
Created August 18, 2020 21:34
A simple React Native component that detects outside tap events
import PropTypes from 'prop-types';
import React from 'react';
import styled from 'styled-components';
const Modal = styled.Modal.attrs(() => ({
transparent: true,
}))``;
const Wrapper = styled.TouchableOpacity`
flex: 1;
@nicolas-amabile
nicolas-amabile / switch-node-version
Created May 20, 2020 18:42
Tired of manually switching node versions when changing projects? Alias for the rescue
# Add those aliases to your favorite alias file
# nvm is required
alias get-required-node="node -pe \"try { require('./package.json').engines.node.replace(/[>=]/g, ''); } catch (e) { }\""
alias use-required-node='[[ `get-required-node` != undefined ]] && nvm use `get-required-node` || echo "No package.json here"'
@nicolas-amabile
nicolas-amabile / flattenArray.js
Last active April 3, 2019 16:48
Flatten an array of nested arrays
/*
* This function returns a flat array given an array of arbitrarily nested arrays
* e.g. [[1,2,[3]],4] -> [1,2,3,4].
*/
const flattenArray = arr => {
const result = []
arr.map(item => {
if (Array.isArray(item)) {
result.push(...flattenArray(item))
} else {