This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Remember, debounced function will not run until it stops getting called for `wait` milliseconds | |
const debounce = (func, wait) => { | |
let timeout | |
return (...args) => { | |
clearTimeout(timeout) | |
timeout = setTimeout(() => func.apply(this, args), wait) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const webpack = require('webpack'); | |
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
const preferEntry = true; | |
module.exports = { | |
entry: ['babel-polyfill', './src/root.js'], | |
output: { | |
path: `${__dirname}/dist`, | |
publicPath: '/', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import { connect } from 'react-redux' | |
import { NavigationActions } from 'react-navigation' | |
export default function (ComposedComponent) { | |
class Authentication extends Component { | |
componentWillMount() { | |
if (!this.props.isAuthenticated) { | |
return this.props.navigation.dispatch(NavigationActions.reset({ | |
index: 0, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function myFunc(obj, callback) { // call back is an optional param | |
if (!callback) { // if callback omitted, we return a promise | |
const performWork = async () => obj // this simulates work being done before resolving | |
return new Promise(async (resolve, reject) => { // return an async promise wrapper | |
const value = await performWork() // do the work | |
resolve(value) // resolve the promise | |
}) | |
} | |
const cb = obj // if callback present, we return it | |
callback(cb) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Password Quality Checker | |
// Inspired by Amy - @thecrafty_coder on Twitter | |
import React from 'react' | |
import { View, Text } from 'react-native' | |
const testPassword = (p) => { | |
const hasSpecial = /[^a-zA-Z0-9]/.test(p) | |
const hasNumber = /[0-9]/.test(p) | |
const hasMixedCase = /[A-Z]/.test(p) && /[a-z]/.test(p) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs') | |
const EventEmitter = require('events') | |
const lazy = new EventEmitter() | |
const someTask = async () => true | |
const anotherTask = async () => true | |
const files = ['file1.txt', 'file2.txt', 'file3.txt'] | |
const readFile = (file) => { | |
try { | |
return new Promise(async (resolve, reject) => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Async function that checks input for no reason | |
// and then resolves or rejects the promise depending on the input | |
async function asyncWin(string) { | |
var input = string; | |
// Private helper method that displays pointless message | |
function _pointless() { | |
console.log('We just waited 1.337 seconds for no reason.') | |
}; | |
// Invoke helper method after 1.337 seconds and wait until it is done | |
var ok = await new Promise((resolve, reject) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
sampleFile = './words.txt'; | |
function getRandomWord(relativeFilePath) { | |
try { | |
// Read file and get words | |
var text = fs.readFileSync(relativeFilePath, 'utf8'); | |
var words = text.split(/\s/); |