Skip to content

Instantly share code, notes, and snippets.

View anthonybrown's full-sized avatar
🎯
Focusing

Tony Brown anthonybrown

🎯
Focusing
View GitHub Profile

Squashing Git Commits

The easy and flexible way

This method avoids merge conflicts if you have periodically pulled master into your branch. It also gives you the opportunity to squash into more than 1 commit, or to re-arrange your code into completely different commits (e.g. if you ended up working on three different features but the commits were not consecutive).

Note: You cannot use this method if you intend to open a pull request to merge your feature branch. This method requires committing directly to master.

Switch to the master branch and make sure you are up to date:

@anthonybrown
anthonybrown / 0-Simple counter: different implementations...
Created February 26, 2017 02:35 — forked from srdjan/100+ different counter apps...
Simple counter: different implementations...
different implementations of the simple counter app... code verbosity vs expressiveness
@anthonybrown
anthonybrown / 0. intro.md
Created February 17, 2017 09:02 — forked from jquense/0. intro.md
Alternative ways to define react Components

The 0.13.0 improvements to React Components are often framed as "es6 classes" but being able to use the new class syntax isn't really the big change. The main thing of note in 0.13 is that React Components are no longer special objects that need to be created using a specific method (createClass()). One of the benefits of this change is that you can use the es6 class syntax, but also tons of other patterns work as well!

Below are a few examples creating React components that all work as expected using a bunch of JS object creation patterns (https://github.com/getify/You-Dont-Know-JS/blob/master/this%20&%20object%20prototypes/ch4.md#mixins). All of the examples are of stateful components, and so need to delegate to React.Component for setState(), but if you have stateless components each patterns tends to get even simpler. The one major caveat with react components is that you need to assign props and context to the component instance otherwise the component will be static. The reason is

@anthonybrown
anthonybrown / npm-upgrade-bleeding.sh
Created January 24, 2017 01:20 — forked from othiym23/npm-upgrade-bleeding.sh
a safe way to upgrade all of your globally-installed npm packages
#!/bin/sh
set -e
set -x
for package in $(npm -g outdated --parseable --depth=0 | cut -d: -f3)
do
npm -g install "$package"
done
@anthonybrown
anthonybrown / 00_LICENSE.md
Created January 4, 2017 08:43 — forked from jfarmer/00_LICENSE.md
It's like lisp, in JavaScript!
@anthonybrown
anthonybrown / README.md
Created December 11, 2016 10:52 — forked from hofmannsven/README.md
My simply Git Cheatsheet
import React from 'react'
import Router from 'react-router/BrowserRouter'
import Match from 'react-router/Match'
import Link from 'react-router/Link'
import Redirect from 'react-router/Redirect'
function elementInViewport(el) {
var top = el.offsetTop
var left = el.offsetLeft
var width = el.offsetWidth
@anthonybrown
anthonybrown / my-component.spec.js
Created November 14, 2016 13:37 — forked from thevangelist/my-component.spec.js
The only React.js component test you'll ever need (Enzyme + Chai)
import React from 'react';
import { shallow } from 'enzyme';
import MyComponent from '../src/my-component';
const wrapper = shallow(<MyComponent/>);
describe('(Component) MyComponent', () => {
it('renders without exploding', () => {
expect(wrapper).to.have.length(1);
});
// this `<Route>` component might make it possible for you to ~generally~
// upgrade to React Router v4 w/o doing hardly anything to your app for the
// happy path stuff.
//
// This definitely won't work as-is, I haven't run this code, just banged it
// out when the thought occured to me that it might be possible.
const { func, object } = React.PropTypes
const Route = (route) => (
@anthonybrown
anthonybrown / form-fields.jsx
Created October 27, 2016 18:29
A quick rundown of working with Redux-Form 6+
import React, { Component } from 'react';
import { Field, reduxForm } from 'redux-form';
import moment from 'moment';
import DatePicker from 'react-datepicker';
import ReactQuill from 'react-quill';
import MaskedInput from 'react-maskedinput';
export const renderField = (field) => (
<div>
<input {...field.input} type={field.type} placeholder={field.placeholder} className="form-control" />