Skip to content

Instantly share code, notes, and snippets.

View jethrolarson's full-sized avatar
:shipit:

Jethro Larson jethrolarson

:shipit:
  • Tableau
  • Seattle
View GitHub Profile
// Take string and get words as an array. Valid split characters are `,` `.` `\s` `/` `\n`
// words :: String -> [String]
export const words = str =>
(str ? str.split(/[\s\n.,/]+/) : []) // split on whitespace
.filter(Boolean);
@jethrolarson
jethrolarson / gist:99ca3c02c0f8c5de85b10843778a580c
Created December 2, 2017 00:57
How moment.js parses falsy values
moment(0) // epoc
moment(undefined) // Now
moment(null) // Invalid Date
moment(false) // throw warning, Invalid date
moment(void 0) // Now
moment('') // Invlid Date
moment([]) // Now
moment({}) // Now
Lenses
======
What is a lens?
---------------
pair of getter and setter that perform immutable updates on parameterized data structure
e.g.
```js
@jethrolarson
jethrolarson / gist:65732a8ba9b4f620b68930923ec3c48a
Created June 21, 2017 22:49
Big O notation for story estimation
O(1) - Trivial, we've done something almost exactly like this and it wont take long to complete at all
O(log n) - Need to add a small capability then it's copy-pasta
O(n) - Simple, It's like things we've done before. No refactoring or architectural changes needed.
O(n^2) - Going to need to rework some things and watch out for regressions
O(n!) - Major rework needed, lots of risk
O(MG) - This is so complex or ill-defined that it may never complete
@jethrolarson
jethrolarson / asyncRedux.md
Last active May 10, 2017 22:32
options for async actions in redux

Note: These aren't necessarily mutually exclusive. E.g. we may want to use promise with thunk to get better ergonomics for certain kinds of effects.

Learnability: 4
Testability: 4
Happy path: 4
Purity: 2
SLOC: 14

  • Doesn't do a lot for you. Just makes it easy to do async actions
// Immutable update techniques
// mutate in place
myData.x.y.z = 7;
myData.a.b.push(9);
mydata.a.b[2] = 3;
// clone and mutate
const newData = deepCopy(myData);
newData.x.y.z = 7;
@jethrolarson
jethrolarson / reactiveLibraries.md
Last active March 26, 2022 01:14
Reactive Stream Library Comparison

Flyd

https://github.com/paldepind/flyd
License: MIT
Size: 22.4 KB (3.4 KB gzip)
Functions: 16
Project Life: Good
Stars: 1129
Code Quality: Good Functional/Procedural
Comments: JSDoc
Quality Automation: Extensive unit tests, CI

@jethrolarson
jethrolarson / typeSignatures.md
Last active January 27, 2017 23:19
presentation on type signatures in js

Type Signatures for your JS

Y THO

A form of documentation that helps developers understand what a function does.

// toUpper :: String -> String
const toUpper = str => str.toUpperCase()
@jethrolarson
jethrolarson / index.js
Created January 4, 2017 18:41
Loop fusion with transducers in Ramda
import {into, pipe, filter, map, propEq, prop} from 'ramda';
const doStuff = pipe(
filter(propEq('status', 'active')),
map(prop('age'))
);
// only iterates array once
into([], doStuff, [{status: 'active', name: 'Pam'}, {status: 'bad', name: 'Mancy'}]);
// ['Pam']
@jethrolarson
jethrolarson / createClass.jsx
Created December 14, 2016 21:31
Bind all solutions
import React, {createClass} from 'react';
class MediaLibrary = createClass({
foo() {
this.setState({foo: !this.state.foo})
},
render() {
return (<Bar onFoo={this.foo} />);
}
}