Skip to content

Instantly share code, notes, and snippets.

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

Evan Shortiss evanshortiss

:octocat:
🇮🇪 🇺🇸
View GitHub Profile
'use strict';
var Promise = require('bluebird')
, express = require('express');
var app = express();
function getUsers () {
return new Promise(function (resolve, reject) {
resolve(['jane', 'john']);
// 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...
@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
'use strict';
const mongo = require('rhmap-mongodb');
// First remove anything that might be in the collection
mongo.collection('test').remove({})
.then(doTest);
function doTest () {
'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)
@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}`)
@evanshortiss
evanshortiss / rhmap-service-ip-filter-application.js
Last active October 25, 2017 22:19
A sample application.js file that uses the IP Filter from my previous Gist
'use strict'
const express = require('express')
const cors = require('cors')
const app = express()
// Enable CORS for all requests
app.use(cors())
@evanshortiss
evanshortiss / rhmap-ip-filter.js
Last active October 25, 2017 18:44
An express middleware function that ensures requests are coming from the IP addresses defined in IP_ALLOWED_ADDRESSES
'use strict'
// Ensure you run "npm install env-var@3 --save"
const env = require('env-var')
// Used to bypass check when running locally
const isLocal = env.get('FH_USE_LOCAL_DB').asBool()
// Valid mbaas IP(s) that can be in the "x-forwarded-for" header
// This must be set or app will not start (required() call) and must be comma separated
@evanshortiss
evanshortiss / sample-list-handler.js
Created November 2, 2017 18:20
Example of a custom list handler for use with FeedHenry Node.js Data Sync
const sync = require('fh-mbaas-api').sync
const workorders = require('lib/sql/workorders')
// Typical init code etc...
// Example of getting work orders for a specific user
sync.handleList('workorders', function(datasetId, query, metadata, done) {
// Getting by the userId passed to the sync framework and the region they are in
workorders.getDataForUserInRegion(query.userId, query.region, (err, specificUserWorkOrders) => {
if (err) {
@evanshortiss
evanshortiss / index.html
Created February 20, 2018 22:09
Contains a reference index.html for the Red Hat & RapID blogpost
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>Hello World</title>
<link rel="stylesheet" href="css/app.css">
</head>
<body>