Skip to content

Instantly share code, notes, and snippets.

Working from home in Boston, sometimes in DC

Eric Brookfield ericdfields

Working from home in Boston, sometimes in DC
Block or report user

Report or block ericdfields

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View prepareModelForRails.js
import reduce from 'lodash/reduce'
import isArray from 'lodash/isArray'
const prepareModelForRails = (model) => {
if (typeof model !== 'object') {
return model
} else {
if (isArray(model)) {
return m => prepareModelForRails(m) )
} else {
return reduce(model, (result, value, key) => {
View editPersonComponent.js
EditPersonForm = reduxForm({
form: 'person',
touchOnChange: true
import { createStore, combineReducers } from 'redux'
import { reducer as formReducer } from 'redux-form'
const reducers = {
form: formReducer
View phoneNumbers.js
const renderPhoneNumbers = ({ fields, meta: { touched, error, submitFailed } }) => (
<button type="button" onClick={() => fields.push({})}>Add Phone Number</button>
{(touched || submitFailed) && error && <span>{error}</span>}
{, index) => {
const field = fields.get(index)
if (field && field._destroy) {
return false
View form.js
class EditPersonForm extends Component {
render() {
const { handleSubmit } = this.props
return (
<form onSubmit={handleSubmit}>
<label htmlFor="first_name">First Name</label>
<Field name="first_name" component="input" />
View example.js
.post( parseHref(this.props) )
.send( updatedPayload(payload,entity) )
.end( (err,response) => {
if (err) {
return standardError()
this.props.callback && this.props.callback()
View ajax.js
const ajax = require('superagent')
export default ajax
ericdfields / gist:3d4ed9c7f7b559289a102207facd61a7
Created Feb 3, 2017
Add multiple items to an Amazon Cart with a single button
View gist:3d4ed9c7f7b559289a102207facd61a7
I've seen links around the web for a list of items and a single 'add to amazon cart' button.
I don't know how to do this more easily through an amazon-provided UI, but it seems that you can hack it together through URL params easy enough, like so:
* ASINs are the string after /dp/ in amazon URLs. (
* Add as URL params w/ incrementing identifiers and quantity couplets (ASIN.1, Quantity.1, ASIN.2, Quantity.2…)
ericdfields / component.js
Last active Jan 10, 2017
Loading Inline SVG into React
View component.js
Use CSS for styling via the awesome styled-components library
import styled from 'styled-components'
const LoadingImage = require('loading-svg/loading-spin.svg')
const LoadingComponent = styled(LoadingImage)`
ericdfields / HOCComponents.js
Last active Sep 28, 2016
Replace nested react component using higher order component
View HOCComponents.js
export class FaxDocumentViewerApp extends Component {
defaultProps = {
documentTitle: (doc) => `${doc.fax_type}${moment(doc.created_at).format('MMM D YYYY [@] h:mm a')}`
render = () => {
<OriginalComponent {...this.props} />
ericdfields / app.js
Last active Aug 29, 2015
Resolving local UI state with Flux using Flummox and Promises
View app.js
import Flux from 'path/to/flux.js'
window.MyApp.flux = new Flux()
You can’t perform that action at this time.