Skip to content

Instantly share code, notes, and snippets.

View apiv's full-sized avatar

Austin Pivarnik apiv

View GitHub Profile
/**
* Jest Conversion script
* This script isn't the cleanest, and uses two different methods for performing global replaces... but it gets the job done.
* We switched from using the `replace` method to the `advancedReplace` about 70% of the way through, and couldn't go and retrofit
* `advancedReplace` everywhere with 100% confidence. However, should you use this script as a base for your own migration,
* I would definitely suggest using `advancedReplace`, which uses the node-replace library.
*/
import {sync as globSync} from 'glob'
import {execSync} from 'child_process'
import fs from 'fs'
language: node_js
sudo: required
dist: trusty
node_js:
- '8'
env:
- JOB_COUNT=5 JOB_INDEX=0
- JOB_COUNT=5 JOB_INDEX=1
- JOB_COUNT=5 JOB_INDEX=2
{
"scripts": {
"test": "node ./node_modules/.bin/jest",
"test:ci": "yarn test --testMatch=$(babel-node ./scripts/parallelize.js)"
}
}
/* @flow */
import glob from 'glob'
/**
* writes a list of files matching the glob pattern to stdout
* runs only the subset of files which fall within the job, set
* in the environment variables.
*
* JOB_COUNT is the number of jobs we will be splitting across, 1-indexed
* JOB_INDEX is the index of the job (subset of files) we should be running, 0-indexed
# Tab complete for ./git-merge-pr script
__git-merge-pr-complete()
{
local cur_word prev_word branch_list
# COMP_WORDS is an array of words in the current command line.
# COMP_CWORD is the index of the current word (the one the cursor is
# in). So COMP_WORDS[COMP_CWORD] is the current word; we also record
# the previous word here, although this specific script doesn't
# use it yet.
type Options = {
action: string,
type: string,
data: {},
params: {},
tolerance?: number,
debounce?: boolean
}
const performAction = (options: Options) => {
// @flow
type Options = {
getId: (passedProps: {}) => string | string[]
}
const Entities = (options: Options) => /* ...code ... */
Entities({ getId: ({ contactId }) => Immutable.List([contactId]) })
// => throws a compiler error, return type of getId must be string | string[]
Entities({ getId: ({ contactId }) => contactId && [contactId] })
import React, { Component }
import { Entities } from 'lib/api/module'
@Entities({
contactResource: {
type: 'contact',
getId: (passedProps) => passedProps.contactId
}
})
class MyComponent extends Component { /* ... */ }

I'll expand this readme soon... but, you get the point, right?

decorator helper - Returns a function that allows you to invoke the decorator function to pass options to before applying the decorator to the property/method.

type option in property decorator - Will coerce the html attribute's value to the type specified when setting from an attribute.

Initializer support - Supports ES7 initial values.

@apiv
apiv / reduce-obj.js
Created September 15, 2015 19:18
Reduce function for an object
function reduceObject(obj, fn, init) {
return Object.keys(obj).reduce(function (accum, key) {
return fn(accum, obj[key], key, obj);
}, init);
}
// usage
var obj = {
a: [1,2,3],