Coggle requires JavaScript to display documents.
const a = [2,9,9] a.indexOf(2); //- a.indexOf(7); // -1
var num1 = [1, 2, 3], num2 = [4, 5, 6], num3 = [7, 8, 9]; var nums = num1.concat(num2, num3); console.log(nums); // results in [1, 2, 3, 4, 5, 6, 7, 8, 9]
var a = ['zero', 'one', 'two', 'three']; var sliced = a.slice(1, 3); console.log(a); // ['zero', 'one', 'two', 'three'] console.log(sliced); // ['one', 'two']
var words = ["spray", "limit", "elite", "exuberant", "destruction", "present"]; var longWords = words.filter(word => word.length > 6); // Filtered array longWords is ["exuberant", "destruction", "present"]
colors.forEach((color) => console.log(color))
numbers.map((number,index) => number*2)
users.find((user) => user.name === "dror")
array.every/some((val) => val > 2) //[1,2,3,4] => false/true //[3,4,5] => true/true
numbers.reduce((sum,number) => number + sum, 0)
[...array1, ...array2] function doSomething(...numbers) // can add multiple numbers as arrguments
for (let color of colors) { //dosomthing }
var a = [1, 2, 3]; a.unshift(4, 5); console.log(a); // [4, 5, 1, 2, 3]
randomArray(length){ return Array.from({length: length}, () => ~~(Math.random() * 400)); }
myFish.splice(2, 1); // remove 1 item at 2-index position
var a = ['one', 'two', 'three']; a.reverse(); console.log(a); // ['three', 'two', 'one']
var a = ['Wind', 'Rain', 'Fire']; a.join(); // 'Wind,Rain,Fire' a.join('-'); // 'Wind-Rain-Fire'
var array = [ { 'dir': 'left', 'code': 97 }, { 'dir': 'right', 'code': 100 } ]; _.keyBy(array, 'dir'); // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
var object = { 'a': [{ 'b': { 'c': 3 } }] }; _.get(object, 'a[0].b.c'); // => 3
_.orderBy(users, ['user', 'age'], ['asc', 'desc']); // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
cconst obj={a: 1, b: '2', c: 3}; _.pickBy(object, _.isNumber); // => {a: 1, c: 3}
_.keys({a:"hello",b:"world"}) //['a','b'] Returns the array of property names.
_.forEach({ 'a': 1, 'b': 2 }, function(value, key) { console.log(key); }); // => Logs 'a' then 'b' (iteration order is not guaranteed).
const obj = { 1234: {name: 'dror', age: 31}, 5678 : {name: 'joe', age: 32} } const arr = _.map(dobj, (value,index) => { return {...value, id: index}; }) // => [{id:1234, name:'dror',age:31},{id:5678,name:'joe',age:32}]
npm install --save lodash import _ from 'lodash';
_.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); // => [{ 'x': 1 }, { 'x': 2 }]
postIdToDelete = 42; return _.omit(state,postIdToDelete)
_.truncate('hi-diddly-ho there, neighborino'); // => 'hi-diddly-ho there, neighbo...'
"hello".split("") //["h","e","l","l","o"]
/d(b+)d/.exec('cdbbdbsbz') => ["abbd","bb"]
/^\d$/.test('5') => true
str.startsWith('hello') //true
str1 = "hello world" str2 = str1.slice(1,4) // 'ell'
'Blue Whale'.indexOf('Blue');
' foo '.trim() // 'foo'
string.charAt(0).toUpperCase()
'abc'.repeat(2); // 'abcabc'
'Blue Whale'.indexOf('Blue'); // returns 0 'Blue Whale'.indexOf('Blute'); // returns -1
"054-5434 916".replace(/[\D]/g,"") //0545434916
Math.random() * 256 //0 - 255`
Math.floor(24.5) //24
Math.abs(-5) //5
Math.min(3,1,4) //4
Math.ceil(.95); // 1
Number.isSafeInteger(testValue)
const newPerson = {...person, y:'snow'}; //create a new object
var prop = 'foo'; var o = { [prop]: 'hey', ['b' + 'ar']: 'there' };
const obj = {a: "hi", b:"world"} Object.keys(obj) //["a","b"]
const {name, age} = person const [ firstnumber] = [1,2,3,4,5]
function Car(options) { this.title = options.title; } Car.prototype.drive = function() { return 'vroom' } const car1 = new Car({ title: 'Focus'})
class Car { constructor(options) { this.title = options.title } drive() { return 'vroom' } } const car1 = new Car();
class Toyota extends Car { constructor(options){ super(options); this.color = options.color; } hunk() { return 'beep'; } }
static hunk(){return 'hunk hunk'} console.log(Car.hunk()) //hunk hunk
fetch(url) .then(response => response.json()) .then(data => console.log(data))
async function getMoviesFromApi() { try { let response = await fetch('https://facebook.github.io/react-native/movies.json'); let responseJdon = await response.json(); return responseJson.movies; } catch(error) { console.log(error); } }
promise = new Promise((resolve, reject) => { setTimeout(() => { resolve(); } , 3000); }); promis .then(() => console.log('finished') .catch(() => console.log('oops...'))
doLongRunningThing = async() => { let result = await myRequest(); console.log(result) }
`/users/${currentUser}/employees`
const COLORS = { red: red, blue: blue } is the same as const COLORS = {red,blue}
function* TeamIterator(team) { yield team.lead; yield team.manager; yield team.engineer; } const names =[]; for (let name of TeamIterator(teamA)) { names.push(name); } // => [jhon,james,Sara]
[Symbol.iterator] : function* () { yield this.lead; yield this.manager; }
*[Symbol.iterator](){ yield this.content for (let child of this.children) { yield* child } }
let data = new Date();
import React, {Component, PropTypes} from 'react'; class Video extends React.Component { static defaultProps = { title: "", } static propTypes = { titile: PropTypes.string } state = { loopsRemaining: this.props.maxLoops, } }
<Button onPress={onPressLearnMore} title="Learn More" color="#841584" accessibilityLabel="Learn more about this purple button" />
alignSelf: 'auto', 'flex-start', 'flex-end', 'center', 'stretch', 'baseline')
flexDirection: 'row', 'column'
justifyContent: 'flex-start', center, flex-end, space-around, and space-between.
textAlign?: enum('auto', 'left', 'right', 'center', 'justify')
alignItems: 'flex-start', 'flex-end','center','stretch'
flexWrap: 'nowrap', 'wrap', 'wrap-reverse'
alignContent: 'flex-start','flex-end','center','space-between','space-around','stretch'
react-native run-ios --simulator="iPhone 6s" emulator -avd Pixel_XL &
adb reverse tcp:3000 tcp:3000 && adb reverse tcp:3001 tcp:3001 adb reverse tcp:3000 tcp:3000 && adb reverse tcp:8081 tcp:8081 adb shell input keyevent 82
emulator -avd Pixel_XL &
git remote -v git remote rm origin git remote add origin <url> git push -u origin master
git stash git stash pop git stash drop
git pull --rebase
git reset --hard head
git pull --rebase --autostash
git checkout -b [name_of_your_new_branch] git checkout [name_of_your_new_branch] git push origin [name_of_your_new_branch]
git reset --soft HEAD~3 && git commit
git checkout master git pull origin master git merge test git push origin master
$ git checkout experiment $ git rebase master
rm -rf node_modules && rm -f package-lock.json && npm i
npm view <module name> dist-tags
npm start -- --reset-cache
npm ls react-native-extended-cli
rm -rf $TMPDIR/*metro*
npm ls | grep react-native-ui-lib@
npm config set registry http://npm.dev.wixpress.com/ npm config set registry https://registry.npmjs.org/
rnx test --e2e --skip-lint
rnx build release rnx test release
export BABEL_ENV=specs
brew cask search macdown brew cask install macdown
npm install --save firebase
firebase.auth().signInWithEmailAndPassword(email,password) .then(user => console.log(user));
firebase.auth().createUserWithEmailAndPassword(email,password) .then(user => console.log(user));
import firebase from 'firebase'; firebase.database().ref(`/users/${currentUser.uid}/employees`) .push({name,phone,shift});
const {currentUser.uid} = firebase.auth();
firebase.database().ref(`/users/${currentUser.uid}/employees`) .on('value', snapshot => { dispatch({type: EMPLOYESS_FETCH_SUCCESS, payload: sanpeshot.val()}) })
firebase.database().ref('users/' + userId).set
import { connect } from 'react-redux' export default connect(null,{<emailChange>})(<LoginForm>);
import {EMAIL_CHANGED} from '../actions/types'; const INITIAL_STATE = { email: ''}; export default (state=INITIAL_STATE, action) => { switch(action.type){ case EMAIL_CHANGED: return {...state, email: action.payload}; default: return state; } };
import {combineReducers} from 'redux'; import AuthReducer from './AuthReducer'; export default combineReducers({ auth: AuthReducer });
const mapStateToProps = state => { return{ email: state.auth.email }; }; export default connect(mapStateToProps,{emailChanged})(LoginForm);
npm install --save redux-thunk
import reduxThuck from 'reduc-thunk'; import {createStore,applyMiddleware} from 'redux'; const store = createStore(reducers,{},applyMiddleware(ReduxThunk)); return ( <Provider store={store}> ...
export const facebookLogin = () => async dispatch => { let token = await AsyncStorage.getItem('fb_token'); if (token) { //Dispatch an action saying FB is done dispath({type: FACEBOOK_LOGIN_SUCCESS, payload: token }) } else { //Start up FB Login process } }
export const emailChange = (text) => { return { type: 'email_change', payload: text } }
lsof -i :8081 kill -9 <port_number>