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 / 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:
-------------------------------------------------
@jastisriradheshyam
jastisriradheshyam / marbles_all_names.go
Created April 17, 2018 09:43
Get all the objects (marble) names in the ledger
//Shows all the marbles or objects in the ledger (blockchain)
//This is a marbles chaincode (hyperledger fabric samples) related code.
// Jasti Sri Radhe Shyam
func (t *SimpleChaincode) getMarblesByRangeAll(stub shim.ChaincodeStubInterface) pb.Response {
//Gets all the data with undefined range
resultsIterator, err := stub.GetStateByRange("", "")
if err != nil {
return shim.Error(err.Error())
}
@jastisriradheshyam
jastisriradheshyam / couchdb_index_format_example.json
Created April 17, 2018 12:22
Couch DB index creation example.
{
"index": {
"fields": ["name"]
},
"ddoc": "index@1.0.0",
"name": "name-index",
"type": "json"
}
//Referesh automatially
<script type="text/javascript">
setTimeout(function(){
location = ''
},60000)
</script>
//Hard Refersh
location.reload(true);
@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
@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 / 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 / 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 / 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 / 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