start_cluster
docker exec -it rc1 mongo
# then run the following in container rc1's mongo shell
rs.initiate(config = { _id: 'test-set', members: [{ _id: 0, host: 'rc1:27017' }, { _id: 1, host: 'rc2:27017' }, { _id: 2, host: 'rc3:27017' }] })
# while in there, populate some test data
use test
db.list.insertOne({ somekey: 'some value' })
db.list.insertOne({ title: 'cool' })
# finally quit
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
// credit: https://hackernoon.com/functional-javascript-resolving-promises-sequentially-7aac18c4431e | |
const N = 5 | |
const promiseSerial = funcs => | |
funcs.reduce( | |
(promise, func) => | |
promise.then(result => func().then(Array.prototype.concat.bind(result))), | |
Promise.resolve([]) | |
) |
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
// Based on https://stackoverflow.com/questions/48720942/node-js-joi-how-to-display-a-custom-error-messages | |
const Hapi = require('@hapi/hapi') | |
const Joi = require('@hapi/joi') | |
const Boom = require('@hapi/boom') | |
const server = Hapi.Server({ | |
port: 3000, | |
routes: { | |
validate: { |
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 asyncJob = () => { | |
console.time('asyncJob') | |
return new Promise(resolve => { | |
return setTimeout(() => { | |
console.timeEnd('asyncJob') | |
return resolve('result from asycJob') | |
}, 1000) | |
}) | |
} |
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
Show hidden characters
{ | |
"presets": [ | |
"env", | |
"react" | |
], | |
"plugins": [ | |
"transform-object-rest-spread", | |
"transform-class-properties" | |
] | |
} |
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 React from 'react' | |
import styled from 'styled-components' | |
const Wrapper = styled.div` | |
position: relative; | |
width: 100%; | |
padding-bottom: 2rem; | |
input:focus ~ label, | |
input:valid ~ label { |
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
serverOptions.cache = [ | |
{ | |
name: 'redisCache', | |
provider: { | |
constructor: require('catbox-redis'), | |
options: { | |
url: process.env.REDIS_URL | |
} | |
} | |
} |
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 Hapi = require('hapi') | |
const Joi = require('joi') | |
const Mongoose = require('mongoose') | |
const Boom = require('boom') | |
const server = Hapi.Server({ | |
port: 3000, | |
routes: { | |
validate: { | |
failAction: (request, h, err) => { |
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 nsq = require('nsqjs') | |
const reader = new nsq.Reader('sample_topic', 'test_channel', { | |
nsqdTCPAddresses: ['127.0.0.1:4150'] | |
}) | |
reader.connect() | |
reader.on('message', msg => { | |
console.log('Received message [%s]: %s', msg.id, msg.body.toString()) |
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
create-parcel-app() { | |
[ $# -lt 1 ] && echo "$funcstack[1] project-name" | |
project=$1 | |
if [ -e $project ]; then | |
echo "object $project already exists" | |
return | |
fi | |
mkdir -p $project/src | |
cd $project | |
cat << EOL > src/index.html |