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
# Add these lines to your dockerfile, before `npm install` | |
# Copy the bitbucket private key to your docker image | |
COPY ./bitbucket_ssh_key /opt/my-app | |
# Copy the ssh script to your docker image | |
COPY ./ssh-bitbucket.sh /opt/my-app | |
# Tell git to use your `ssh-bitbucket.sh` script | |
ENV GIT_SSH="/opt/map-project-tile-server/ssh-bitbucket.sh" |
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 * as fs from 'fs'; | |
import * as assert from 'assert'; | |
import * as _ from 'lodash'; | |
function assertFileExists(filePath:string, msg?:string) { | |
try { | |
fs.statSync(filePath); | |
} | |
catch (err) { | |
if (_.includes(['ENOENT', 'ENOTDIR'], err.code)) { |
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
function mockReadFile(mockPath, content) { | |
// see https://gist.github.com/eschwartz/955a3f8925e24270550cb635dd49c12b | |
const deferred = Deferred(); | |
sinon.stub(fs, 'readFile', _.wrap(fs.readFile, (origFn, path, encoding, cb) => { | |
if (path !== mockPath) { | |
return origFn.readFile(path, encoding, cb); | |
} | |
// Only resolve `fs.readFile` when deferred is resolved |
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
/** | |
* eg. | |
* | |
* poll( | |
* () => Promise.resolve(Math.random()), | |
* val => val > 0.5 | |
* ) | |
* .then(val => console.log(`You won, with ${val}!`)); | |
* | |
* @param {():Promise<T>} run |
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
function Deferred() { | |
var deferred = { | |
resolve: null, | |
reject: null | |
}; | |
deferred.promise = new Promise((resolve, reject) => { | |
// Save resolve/reject to deferred, for later usage. | |
deferred.resolve = resolve; | |
deferred.reject = reject; | |
}); |
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
function intent({DOM}) { | |
return { | |
addTodo: DOM.get('input', 'change'). | |
map(evt => evt.target.value). | |
filter(val => val.trim().length), | |
removeTodo: DOM.get('button', 'click'). | |
// Map the remove button click to the item text | |
map(evt => evt.target.previousElementSibling.innerText.trim()) | |
}; | |
} |
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 fs = require('fs'); | |
const assert = require('assert'); | |
const _ = require('lodash'); | |
function fileExists(filePath, msg) { | |
try { | |
fs.statSync(filePath); | |
} | |
catch (err) { | |
if (_.includes(['ENOENT', 'ENOTDIR'], err.code)) { |
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 assert = require('assert'); | |
const _ = require('lodash'); | |
function throwsAsync(block, expectedError, message) { | |
return block() | |
.then(res => { | |
assert.fail(res, expectedError, message, 'is'); | |
}, err => { | |
if (_.isFunction(expectedError)) { | |
// note that assert.throws doesn't work with custom Error constructors |
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
#!/usr/bin/env node | |
/** | |
* Usage: | |
* | |
* node cluster.js ./worker-script.js | |
*/ | |
const cluster = require('cluster'); | |
const path = require('path'); | |
function startCluster(runWorker, opts) { |
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 _ = require('lodash'); | |
function series(count, asyncFn) { | |
return _.range(0, count) | |
.reduce((lastRun_, i) => { | |
return lastRun_.then(() => asyncFn(i)) | |
}, Promise.resolve()); | |
} | |
series(10, (i) => { |