Skip to content

Instantly share code, notes, and snippets.

View svsh227's full-sized avatar

SHUBHAM VERMA svsh227

  • * Capgemini India * Srijan Technologies, Gurugram * Daffodil Software Ltd, Gurgaon
  • Gurugram, India
View GitHub Profile
var express = require('express');
var graphqlHTTP = require('express-graphql');
var { buildSchema } = require('graphql');
// Construct a schema, using GraphQL schema language
var schema = buildSchema(`
type Query {
rollDice(numDice: Int!, numSides: Int): [Int]
}
`);
@svsh227
svsh227 / package.json
Last active December 27, 2019 05:09
Create a Flame Graph for your node app | Profiling nodeJS app
//package.json
{
"name": "flame-graph-exercise",
"version": "1.0.0",
"private": true,
"scripts": {
"start": "node --perf-basic-prof-only-functions app.js"
},
"author": "Shubham Verma",\
"dependencies": {
@svsh227
svsh227 / app.js
Last active December 27, 2019 05:08
Create a Flame Graph for your node app | Profiling nodeJS app
//app.js
const express = require('express');
const console = require('console');
const levenshtein = require('fast-levenshtein');
var arr=[];
const HOW_OBVIOUS_THE_FLAME_GRAPH_SHOULD_BE_ON_SCALE_1_TO_100 = 10;
const someFakeModule = (function someFakeModule () {
return {
calculateStringDistance (a, b) {
@svsh227
svsh227 / makeIndex.js
Created December 27, 2019 05:12
Integrate Elasticsearch With Node.js
//makeIndex.js
const _ = require('highland');
const fs = require('fs');
const csv = require('csv-parser');
const elasticsearch = require('elasticsearch');
const indexName = 'demo_elastic_index';
const start = async () => {
const client = new elasticsearch.Client({
host: 'localhost:9200',
@svsh227
svsh227 / searchData.js
Created December 27, 2019 05:15
Integrate Elasticsearch With Node.js
//searchData.js
const elasticsearch = require('elasticsearch');
const indexName = 'demo_elastic_index';
const query = 'Lewisham';
const searchData = async () => {
const client = new elasticsearch.Client({
host: 'localhost:9200',
// log: 'trace',
});
await client.ping({
@svsh227
svsh227 / deleteIndex.js
Created December 27, 2019 05:16
Integrate Elasticsearch With Node.js
//deleteIndex.js
const elasticsearch = require('elasticsearch');
const indexName='demo_elastic_index';
const deleteIndex = async () => {
const client = new elasticsearch.Client({
host: 'localhost:9200',
// log: 'trace',
});
await client.ping({
requestTimeout: 3000
@svsh227
svsh227 / query.js
Created December 27, 2019 05:17
ntegrate Elasticsearch With Node.js
{
"query": { //1
"bool": { //2
"must": [
{ "match":{"address":"Street"}} //3
],
"filter": [ //4
{ "term":{"gender":"f"}}, //5
{ "range": { "age": { "gte": 25 }}} //6
]
@svsh227
svsh227 / package.json
Created December 28, 2019 18:15
Blockchain with NodeJS
//package.json:
{
"name": "blockchain",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Shubham Verma",
@svsh227
svsh227 / main.js
Last active December 28, 2019 18:37
Blockchain with NodeJS
//main.js
const crypto = require('crypto');
class Block {
constructor(index, data, prevHash) {
this.index = index;
this.timestamp = Math.floor(Date.now() / 1000);
this.data = data;
this.prevHash = prevHash;
this.hash=this.getHash();
}
@svsh227
svsh227 / sample.json
Last active January 16, 2020 05:39
Write JSON Data Into an XLSX/Excel File in JavaScript
//sample.json
[{
"firstName":"Shubham",
"lastName":"Verma",
"email":"example@gmail.com",
"Mob:":1234567890,
"country":"India"
},
{
"firstName":"Shubham",