Skip to content

Instantly share code, notes, and snippets.

View timlesallen's full-sized avatar

Tim Allen timlesallen

View GitHub Profile
const findMin = array =>
array.find(
(item, index) => item < array[index > 0 ? index - 1 : array.length - 1]
);
const findMinBinarySearch = (array, left = 0, right) => {
if (right === undefined) right = array.length - 1;
if (right - left === 0) return array[left];
const midpoint = Math.floor(left + (right - left) / 2);
@timlesallen
timlesallen / index.js
Last active September 16, 2020 23:00
function fibonacciLike (input) {
const sequences = [];
input.forEach((number, i) => {
// Append to the all sequences where this is a legitimate continuation.
// We need to consider all of them because any values of a, b where a + b = c could form
// part of the solution depending on what comes afterwards.
sequences.forEach(sequence => {
const [a, b] = sequence;
if (a + b === number) sequence.unshift(number);
});
0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'ci' ]
2 info using [email protected]
3 info using [email protected]
4 verbose npm-session e834e6c25bc148cd
5 info prepare initializing installer
6 verbose prepare starting workers
7 verbose prepare installation prefix: /code
8 verbose prepare using package-lock.json
9 warn prepare removing existing node_modules/ before installation
services:
myservice:
volumes: npm-cache:/root/.npm
command: npm run install-start
volumes:
npm-cache:
external: false
@timlesallen
timlesallen / gist:0c4934ca0644b12e1e69
Last active August 29, 2015 14:13
Provisioning a docker container (port 80) on ec2 (WIP)
# First, create an ec2 instance and log in to it.
curl -sSL https://get.docker.com/ubuntu/ | sudo sh # (sets up docker on the box)
git pull <git repo> # get your repo
cd <git repo> && sudo docker build -t <image-tag> . #build your image
sudo docker run -d -p 80:80 --restart=always <image-tag> # start it
@timlesallen
timlesallen / gist:8515673
Last active January 3, 2016 20:29
Playing around to get a nice(r) API for the job management module.
/**
* @param {Object} job The data you want to save for the job.
* @param {int} processIn The job will not get service until this many ms have elapsed.
* @param {function} done Callback.
*/
jobs.create(job, processIn, done);
// Form of callback for jobs.process():
// done(err, newJob, processIn)
var callback = function(job, done) {