Skip to content

Instantly share code, notes, and snippets.

Avatar

Adam Mackintosh agm1984

View GitHub Profile
@agm1984
agm1984 / reactNativeRememberMe
Last active Oct 31, 2017
React Native, Redux, JWT & Remember Me
View reactNativeRememberMe
//LOGIN VIEW
import {
initRememberMe,
toggleRememberMe
} from './login_actions'
class LoginForm extends Component {
componentWillMount() {
this.props.initRememberMe()
}
@agm1984
agm1984 / reactScrollPositionY.js
Created Feb 23, 2018
How to get Y scroll position in React
View reactScrollPositionY.js
import React, { Component } from 'react'
import UserDetails from './UserDetails'
/**
* This utility function allows function calls to be debounced.
* @param {Function} func Function that requires debouncing
* @param {Number} wait Wait time in milliseconds between successive invocations
*/
const debounce = (func, wait) => {
let timeout
@agm1984
agm1984 / capitalizer.js
Last active Mar 13, 2018
Word Capitalizer Function && Sentence Capitalizer Function
View capitalizer.js
// 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 Apr 6, 2018
Some THREE.js experiementation
View three-with-react.js
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 Apr 10, 2018
JavaScript: is return await needed? sometimes.
View returnAwait.js
// 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
Adam ES Lint Airbnb config settings
View eslintrc.json
{
"env": {
"node": true,
"browser": true,
"es6": true
},
"parser": "babel-eslint",
"extends": "airbnb",
"parserOptions": {
"ecmaFeatures": {
View recursiveFetch.js
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 Jun 15, 2018
ES Lint config for Vue JS
View .eslintrc.json
{
"env": {
"browser": true,
"es6": true,
"node": true
},
"parserOptions": {
"parser": "babel-eslint"
},
"extends": [
@agm1984
agm1984 / composition-example.js
Last active Jul 21, 2018
Advanced JavaScript Object and Function composition using basic logic
View composition-example.js
// 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 Nov 4, 2018
Shows the amount of time elapsed since a timestamp, with pretty formatting
View showTimeElapsed.js
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