Skip to content

Instantly share code, notes, and snippets.

View gramcha's full-sized avatar

Ganeshkumar Ramachandran gramcha

View GitHub Profile
@gramcha
gramcha / chrome-selenium-test.js
Created April 6, 2022 06:59
up chrome browser and go to a site
const chrome = require('selenium-webdriver/chrome');
const chromedriver = require('chromedriver');
const {
By,
until,
Builder,
} = require('selenium-webdriver');
const driver = new Builder().forBrowser('chrome')
@gramcha
gramcha / redis-distributed-lock.js
Last active April 12, 2022 14:32
redis - node-redlock - poc
/* global logger */
const ioredis = require('ioredis');
const { default: Redlock, ResourceLockedError } = require("redlock");
if (!global.logger) {
global.logger = console;
}
class DistributedLockService {
static getIORedisInstance(redisConfig) {
@gramcha
gramcha / sob.js
Last active April 8, 2022 05:15
share of business
function getShareMetaData() {
return {
t1: {
percentage: 30,
},
t2: {
percentage: 50,
},
t3: {
percentage: 20,
@gramcha
gramcha / having-multiple-jdk-macos.md
Created November 28, 2020 14:34
Managing multiple Java versions in MacOS

Installing different versions of open jdk through Homebrew(assuming already installed) and already having Java 8.

We need to install a tool called jenv - Java version manager which is similar to nvm(nodeJs version manager).

brew install jenv

Export the jenv path to .bash_profile or .zshrc - whatever you are using. I am using .zshrc

const Joi = require('@hapi/joi');
const objectMapping = {
quantity: Joi.number().min(0.00000000001).required(),
};
const materialInvoiceSchema = Joi.object()
.keys(objectMapping).unknown(true);
const materialObject = { quantity: 1.000 };
const { error, value } = Joi.validate(materialObject, materialInvoiceSchema,
{ convert: true });
@gramcha
gramcha / get-month-wise-interval-dates-from-a-date-range
Last active April 21, 2020 10:19
getMonthWiseIntervalDatesFromADateRange
const moment = require('moment');
function getMonthWiseIntervalDatesFromADateRange(startDateString, endDateString) {
let startMoment = moment(startDateString);
const endMoment = moment(endDateString);
const monthDiff = endMoment.diff(startMoment, 'months');
console.log(monthDiff);
const pairsOfDates = [];
if (monthDiff === 0) {
const result = { startDate: startMoment, endDate: moment(endMoment) };
@gramcha
gramcha / add_git_submodule.sh
Created October 25, 2018 11:22
How do I add GIT submodule?
git submodule add https://github.com/<user>/reponame
#in case of older versions of git
git submodule update --init --recursive
@gramcha
gramcha / remove_git_submodule.sh
Created October 25, 2018 11:18
How do I remove a GIT submodule?
#lets assume git sub module name is 'eureka-client-service'
#required git version >= 1.8.5.2
git rm eureka-client-service
rm -rf .git/modules/eureka-client-service
git config -f .git/config --remove-section submodule.eureka-client-service 2> /dev/null