ext install prettier-vscode
ext install prettier-standard-vscode
ext install vscode-standardjs
{
| const Hapi = require('hapi') | |
| const double = (input) => { | |
| return new Promise(resolve => { | |
| setTimeout(() => { | |
| return resolve(input+input) | |
| }, 500) | |
| }) | |
| } |
| const fetch = require('node-fetch') | |
| const delay = (ms) => { | |
| return new Promise(resolve => { | |
| setTimeout(() => { | |
| resolve() | |
| }, ms) | |
| }) | |
| } | |
| const retryFetch = (url, fetchOptions={}, retries=3, retryDelay=1000) => { |
| const register = async server => { | |
| server.route([ | |
| { | |
| path: '/moduleA/info', | |
| method: 'GET', | |
| handler: request => { | |
| return 'this is from moduleA/info' | |
| } | |
| } | |
| ]) |
| // handy function to strip the plusing part of a email address with + | |
| const stripPlusing = em => em.replace(/\+[^@]+/, '') | |
| console.log(stripPlusing('[email protected]')) | |
| console.log(stripPlusing('[email protected]')) | |
| console.log(stripPlusing('[email protected]')) | |
| /* | |
| [email protected] | |
| [email protected] |
| handler: (request, h) => { | |
| const captcha = svgCaptcha.create({ | |
| size: 5 | |
| }) | |
| return h.response(captcha.data).header('Content-Type', 'image/svg+xml') | |
| } |
| 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 |
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
| 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()) |
| 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) => { |