Skip to content

Instantly share code, notes, and snippets.

View agm1984's full-sized avatar

Adam Mackintosh agm1984

View GitHub Profile
@agm1984
agm1984 / reactNativeRememberMe
Last active October 31, 2017 08:00
React Native, Redux, JWT & Remember Me
//LOGIN VIEW
import {
initRememberMe,
toggleRememberMe
} from './login_actions'
class LoginForm extends Component {
componentWillMount() {
this.props.initRememberMe()
}
@agm1984
agm1984 / capitalizer.js
Last active March 13, 2018 09:30
Word Capitalizer Function && Sentence Capitalizer Function
// CAPITALIZE WORD
// ie: Capitalize the first letter
const word = 'capitalized'
const capitalize = word => [word]
.map(letter => letter.slice(0,1).toUpperCase() + letter.slice(1))
.toString()
console.log(
'Look mom:',
@agm1984
agm1984 / three-with-react.js
Last active April 6, 2018 03:30
Some THREE.js experiementation
import React, { Component } from 'react'
import * as THREE from 'three'
// import * as OBJLoader from 'three-obj-loader'
// import MTLLoader from 'three-react-mtl-loader'
// import OBJLoader from 'three-react-obj-loader'
// const loader = require('three-json-loader')(THREE)
const OrbitControls = require('three-orbit-controls')(THREE)
// OrbitControls: for Camera
@agm1984
agm1984 / returnAwait.js
Created April 10, 2018 05:04
JavaScript: is return await needed? sometimes.
// INCLUDING AWAIT DELEGATES TO PARENT
const dontBubbleUp = async () => {
const samplerPack = async () => {
throw new Error('BAD')
}
try {
return await samplerPack()
} catch (e) {
throw new Error('handling rejection upstream in parent')
}
@agm1984
agm1984 / eslintrc.json
Created May 1, 2018 18:56
Adam ES Lint Airbnb config settings
{
"env": {
"node": true,
"browser": true,
"es6": true
},
"parser": "babel-eslint",
"extends": "airbnb",
"parserOptions": {
"ecmaFeatures": {
@agm1984
agm1984 / recursiveFetch.js
Created May 25, 2018 18:09
Solution example
const axios = require('axios')
const followIDs = async (next) => {
if (next) {
const nextRes = await axios({
method: 'get',
url: next,
responseType: 'json'
})
if (nextRes.data.message) {
@agm1984
agm1984 / .eslintrc.json
Last active June 15, 2018 21:06
ES Lint config for Vue JS
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"parserOptions": {
"parser": "babel-eslint"
},
"extends": [
@agm1984
agm1984 / composition-example.js
Last active July 21, 2018 20:52
Advanced JavaScript Object and Function composition using basic logic
// First we are creating or getting some users and placing them in `users`
const users = [
{ name: 'Bob' },
{ name: 'Alice' },
]
// Then we are creating a config object that we could pass around as needed
// Notice we are using shorthand `users` instead of `users: users`
const config = {
appOwner: 'INSERT_YOUR_NAME',
@agm1984
agm1984 / showTimeElapsed.js
Created November 4, 2018 05:57
Shows the amount of time elapsed since a timestamp, with pretty formatting
const showTimeElapsed = (timestamp) => {
if (typeof timestamp !== 'number') return 'NaN'
const SECOND = 1000
const MINUTE = SECOND * 60
const HOUR = MINUTE * 60
const DAY = HOUR * 24
const MONTH = DAY * 30
const YEAR = MONTH * 12
@agm1984
agm1984 / sortArrayOfObjects.js
Created November 19, 2018 19:08
JavaScript Sort algorithm
const data = [
{ first: 'David', last: 'Goldstein', age: 92 },
{ first: 'Tom', last: 'Stamper', age: 23 },
{ first: 'Sally', last: 'Brunswick', age: 76 },
{ first: 'Steve', last: 'Henderson', age: 37 },
{ first: 'Mark', last: 'Chopper', age: 75 },
{ first: 'Lucy', last: 'Steel', age: 29 },
]
// localeCompare is a String prototype: