Skip to content

Instantly share code, notes, and snippets.

View gabemeola's full-sized avatar
🐛

Gabe gabemeola

🐛
View GitHub Profile
@gabemeola
gabemeola / states_hash.json
Created February 27, 2017 21:26 — forked from mshafrir/states_hash.json
US states in JSON form
{
"AL": "Alabama",
"AK": "Alaska",
"AS": "American Samoa",
"AZ": "Arizona",
"AR": "Arkansas",
"CA": "California",
"CO": "Colorado",
"CT": "Connecticut",
"DE": "Delaware",
@gabemeola
gabemeola / LazyLoad.jsx
Created April 16, 2017 21:53
Lazyloading React components using React Router and Webpack Code Module Splitting
import React, { Component, PropTypes } from 'react';
import { LoadingSplash, LoadingSpinner } from 'components/Injectables';
export default class LazyLoad extends Component {
constructor(props) {
super(props);
this.state = {
loading: true,
error: '',
@gabemeola
gabemeola / BouncePress.jsx
Last active April 16, 2017 22:05
Higher Order Component that wraps any clickable element, allowing for a "bounce" animation on click or touch.
import React, { PropTypes, Component } from 'react';
class BouncePress extends Component {
constructor(props) {
super(props);
this.bouncePressElem = null;
}
addBouncePressRef = (e) => {
this.bouncePressElem = e;
@gabemeola
gabemeola / app.jsx
Created April 16, 2017 22:14
Initializing React Application with async data loading, and persisting data to user device local storage with redux-persist and localForage.
/* Import in React Project files */
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import thunk from 'redux-thunk';
import { combineReducers, compose, applyMiddleware, createStore } from 'redux';
import { persistStore, autoRehydrate } from 'redux-persist';
import localForage from 'localforage';
/* Import Routes and App Data */
@gabemeola
gabemeola / Deferred.js
Created November 24, 2017 18:25
Deferred Object using native Promises
const noop = () => {};
/**
* This Class creates a Promise object
* that has its resolve and reject
* methods publicly exposed.
*
* This allows a user to resolve / reject
* this promise from outside the Promise function scope.
*/
@gabemeola
gabemeola / introrx.md
Created December 4, 2017 22:06 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
@gabemeola
gabemeola / insertScript.js
Created December 18, 2017 19:18
Helper function for inserting external script tags
/**
* Inserts a script tag of src
* in the Head of HTML.
*
* @param {string} src - Src for Javascript request
* @param {Object} config
* @return {Promise} - Returns a promise of event when loaded / error
*/
export default function insertScript(src, { async = true, defer = false } = {}) {
return new Promise((resolve, reject) => {
import { debounce } from 'lodash';
class ResizeObservable {
constructor() {
this.listeners = [];
this._resizeFunc = debounce(() => {
this.emit();
}, 300);
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Loading } from 'components';
export default class Enabler extends Component {
static propTypes = {
children: PropTypes.node.isRequired,
/**
* Bootstrap function to run.
@gabemeola
gabemeola / once.js
Last active January 16, 2018 02:53
Caches a function call to be in lazily invoked just once.
/**
* Takes a function a lazily runs it once when invoked.
*
* Returns cached return value to subsequent calls.
* Return value will always have reference equality with subsequent calls.
*
* @param {function} func - Function to run Once
* @return {function}
*/
export default function once(func) {