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 / 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 / .port
Last active October 31, 2018 17:07
Port validation
{
"validPort" : ["256"],
"invalidPort" : [],
"minPort" : "1000",
"maxPort" : "1200"
}
// IPv4
var regexStringIPv4 = '^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$';
var regexIPv4 = new RegExp(regexStringIPv4, flags);
console.log(regexIPv4.test("192.168.0.25.25.23")); // false
console.log(regexIPv4.test("192.168.0.25")); // true
@jastisriradheshyam
jastisriradheshyam / uploadAJAX.js
Created October 16, 2018 13:23
Document in upload
var someFunctionToUse = function (obj) {
// Form data
var formData = new FormData();
// Appending the files data in form data
formData.append("doc_file", document.getElementById("upload_input_id").files[0]);
// (Example) attribute from an object
formData.append("data_filed_name", obj.getAttribute("object_attribute_name"));
// Creating the Request object
var oReq = new XMLHttpRequest();
// Creating event
@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 / 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 / Caps_conversion.js
Last active July 3, 2018 13:04
Java Script Tricks
function ucFirstAllWords( str )
{
var pieces = str.split(" ");
for ( var i = 0; i < pieces.length; i++ )
{
var j = pieces[i][0].toUpperCase();
pieces[i] = j + pieces[i].substr(1).toLowerCase();
}
return pieces.join(" ");
}
@jastisriradheshyam
jastisriradheshyam / go_interface_json_unmarsall.go
Last active June 25, 2018 07:50
This is to get the unknown data (from json) and parse in go program for further opertions
package main
// Importing libraries
import (
"encoding/json"
"fmt"
)
func main() {
// Sample JSON string
@jastisriradheshyam
jastisriradheshyam / caller_name.go
Last active June 11, 2018 04:57
outputs the function name.
// Copyright 2018 Jasti Sri Radhe Shyam
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in
//Referesh automatially
<script type="text/javascript">
setTimeout(function(){
location = ''
},60000)
</script>
//Hard Refersh
location.reload(true);