Skip to content

Instantly share code, notes, and snippets.

Jamie Mason JamieMason

Block or report user

Report or block JamieMason

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View machine.js
// Generally Expected Flow (actions and implementation are missing)
//
// 1 renderNode runs logic which inspects this hard-coded rootNode
// 2 transtions to renderBranch because it has children
// 3 there are two children so the UI would display them
// 4 user chooses the first child
// 5 fetchNode finds no children property, so there is nothing more to load
// 6 fetchNode resolves success with the node
// 7 renderNode runs logic which inspects the node
// 8 transtions to renderLeaf because it has no children
View extract-story-codemod.js
export default function transformer(file, api) {
const j = api.jscodeshift;
const toPascalCase = str =>
`${str}`
.replace(new RegExp(/[-_]+/, 'g'), ' ')
.replace(new RegExp(/[^\w\s]/, 'g'), '')
.replace(
new RegExp(/\s+(.)(\w+)/, 'g'),
($1, $2, $3) => `${$2.toUpperCase() + $3.toLowerCase()}`
@JamieMason
JamieMason / pluck-unique-values-from-array-of-javascript-objects.md
Created Sep 14, 2018
Pluck Unique Values from Array of Javascript Objects
View pluck-unique-values-from-array-of-javascript-objects.md

Pluck Unique Values from Array of Javascript Objects

Implementation

const pluck = key => array => Array.from(new Set(array.map(obj => obj[key])));

Usage

@JamieMason
JamieMason / group-objects-by-property.md
Created Sep 14, 2018
Group Array of JavaScript Objects by Key or Property Value
View group-objects-by-property.md

Group Array of JavaScript Objects by Key or Property Value

Implementation

const groupBy = key => array =>
  array.reduce((objectsByKeyValue, obj) => {
    const value = obj[key];
    objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj);
    return objectsByKeyValue;
@JamieMason
JamieMason / transducers.md
Last active Jun 15, 2019
Learning about JavaScript Transducers
View transducers.md
@JamieMason
JamieMason / get-all-assignees-of-github-milestone.md
Created Jul 4, 2018
List all assignees of a GitHub Milestone
View get-all-assignees-of-github-milestone.md

List all assignees of a GitHub Milestone

  1. Visit the milestone at eg. https://github.com/USER/REPO/milestone/1
  2. Run this in your console
    [...document.querySelectorAll('.from-avatar')].map(el => el.getAttribute('alt'))
  3. An array of GitHub usernames will be logged.
@JamieMason
JamieMason / lerna-list-peer-dependencies.md
Created Jul 4, 2018
List all peerDependencies for packages in a Lerna Monorepo
View lerna-list-peer-dependencies.md

List all peerDependencies for packages in a Lerna Monorepo

System Requirements

brew install jq
npm install -g glob-exec

Usage

@JamieMason
JamieMason / npm-exact-versions.js
Created May 3, 2018
Replace semver ranges with exact version numbers in package.json files
View npm-exact-versions.js
const childProcess = require('child_process');
const fs = require('fs');
const path = require('path');
const glob = require('glob');
const filePaths = glob
.sync('package.json')
.concat(glob.sync('packages/*/package.json'))
.map(filePath => path.resolve(process.cwd(), filePath));
@JamieMason
JamieMason / find-recently-changed-npm-dependencies.js
Last active Jan 12, 2018
Find recently changed npm dependencies
View find-recently-changed-npm-dependencies.js
const exec = require('child_process').exec;
const sortBy = (key, reverse) => {
const moveSmaller = reverse ? 1 : -1;
const moveLarger = reverse ? -1 : 1;
return (a, b) => {
if (a[key] < b[key]) {
return moveSmaller;
}
if (a[key] > b[key]) {
View functors.js
function Maybe(x) {
if (this instanceof Maybe === false) {
return new Maybe(x);
}
this.value = x;
}
Maybe.prototype.map = fn => (this.value == null ? this : new Maybe(fn(this.value)));
function Either(left, right) {
You can’t perform that action at this time.