Skip to content

Instantly share code, notes, and snippets.

View andrewgeorgemitchell's full-sized avatar

Andrew Mitchell andrewgeorgemitchell

View GitHub Profile
@andrewgeorgemitchell
andrewgeorgemitchell / findLargestLevelOfTree.js
Created January 31, 2019 17:42
A small function to find the sum of levels on a tree and return the level with the largest sum.
const findLargestLevel = function(node) {
// Search Breadth First
// Define queue
let queue = [];
// Enqueue first
let depth = 0;
queue.push({node, depth});
// Track Depth Sums
let sumTracker = [];
while (queue.length > 0) {
@andrewgeorgemitchell
andrewgeorgemitchell / cashIntMath.js
Created February 7, 2019 17:47
A cash class which uses integer math to maintain precision in javascript.
class CashAmount{
constructor(cashDecimalValue) {
this.cashDecimalValue = cashDecimalValue;
this.totalInPennies = this.totalInPennies.bind(this);
this.addDoubleAmount = this.addDoubleAmount.bind(this);
this.toDouble = this.toDouble.bind(this);
this.toDoubleString = this.toDoubleString.bind(this);
this.quantityOfEachDenomination = this.quantityOfEachDenomination.bind(this);
// server.js
...
app.use('/api/products', productRoutes);
...
// controller/productRoutes.js
const express = require('express');
const Products = require('../models/products');
## MySQL Read Queries
-- SELECT * FROM Songs as s
-- WHERE id = 10000000;
~ .1 ms
## MySQL Queries for related songs
-- SELECT * FROM Songs as s
-- LEFT JOIN Song_to_songs as sts
config:
target: 'http://localhost:8081'
processor: "./generateGraphQuery.js"
phases:
- duration: 20
arrivalRate: 20
- duration: 5
arrivalRate: 50
- duration: 5
arrivalRate: 55
config:
target: 'http://localhost:8081'
processor: "./generateGraphQuery.js"
phases:
- duration: 20
arrivalRate: 20
- duration: 5
arrivalRate: 50
- duration: 5
arrivalRate: 55
~ 150 RPS for intial setup, no optimization
Artillery EC2 Bombardment Results:
Started phase 20, duration: 5s @ 22:26:42(+0000) 2019-03-14
Report @ 22:26:47(+0000) 2019-03-14
Elapsed time: 2 minutes, 0 seconds
Scenarios launched: 1425
Scenarios completed: 1422
Requests completed: 1422
~ 200 RPS for with intial load balancer setup
Started phase 28, duration: 5s @ 22:27:22(+0000) 2019-03-14
Report @ 22:27:27(+0000) 2019-03-14
Elapsed time: 2 minutes, 40 seconds
Scenarios launched: 1874
Scenarios completed: 1360
Requests completed: 1360
RPS sent: 187.69
Request latency:
const { Client } = require('pg');
const { pg } = require('../../config');
module.exports = {
getAll: async (table) => {
try {
const db = new Client(pg);
await db.connect();
const query = `SELECT * FROM ${table}`;
const results = await db.query(query);
@andrewgeorgemitchell
andrewgeorgemitchell / trpc-playground-fix.ts
Created February 27, 2024 05:25
trpc-playground fix for not resolving types in v11
/**
* << README >>
* Github Issue: https://github.com/sachinraja/trpc-playground/issues/55
*
* This file is a workaround for fixing issues with the schema generation for the trpc-playground package
* with the V11 tRPC release. This file fixes an issue where the typescript types for the router are not resolved correctly
*
* This is due to the fact that the trpc package made some breaking changes to the router type
* Issues this file fixes:
* - _def.query and _def.mutation are now replaced by a _def.type field which can be 'query' | 'mutation' | 'subscription'