Skip to content

Instantly share code, notes, and snippets.

@bradparker
bradparker / generic-state-container.md
Last active January 6, 2016 03:34
Generic state container

Must do prop transformation, it needs to add a specific onChange handler to each control.

I dislike this immensly but it'll work with our existing components and is ugly enough to encourage us to move to something like Redux.

// import get from 'lodash/object/get'

const handleControlChange = (onChange, statePath) => (value) =>
  onChange(statePath, value)
  
@bradparker
bradparker / sharing-behaviour-between-react-components.md
Last active June 13, 2018 21:03
Sharing behaviour between React components

Sharing behaviour between React components

React 0.13 introduced using plain Javascript classes to create components, 0.14 introduced "stateless functional components" as another method of defining them. Neither of these have an in-built method for behaviour sharing such as we had with the mixins option passed to createClass. So now we get to review mixins as a pattern for behaviour sharing and, if necessary, come up with something better. If they're not all bad, we'll need to figure out how to, or even if we can, add them to the two new component definition options.

The problem

Dan Abromov's medium article from Mar 2015 makes the case for avoiding mixins.

For me (paraphrasing in the extreme), the key problems exposed are:

  • mixins can unintentionally hide / distribute the source of behaviour
@bradparker
bradparker / method-compose.js
Created November 17, 2015 08:01
Smoosh two object's methods together
const { keys, assign } = Object
const concern = {
doSideEffectyThing () {
this.property1 = 'Hip, hip!'
}
}
const instance = {
someProp: 'Foo',
@bradparker
bradparker / package.json
Last active January 12, 2016 06:13
Keep it simple
{
"name": "get-going",
"version": "2.0.1",
"description": "",
"main": "dist/index.html",
"engines": {
"node": "5.2.0"
},
"scripts": {
"setup:source:dir": "mkdir -p source",
@bradparker
bradparker / rough-outline-of-steps.md
Created September 16, 2015 00:44
Design production process

Rough outline of the steps in an isolated design job

  • Define project objectives
  • Review identity standards
  • Develop concepts and prototypes (The Design process)
  • Present solution
  • Evaluate solution (Maybe loops back to Develop)
  • Prepare for production
  • Evaluate finished piece(s) (Maybe loops back to Develop)
  • Deliver finished files for production / distribution
@bradparker
bradparker / a_ok.rb
Created September 9, 2015 01:57
Well this is, unsurprisingly, fine
(1..10e6).map {
SecureRandom.uuid
}.reduce(Hash.new(0)) { |counts, uuid|
counts[uuid] += 1
counts
}.values.uniq
@bradparker
bradparker / index.html
Created August 30, 2015 12:32
JS Scratch Pad
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Scratch pad</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.2.5/mocha.min.css" />
</head>
<body>
<div id="mocha"></div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.2.0/chai.min.js"></script>
@bradparker
bradparker / alternative.hs
Last active May 25, 2018 04:28
Haskell Buzz
module Main where
import Control.Applicative
import Data.Monoid
fizz n
| n `mod` 3 == 0 = Just "Fizz"
| otherwise = Nothing
buzz n
@bradparker
bradparker / cons.js
Last active August 29, 2015 14:20
Cons!
const cons = (a, b) =>
(member) => {
if (member === 1) {
return a
} else if (member === 2) {
return b
}
}
const car = (pair) =>
@bradparker
bradparker / line-slope-intercept.js
Created December 31, 2014 03:33
Line, slope intercept form
function Line (slope, intercept) {
this.slope = slope
this.intercept = intercept
}
function getX (y) {
y = y || 0
return (y - this.intercept) / this.slope
}
Line.prototype.getX = getX;