View sumToTarget.js
const sumToTarget = (arr, target) => {
if (!Array.isArray(arr) || arr.length < 2) { return []; } // Check for bad input
const results = [];
const hash = {};
for (var i = 0; i < arr.length; i += 1) {
const current = arr[i];
if (hash[current] === undefined) {
hash[target - current] = i;
View russianDolls.js
const russianDoll = (arr) => {
let max = 0;
for(let i = 0; i < arr.length; i +=1) {
let currMax = 0;
let curr = arr[i];
for(let j = 0; j < arr.length; j +=1) {
let comparitor = arr[j];
if(curr[0] < comparitor[0]) {
if(curr[1] < comparitor[1]) {
currMax +=1;
View cashinator.js
const Register = (products, cash, salesTax) => {
this.products = {}, this.cash = cash, this.salesTax = salesTax;
// parse comma separted price list
// attach product name as key in this.products
// value is an object with props
// sku : number,
// price : number,
// taxable: boolean
this.transactionLog = {};
// will contain objects of all previous transactions
View proxy-loadtest.js
Jakes-MacBook-Pro:images-service Kake$ loadtest -t 20 -c 10 --rps 200 http://ec2-54-183-221-120.us-west-1.compute.amazonaws.com/222
[Fri May 18 2018 19:35:23 GMT-0700 (PDT)] INFO Requests: 0, requests per second: 0, mean latency: 0 ms
[Fri May 18 2018 19:35:28 GMT-0700 (PDT)] INFO Requests: 831, requests per second: 166, mean latency: 31.3 ms
[Fri May 18 2018 19:35:33 GMT-0700 (PDT)] INFO Requests: 1752, requests per second: 184, mean latency: 33.2 ms
[Fri May 18 2018 19:35:38 GMT-0700 (PDT)] INFO Requests: 2673, requests per second: 184, mean latency: 43.9 ms
[Fri May 18 2018 19:35:43 GMT-0700 (PDT)] INFO
[Fri May 18 2018 19:35:43 GMT-0700 (PDT)] INFO Target URL: http://ec2-54-183-221-120.us-west-1.compute.amazonaws.com/222
[Fri May 18 2018 19:35:43 GMT-0700 (PDT)] INFO Max time (s): 20
[Fri May 18 2018 19:35:43 GMT-0700 (PDT)] INFO Concurrency level: 10
View seed.js
const { db, mongoose, Image, getNextSequenceValue, updateSequenceValue, Counters } = require('./index.js');
const faker = require('faker');
const imgUrl = 'https://s3-us-west-1.amazonaws.comhttps://gist.github.com/images-service-images/pic'; //pic<1-270>.jpg';
// Generates list of image urls for each listing
const randNumInRange = (min, max) => Math.floor(Math.random() * (max - min + 1) + min);
const randImageArray = () => {
let arr = [];
for (let j = 0; j < randNumInRange(2, 5); j += 1) {
arr.push(imgUrl + randNumInRange(1, 270) + '.jpg');
}
View proxyTest.js
Jakes-MacBook-Pro:images-service Kake$ loadtest http://localhost:8080/123 -t 30 -c 10 --rps 500
[Thu May 17 2018 14:36:51 GMT-0700 (PDT)] INFO Requests: 0, requests per second: 0, mean latency: 0 ms
[Thu May 17 2018 14:36:56 GMT-0700 (PDT)] INFO Requests: 2167, requests per second: 434, mean latency: 7.3 ms
[Thu May 17 2018 14:37:01 GMT-0700 (PDT)] INFO Requests: 4665, requests per second: 500, mean latency: 4.5 ms
[Thu May 17 2018 14:37:06 GMT-0700 (PDT)] INFO Requests: 7162, requests per second: 499, mean latency: 4.6 ms
[Thu May 17 2018 14:37:11 GMT-0700 (PDT)] INFO Requests: 9666, requests per second: 501, mean latency: 5.2 ms
[Thu May 17 2018 14:37:16 GMT-0700 (PDT)] INFO Requests: 12166, requests per second: 500, mean latency: 6.3 ms
[Thu May 17 2018 14:37:21 GMT-0700 (PDT)] INFO
[Thu May 17 2018 14:37:21 GMT-0700 (PDT)] INFO Target URL: http://localhost:8080/123
View lfuCache.js
var LFUCache = function(capacity) {
this.recent = [];
this.oldest = null;
this.capacity = capacity;
};
/**
* @param {number} key
* @return {number}
*/
View frequencySort.js
const frequencySort = (str) => {
let chars = {}, result = '', max = 0;
str.split('').forEach((ltr) => {
chars[ltr] ? chars[ltr]+=1 : chars[ltr] = 1;
});
return sort(chars);
};
const sort = (obj) => {
let chars = [], max = [0,0], result = '';
View gist:7255b6af4e61f4183bc22708ddb55b11
config:
target: 'http://127.0.0.1:3000'
phases:
- duration: 120
arrivalRate: 10
defaults:
headers:
x-my-service-auth: '987401838271002188298567'
processor: "./artilleryScript.js"
scenarios:
View messageBus.js
// busloads of messages
let messages = {};
let messageBus = {
publish: (topic, message) => {
if(messages[topic]) {
messages[topic].push(message);
} else {
messages[topic] = [message]
}