Skip to content

Instantly share code, notes, and snippets.

View angeloashmore's full-sized avatar

Angelo Ashmore angeloashmore

View GitHub Profile
@angeloashmore
angeloashmore / useEventEmitter.js
Created October 27, 2019 21:24
Creates an event emitter and returns a hook that can listen to and emit events.
import { useEffect } from 'react'
import mitt from 'mitt'
// Creates an new event emitter and returns a hook that can listen to and emit
// events.
const create = () => {
const emitter = mitt()
const useEventEmitter = handlers => {
useEffect(() => {
@angeloashmore
angeloashmore / .tmux.conf
Last active January 18, 2020 02:27
dotfiles
#####################
# Plugins
#####################
# Base
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
# UI
set -g @plugin 'seebi/tmux-colors-solarized'
@angeloashmore
angeloashmore / gatsby-build-time-optimizations.md
Last active October 4, 2019 19:56
Strategies to shorten build times for Gatsby websites.

Gatsby Build Time Optimizations

Strategies to shorten build times for Gatsby websites.

Gatsby Image

Reduce number of breakpoints using srcSetBreakpoints

srcSetBreakpoints sets the quantity and dimensions of the images provided to the srcset property. By default, Gatsby Image (via gatsby-plugin-sharp)

@angeloashmore
angeloashmore / withDefaultProps.js
Created September 19, 2019 21:52
React HOC to automatically apply a component's default props before provided props.
import React from 'react'
import hoistNonReactStatics from 'hoist-non-react-statics'
// Returns the components name. If a name cannot be determined, "Component" is
// used.
const getComponentName = Component =>
Component.displayName || Component.name || 'Component'
// Higher order component that automatically applies default props to the
// wrapped component.
@angeloashmore
angeloashmore / useScrollYDirection.js
Created May 6, 2019 20:58
Basic scrollY direction hook. -1 if up, 1 if down, 0 if static.
import { useState, useCallback, useEffect, useRef } from 'react'
const isBrowser = typeof window !== 'undefined'
export const useScrollDirection = ({ threshold = 0 }) => {
const UP = -1
const STATIC = 0
const DOWN = 1
const prev = useRef(isBrowser ? window.scrollY : 0)
@angeloashmore
angeloashmore / useDispatcher.js
Created April 17, 2019 00:03
Reducer-style action handler hook. Send actions using a { type, payload } action descriptor.
import {
__,
compose,
difference,
has
isFunction,
isPlainObject,
keys,
negate,
} from 'lodash/fp'
@angeloashmore
angeloashmore / valuesDeep.js
Created August 20, 2018 08:30
Returns all deeply nested values of the supplied object.
import * as R from 'ramda'
import * as RA from 'ramda-adjunct'
export const valuesDeep =
R.cond([
[
RA.isPlainObj,
R.pipe(
R.values,
R.map(x => valuesDeep(x)),
@angeloashmore
angeloashmore / guide.md
Created March 15, 2018 00:47
Setup macOS nodejs development environment
  1. Install Homebrew

    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  2. Create a Brewfile

    touch ~/Brewfile
@angeloashmore
angeloashmore / Preload.js
Last active January 23, 2018 22:24
React Preload Component
import React, { Component } from 'react'
import PropTypes from 'prop-types'
import { withStatechart } from 'react-automata'
const statechart = {
initial: 'idle',
states: {
idle: {
on: {
LOAD: 'loading',
;; -*- mode: emacs-lisp -*-
;; This file is loaded by Spacemacs at startup.
;; It must be stored in your home directory.
(defun dotspacemacs/layers ()
"Configuration Layers declaration.
You should not put any user code in this function besides modifying the variable
values."
(setq-default
;; Base distribution to use. This is a layer contained in the directory