Skip to content

Instantly share code, notes, and snippets.

View jastisriradheshyam's full-sized avatar
🪀
((~~~))

Jasti Sri Radhe Shyam jastisriradheshyam

🪀
((~~~))
View GitHub Profile
@jastisriradheshyam
jastisriradheshyam / time_format.js
Created August 31, 2018 07:54
A Time Format function
// Gives the current Date Time in this format --> ddmmyyyy hh:mm:ss
var getLCurrentDateFormated = function () {
let date_now = new Date();
return date_now.toLocaleString('en-IN', { day: "2-digit", month: "2-digit", year: "numeric", hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false, timeZone: 'Asia/Kolkata' }).replace(/[\/\,]/g, "");
}
@jastisriradheshyam
jastisriradheshyam / git.md
Last active February 12, 2019 14:18
Git commands and info

git branch
git clone repo_location
git pull origin branch_name
git push origin branch_name
git commit -S[GPG key]
git merge brach_to_merge --no-commit --no-ff
git status
git stash
git stash apply

@jastisriradheshyam
jastisriradheshyam / dateDiff.js
Created October 31, 2018 12:07
date difference js
// Reference - https://www.w3resource.com/javascript-exercises/javascript-date-exercise-8.php
var date_diff_inseconds = function (date1, date2) {
let dt1 = new Date(date1);
let dt2 = new Date(date2);
return Math.floor((Date.UTC(dt2.getFullYear(), dt2.getMonth(), dt2.getDate(), dt2.getHours(), dt2.getMinutes(), dt2.getSeconds()) - Date.UTC(dt1.getFullYear(), dt1.getMonth(), dt1.getDate(), dt1.getHours(), dt1.getMinutes(), dt1.getSeconds())) / (1000));
};
var date_diff_inminutes = function (date1, date2) {
let dt1 = new Date(date1);
let dt2 = new Date(date2);
@jastisriradheshyam
jastisriradheshyam / response.js
Created August 19, 2019 21:02
Error handling Javascript
// response for error handling
let response = {
success: Boolean,
errorType: Number, // 1 - Programmer or config, 2 - Operational
responseCode: String,
message: String
};
@jastisriradheshyam
jastisriradheshyam / error_to_string.js
Last active April 14, 2020 11:17
Node JS, full error object to string
// node.js error object to string
const util = require('util')
var fullErrorObjectString = "";
try {
k++
} catch (error) {
console.log(util.inspect(error, false, null, false /* enable colors */))
fullErrorObjectString = util.inspect(error, false, null, false /* enable colors */).toString()
}
@jastisriradheshyam
jastisriradheshyam / cwd_change_nodejs.js
Created April 17, 2020 20:59
Change nodejs process current working directory
const path = require('path');
// here after the dirname just make it to the root path of your choice
// all the path.resolve() will resolve from the process current directrory
// and chdir change that directory
const val = path.resolve(path.dirname(require.main.filename)+"/../..")
process.chdir(val);
/*
use case:
@jastisriradheshyam
jastisriradheshyam / Time_Measure.js
Last active August 13, 2020 16:27
Time Measure of the code inside the node js (only use for benchmarking)
// Node.js Time measure for benchmarking
// Way One : in microseconds
var hrTime1 = process.hrtime();
// code
var hrTime1 = process.hrtime();
startP = hrTime[0] * 1000000 + hrTime[1] / 1000;
endP = hrTime1[0] * 1000000 + hrTime1[1] / 1000;
// Shows the time difference in micro second
console.log(endP - startP);
@jastisriradheshyam
jastisriradheshyam / allSettled.js
Created September 7, 2020 08:02
allSettled polyfill
Promise.allSettled = function (promises) {
const mappedPromises = promises.map(promise => (
promise
.then(value => ({ status: 'fulfilled', value }))
.catch(reason => ({ status: 'rejected', reason }))
));
return Promise.all(mappedPromises);
};
@jastisriradheshyam
jastisriradheshyam / pm2.md
Last active September 14, 2020 09:09
PM2 Start for NPM start script based projects

pm2 start --name "dev react" --time npm -- start

@jastisriradheshyam
jastisriradheshyam / synchronous_sleep.js
Last active October 1, 2020 11:10
Its a synchronous sleep function.
/*
Usage:
-------------------------------------------------
var syn_timeout = require('synchronous_timeout');
//some code
await syn_timeout.pause(300);
//some code
-------------------------------------------------
if defined and used in a same file:
-------------------------------------------------