Skip to content

Instantly share code, notes, and snippets.

View djmccormick's full-sized avatar

Dustin McCormick djmccormick

  • Indianapolis, IN
View GitHub Profile
@djmccormick
djmccormick / BaseComponent.js
Created June 12, 2017 07:54
A base react component supporting Immutable state, smarter shouldComponentUpdate, and related helper methods.
import Immutable from 'immutable';
import { Component } from 'react';
import _ from 'lodash';
import shallowEqual from 'shallowequal';
export default class BaseComponent extends Component {
constructor() {
super(...arguments);
this.state = { data: this.getDefaultState() };
@djmccormick
djmccormick / connect-to-stores.js
Last active February 18, 2016 04:19
An ES6 decorator for syncing Alt.js store changes with React components. This is similar to Alt.js's connectToStores higher-order component, except implemented as a decorator to avoid the problems that come with higher-order components. getStores (return an array of stores to listen to) and getStateFromStores (return an object of state updates) …
import React from 'react';
import _ from 'lodash';
export default function (Base) {
return class extends Base {
constructor() {
super();
if (!_.isFunction(this.getStores)) {
throw new Error('connectToStores() expects the decorated component to have a getStores() method.');
@djmccormick
djmccormick / .tmux.conf
Last active August 29, 2015 14:13 — forked from snuggs/.tmux.conf
##############################
# _
# | |_ _ __ ___ _ ___ __
# | __| '_ ` _ \| | | \ \/ /
# | |_| | | | | | |_| |> <
# \__|_| |_| |_|\__,_/_/\_\
#
#############################
#
# COPY AND PASTE
@djmccormick
djmccormick / helpers.js
Created October 17, 2014 15:41
Add to Underscore.js the ability to get a nested object property via a path string.
_.mixin({
/**
* getNestedObjectPropertyByPath
*
* Helps in accessing a nested object property via a path string
* See http://stackoverflow.com/a/6491621/679369
*
* @param {object} o An object
* @param {string} s A string representing the key of a property to return
* @return {*} The property of o represented by s
@djmccormick
djmccormick / git-cleanup
Last active August 29, 2015 14:06
A quick shell script to clean up merged branches both locally and on origin, plus prune local branches
#!/bin/sh
git checkout master
git remote update --prune
git branch -r --merged | grep -v master | grep -v develop | sed -e 's/origin\//:/' | xargs git push origin
git branch --merged | grep -v master | grep -v develop | xargs git branch -d