Skip to content

Instantly share code, notes, and snippets.

Avatar
:shipit:

Jethro Larson jethrolarson

:shipit:
  • Tableau
  • Seattle
View GitHub Profile
View string.js
// 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);
View gist:99ca3c02c0f8c5de85b10843778a580c
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
View gist:2a28945743668cf828c9eb5a4a924d2f
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 Jun 21, 2017
Big O notation for story estimation
View gist:65732a8ba9b4f620b68930923ec3c48a
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
options for async actions in redux
View asyncRedux.md

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.

Thunk

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
View immutable_update_techniques.js
// 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 Jan 24, 2020
Reactive Stream Library Comparison
View reactiveLibraries.md

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 Jan 27, 2017
presentation on type signatures in js
View typeSignatures.md

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 Jan 4, 2017
Loop fusion with transducers in Ramda
View index.js
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']
View createClass.jsx
import React, {createClass} from 'react';
class MediaLibrary = createClass({
foo() {
this.setState({foo: !this.state.foo})
},
render() {
return (<Bar onFoo={this.foo} />);
}
}