Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / simple-rev.js
Created January 15, 2016 03:00
simple revision-er
'use strict'
const crypto = require('crypto')
const fs = require('fs')
const mkdirp = require('mkdirp')
const path = require('path')
const recursive = require('recursive-readdir')
const assign = Object.assign
const keys = Object.keys
@bradparker
bradparker / hoc-examples.js
Last active January 18, 2016 05:41
HOC examples
// I18n
const translateable = (translations) => (Component) =>
(props = { locale: 'default' }) => {
const localTranslations = translations[locale]
return <Component { ...props } { ...localTranslations } />
}
const Greeter = ({ greeting, name }) =>
<p>{ greeting }, { name }</p>
@bradparker
bradparker / mathy-parser.js
Last active February 21, 2016 08:05
Dunno yet
import { expect } from 'chai'
const head = (arr = []) => arr[0]
const tail = (arr = []) => arr.slice(1)
const last = (arr = []) => arr.slice(0).pop()
const init = (arr = []) => arr.slice(0, arr.length - 1)
const nextInScope = (tokens, depth = 1, closeCount = 0) => {
if (depth === closeCount) {
return tokens
@bradparker
bradparker / lijsp.js
Last active March 17, 2016 04:18
LIJSP... heh
import { expect } from 'chai'
const head = (arr = []) => arr.slice(0)[0]
const tail = (arr = []) => arr.slice(1)
const last = (arr = []) => arr.slice(0).pop()
const init = (arr = []) => arr.slice(0, arr.length - 1)
const subExpression = (tokens, depth = 0, currentBranch = []) => {
if (tokens.length === 0 || head(tokens) === ')') {
return [currentBranch, tail(tokens)]