Skip to content

Instantly share code, notes, and snippets.

View dineshnagarit's full-sized avatar
🎯
Focusing

Dinesh Nagar dineshnagarit

🎯
Focusing
View GitHub Profile
@goldbergyoni
goldbergyoni / explicit-test.js
Created December 23, 2018 19:10
A test that one can read without leaving and visiting external code
it("When getting orders report, get the existing orders", () => {
//This one hopefully is telling a direct and explicit story
const orderWeJustAdded = ordersTestHelpers.addRandomNewOrder();
const queryObject = newQueryObject(config.DBInstanceURL, queryOptions.deep, useCache:false);
const result = queryObject.query(config.adminUserToken, reports.orders, pageSize:200);
expect(result).to.be.an('array').that.does.include(orderWeJustAdded);
})
@batrudinych
batrudinych / [parallel-promises]-take2.js
Created January 14, 2019 10:58
Running async operations in parallel and harvesting the results
async function take2() {
// Running Promises in parallel
const listOfPromises = listOfArguments.map(asyncOperation);
// Harvesting
return await Promise.all(listOfPromises);
}
@batrudinych
batrudinych / [parallel-promises]-take3-subtake1-part0.js
Created January 14, 2019 10:58
Running async operations in parallel. Concurrency limit applied correctly
async function take3subtake1part0() {
const concurrencyLimit = 5;
const argsCopy = listOfArguments.slice();
const promises = new Array(concurrencyLimit).fill(Promise.resolve());
// Recursively chain the next Promise to the currently executed Promise
function chainNext(p) {
if (argsCopy.length) {
const arg = argsCopy.shift();
return p.then(() => {
const operationPromise = asyncOperation(arg);
@Bilguun132
Bilguun132 / user.model.js
Last active October 22, 2019 05:08
nodejs-auth-Tutorial-usermodel
const config = require('config');
const jwt = require('jsonwebtoken');
const Joi = require('joi');
const mongoose = require('mongoose');
//simple schema
const UserSchema = new mongoose.Schema({
name: {
type: String,
required: true,
@faizahmedfarooqui
faizahmedfarooqui / remove-duplicate-transactions.js
Last active March 4, 2021 06:09
Remove transactions that has duplicate source, target, amount & category + the time difference between the transaction is less than 1 minute.
// Converts the time string into Date Object
const timestamp = _time => Date.parse(_time) / 1000;
/**
* 1. group-by given keys
* 2. sort the groups in ascending order for Time key
* 3. filters duplicate entries with time difference < 60 seconds
*
* @param _array Array [required]
* @param _function Function [required]