Skip to content

Instantly share code, notes, and snippets.

View abhi5658's full-sized avatar
:shipit:
Go watch something else. This is not Facebook!

Abhishek Shah abhi5658

:shipit:
Go watch something else. This is not Facebook!
  • Postman | Airmeet | Simform
  • Bengaluru
View GitHub Profile
@abhi5658
abhi5658 / lru_cache.js
Last active February 15, 2024 21:39
Implemeting LRU cache in Javascript via set and map and time complexity O(n x m) (entries x memory size) but m is constant hence complexity is O(n)
let pages = [7, 0, 1, 2, 0, 3, 0, 4, 2, 3, 0, 3, 2];
let memorySize = 4;
function lruCache1() {
let memory = new Set();
let recentUsedPageIndex = new Map();
let pageFault = 0;
for (let i = 0; i < pages.length; i++) {
const currentPage = pages[i];
@abhi5658
abhi5658 / test_node_process_memory_usage.js
Created November 4, 2020 18:25
The setup helps to monitor memory used by node process to execute a function
const myFunction = async (args) => {
// do something in this function whose memory you want to monitor
return 0;
}
function sleep(ms) {
return new Promise((resolve) => {
console.log(`***\n***\nsleeping for ${ms / 1000} seconds`)
setTimeout(resolve, ms);
});
@abhi5658
abhi5658 / afterTokenApiCall.js
Created August 24, 2020 07:44
Retry Refresh Token Pattern with Node Promises and Salesforce
import { httpGet } from '../util/http';
import { getAccessToken, expireToken } from './salesforceOAuth';
import { retryOnce } from '../util/retry';
import logger from '../logger';
/**
* API call to get data
* wrapped into retryOnce() util function with fallback unauthorised function
* -- wrapped into getAccessToken() function
*/