Skip to content

Instantly share code, notes, and snippets.

View evanshortiss's full-sized avatar
:octocat:
🇮🇪 🇺🇸

Evan Shortiss evanshortiss

:octocat:
🇮🇪 🇺🇸
View GitHub Profile
@evanshortiss
evanshortiss / socket-express-logger.js
Created October 25, 2017 00:32
Simple middleware to log information related to the underlying socket and proxies that forwarded the incoming request
// 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}`)
'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)
'use strict';
const mongo = require('rhmap-mongodb');
// First remove anything that might be in the collection
mongo.collection('test').remove({})
.then(doTest);
function doTest () {
@evanshortiss
evanshortiss / rhmap-service-rename.js
Created March 9, 2017 15:20
Rename the Cloud App of RHMAP Services so they show the correct name across all UI components
'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
// 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...
'use strict';
var Promise = require('bluebird')
, express = require('express');
var app = express();
function getUsers () {
return new Promise(function (resolve, reject) {
resolve(['jane', 'john']);
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
'use strict';
var express = require('express')
, async = require('async');
var app = express();
function getAges (callback) {
callback(null, ['23', '43']);
}
'use strict';
var Promise = require('bluebird')
, express = require('express');
var app = express();
async function getUsers () {
return new Promise(function (resolve, reject) {
resolve(['jane', 'john']);
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