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
// Set a DEBUG environment var to "*" or "socket-logger" to enable | |
const log = require('debug')('socket-logger') | |
// Place this before other middlewares so it is invoked first - remember they invoke in the defined order | |
app.use(function (req, res, next) { | |
log('============================================================') | |
log(`received request from remote socket with req.headers - ${JSON.stringify(req.headers)}`) | |
log(`received request from remote socket with req.socket.address - ${JSON.stringify(req.socket.address())}`) | |
log(`received request from remote socket with req.socket.localAddress - ${req.socket.localAddress}`) |
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
'use strict'; | |
const mongo = require('rhmap-mongodb'); | |
// First remove anything that might be in the collection | |
mongo.collection('test').remove({}) | |
.then(() => { | |
const start = Date.now(); | |
return doTest(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
'use strict'; | |
const mongo = require('rhmap-mongodb'); | |
// First remove anything that might be in the collection | |
mongo.collection('test').remove({}) | |
.then(doTest); | |
function doTest () { |
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
'use strict'; | |
const Promise = require('bluebird'); | |
const fhc = Promise.promisifyAll(require('fh-fhc')); | |
const env = require('env-var'); | |
const log = require('fh-bunyan').getLogger(__filename); | |
const R = require('ramda'); | |
// fhc login and target vars. you can set these in bash using a command such as | |
// "export FHC_USER=user@acme.com", or by uncommenting the defaults below and |
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
// Assume our api does not want these fields returned (ideally we would strip from db query, but you get the idea) | |
var cleanseData = R.map(R.omit('dob', 'social-security', 'nickname', 'height', 'favourite-movie')); | |
const age = 25; | |
// Remove users below an age | |
var filterData = R.filter((u) => { return u.age >= age }); | |
function getUsersOlderThanAge (age) { | |
// We could add a catch here if we want to add more error data... |
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
'use strict'; | |
var Promise = require('bluebird') | |
, express = require('express'); | |
var app = express(); | |
function getUsers () { | |
return new Promise(function (resolve, reject) { | |
resolve(['jane', 'john']); |
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
Every second run is using async await, i.e 1 & 3 uses the callback server, and 2 & 4 use async await. | |
eshortis@eshortis-OSX:~/workspaces/personal/aysnc-await$ ab -n 10000 -c 250 -r http://127.0.0.1:3001/ | |
This is ApacheBench, Version 2.3 <$Revision: 1663405 $> | |
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ | |
Licensed to The Apache Software Foundation, http://www.apache.org/ | |
Benchmarking 127.0.0.1 (be patient) | |
Completed 1000 requests |
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
'use strict'; | |
var express = require('express') | |
, async = require('async'); | |
var app = express(); | |
function getAges (callback) { | |
callback(null, ['23', '43']); | |
} |
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
'use strict'; | |
var Promise = require('bluebird') | |
, express = require('express'); | |
var app = express(); | |
async function getUsers () { | |
return new Promise(function (resolve, reject) { | |
resolve(['jane', 'john']); |
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
for log in `fhc app logs list --app=irfeeciv4vf3uxwnlchbjwuj --env=tke-test --json\ | |
| \grep -i "std" | sed 's/.*"\(.*\)"[^"]*$/\1/'`; do \ | |
fhc app logs get --logname="$log" --app=irfeeciv4vf3uxwnlchbjwuj --env=tke-test --verbose; done > output.txt |