This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const log = console.log; | |
function timed(title, promiseFactory) { | |
return (...args) => { | |
const t0 = Date.now(); | |
log(title, 'start'); | |
return promiseFactory(...args) | |
.then((results) => { | |
const dt = Date.now() - t0; | |
log(title, 'end', `(${dt} ms)`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Extracted from https://github.com/rjz/typescript-react-redux | |
// Simulate a flaky API around otherwise an otherwise synchronous `f()`. | |
const flakify = <T>(f: () => T): Promise<T> => | |
new Promise((resolve, reject) => | |
// We'll always take 200 * (1d10 + 1) ms to respond | |
window.setTimeout(() => { | |
try { | |
// And ~20% of the time we'll fail, because flaky. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Check local javascript files for references to dependencies appearing in | |
# `package.json`. | |
# | |
# `require`-only: **does not** account for ESNext `import` syntax (yet!) | |
js_files=$(find . -path ./node_modules -prune -o -name '*.js' -type f \ | |
| grep -v node_modules) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Update TypeScript `typings` to their latest versions. | |
# | |
# Running this ad-hoc may break your project; be prepared to resolve issues by | |
# hand. | |
# | |
# Released under the terms of the MIT License | |
set -e |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# pre-commit hook to lint JS/X | |
# | |
# Assumes that `eslint` is installed via npm as usual. | |
set -e | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Bootstraps setup of dynamodb_local | |
# Set download path if needed | |
DOWNLOAD_PATH=http://dynamodb-local.s3-website-us-west-2.amazonaws.com/dynamodb_local_latest.tar.gz | |
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
BUNDLE_FILE="${DIR}/dynamodb_local_latest.tar.gz" | |
INSTALL_DIR="${DIR}/.dynamo" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example of mocking out global `fetch` | |
// | |
// Spec works using Jasmine (via Karma) and _either_ tsc or babel. | |
// | |
// $ npm install --save-dev fetch-mock whatwg-fetch | |
// | |
// If using `tsc`, grab the type definitions as well: | |
// | |
// $ typings --save --global dt~fetch-mock dt~whatwg-fetch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Redux actions using TypeScript discriminated unions | |
// | |
// Source: https://github.com/rjz/typescript-react-redux/ | |
// Actions | |
export type Action = | |
{ type: 'INCREMENT_COUNTER', delta: number } | |
| { type: 'RESET_COUNTER' } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# ngrok's web interface is HTML, but configuration is bootstrapped as a JSON | |
# string. We can hack out the forwarded hostname by extracting the next | |
# `*.ngrok.io` string from the JSON | |
# | |
# Brittle as all get out--YMMV. If you're still reading, usage is: | |
# | |
# $ ./ngrok_hostname.sh <proto> <addr> | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"mime" | |
"net/http" | |
"strings" | |
) | |
// Determine whether the request `content-type` includes a | |
// server-acceptable mime-type | |
// | |
// Failure should yield an HTTP 415 (`http.StatusUnsupportedMediaType`) |