Skip to content

Instantly share code, notes, and snippets.

@marciojrtorres
marciojrtorres / javascript_programacao_defensiva.js
Created August 5, 2013 20:41
Arrumando a casa com técnicas de programação defensiva
function dobro(n) {
if (typeof(n) != "number") return 0; // se n não é um número retorne 0
return n * 2;
}
document.write(dobro(2)); // ok, imprime 4
document.write(dobro("t")); // ok, "t" não é do tipo number, então imprime 0
@sibelius
sibelius / authenticatedMidldeware.tsx
Created February 15, 2019 12:16
Auth middleware to use with RR4
import * as React from 'react';
import { withRouter } from 'react-router-dom';
import { isLoggedIn } from '../../security/authentication';
import routeTo from '../utils/routeTo';
const authenticatedMiddleware = Component => {
class AuthenticatedMiddleware extends React.PureComponent {
componentDidMount() {
this.redirectIfNotAuthenticated();
@sibelius
sibelius / _usage.tsx
Created July 11, 2019 11:15
NavigationPersistence snippet to save navigation state
<AppRouter
ref={stackNavigatorRef => NavigatorService.setContainer(stackNavigatorRef)}
screenProps={{
t,
theme,
}}
{...getPersistenceFunctions(navigationPersistenceKey)}
/>
@lucianomlima
lucianomlima / adb_connect.sh
Created June 5, 2019 17:57
Connect to Android devices with ADB through wi-fi
function adb_connect {
# PORT used to connect. Default: 5555
PORT=${1:-5555}
# IP address from current device connected
IP_ADDRESS=`adb shell ip route | awk '{print $9}'`
echo "ADB connect to $IP_ADDRESS on port $PORT"
# Change connection from usb to tcpip using $PORT
@sibelius
sibelius / metro.config.js
Created May 7, 2019 14:38
Metro config that works well with monorepo
/**
* Metro configuration for React Native
* https://github.com/facebook/react-native
*
* @format
*/
const path = require('path');
const { FileStore } = require('metro-cache');
@melloc01
melloc01 / cloudSettings
Last active September 24, 2021 14:43
Visual Studio Code Settings Sync Gist
{"lastUpload":"2018-12-19T18:25:14.965Z","extensionVersion":"v3.2.4"}
@robertknight
robertknight / Build.md
Last active July 8, 2022 01:32
Minimal Webpack DllPlugin example

Compile with:

webpack --config vendor.webpack.config.js
webpack --config app.webpack.config.js

Use with the following index.html

@elijahmanor
elijahmanor / index-0-non-debounced.js
Last active December 20, 2022 21:14
React Debouncing Events
import React, { Component } from "react";
import { render } from "react-dom";
import "./index.css";
class Widget extends Component {
state = { text: "" };
handleChange = (e) => {
this.setState({ text: e.target.value });
};
render() {
@srikanthsunkari
srikanthsunkari / [Updated]webpack.config.js
Last active June 26, 2023 12:16
react native web with webpack configuration
// web/webpack.config.js
const path = require('path');
const webpack = require('webpack');
const appDirectory = path.resolve(__dirname, '../');
// This is needed for webpack to compile JavaScript.
// Many OSS React Native packages are not compiled to ES5 before being
// published. If you depend on uncompiled packages they may cause webpack build
@sibelius
sibelius / learning.md
Last active August 23, 2023 13:21
Learning Path React Native

Basics

  • Learn how to start a new react native project
  • Run it on ios simulator, on android emulator, on a real iPhone device and on a real Android device, with and without debugging enabled.
  • Learn how to upgrade a react native project
  • Learn how to add a package to the project
  • Learn how to add a package that has a native dependency (https://github.com/airbnb/react-native-maps, https://github.com/evollu/react-native-fcm) - DO NOT USE COCOAPODS
  • Learn how to use fetch to get data from your backend

Learn Navigation