Skip to content

Instantly share code, notes, and snippets.

@tankala
tankala / CartPoleGameUnderstanding.py
Last active October 19, 2018 11:26
First time we want to understand exactly what happens with CartPole game this code snippet will help you
import gym
env = gym.make('CartPole-v1')
env.reset()
for step_index in range(1000):
env.render()
action = env.action_space.sample()
observation, reward, done, info = env.step(action)
print("Step {}:".format(step_index))
print("action: {}".format(action))
print("observation: {}".format(observation))
@tankala
tankala / printDataBetweenTokenRangeOfCassandrTable.js
Created September 8, 2018 15:13
Finding minimum and maximum token range in a Cassandra table and Printing data between certain range.
const cassandra = require('cassandra-driver');
const client = new cassandra.Client({contactPoints: ['127.0.0.1'], keyspace: 'movie_lens'});
const bignum = require('bignum');
//Finding minimum and maximum token range in a Cassandra table
client.execute('select MIN(token(movie_id)), MAX(token(movie_id)) from movies;',
function(err, result) {
let minToken = result.rows[0]['system.min(system.token(movie_id))'];
let maxToken = result.rows[0]['system.max(system.token(movie_id))'];
console.log("Minimum token: " + minToken);
@tankala
tankala / UpdateAddressOfAUser.js
Created August 5, 2018 15:24
Updating user address with the passing a variable to callback function concept using bind()
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "root",
database: "Employee"
});
con.connect(function (err) {
@tankala
tankala / PassAVariableToCallbackFunction.js
Created August 5, 2018 15:12
How to pass a Variable or Argument to a callback function in Node.js
var mainFunction = function(callback) {
//Did something
console.log("In Main Function");
callback();
}
var callbackFunction = function() {
console.log('Variable: ' + this.variable);
console.log("In Callback Function");
}
var mysql = require('mysql');
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "root",
database: "Employee"
});
con.connect(function (err) {
@tankala
tankala / correctWordWizard.js
Created July 28, 2018 13:18
Word Wizard code for calculating words count and sorting in Desc
const stopWordsSet = new Set(["a", "about", "above", "after", "again", "against", "all", "am", "an", "and", "any", "are", "as", "at", "be", "because", "been", "before", "being", "below", "between", "both", "but", "by", "could", "did", "do", "does", "doing", "down", "during", "each", "few", "for", "from", "further", "had", "has", "have", "having", "he", "he'd", "he'll", "he's", "her", "here", "here's", "hers", "herself", "him", "himself", "his", "how", "how's", "i", "i'd", "i'll", "i'm", "i've", "if", "in", "into", "is", "it", "it's", "its", "itself", "let's", "me", "more", "most", "my", "myself", "nor", "of", "on", "once", "only", "or", "other", "ought", "our", "ours", "ourselves", "out", "over", "own", "same", "she", "she'd", "she'll", "she's", "should", "so", "some", "such", "than", "that", "that's", "the", "their", "theirs", "them", "themselves", "then", "there", "there's", "these", "they", "they'd", "they'll", "they're", "they've", "this", "those", "through", "to", "too", "under", "until", "up", "very", "
@tankala
tankala / cpuProfiling.js
Created July 28, 2018 12:30
CPU profiling using v8-profiler
app.get('/doCPUProfiling/profileId/:profileId/durationInSec/:durationInSec', function (req, res) {
let profileId = req.params['profileId'];
let durationInMilliSec = req.params['durationInSec'] * 1000;
// Start profiling
profiler.startProfiling(profileId);
setTimeout(function () {
stopProfiling(profileId);
}, durationInMilliSec);
res.json({});
});
@tankala
tankala / wordWizard.js
Created July 28, 2018 12:10
Word Wizard for calculating words count with business logic flaw
const stopWords = ["a", "about", "above", "after", "again", "against", "all", "am", "an", "and", "any", "are", "as", "at", "be", "because", "been", "before", "being", "below", "between", "both", "but", "by", "could", "did", "do", "does", "doing", "down", "during", "each", "few", "for", "from", "further", "had", "has", "have", "having", "he", "he'd", "he'll", "he's", "her", "here", "here's", "hers", "herself", "him", "himself", "his", "how", "how's", "i", "i'd", "i'll", "i'm", "i've", "if", "in", "into", "is", "it", "it's", "its", "itself", "let's", "me", "more", "most", "my", "myself", "nor", "of", "on", "once", "only", "or", "other", "ought", "our", "ours", "ourselves", "out", "over", "own", "same", "she", "she'd", "she'll", "she's", "should", "so", "some", "such", "than", "that", "that's", "the", "their", "theirs", "them", "themselves", "then", "there", "there's", "these", "they", "they'd", "they'll", "they're", "they've", "this", "those", "through", "to", "too", "under", "until", "up", "very", "was", "we",
@tankala
tankala / controller.js
Created July 28, 2018 12:07
Controller
const wordWizard = require('./wordWizard')
exports.getWordsCountInDesc = function (req, res) {
let callBack = function (err, response) {
if (err) {
res.json({});
} else {
res.json(response);
}
}
@tankala
tankala / app.js
Created July 28, 2018 12:04
Profiling Node.js application using v8-profiler
// Imports
var express = require('express');
const bodyParser = require('body-parser');
const morgan = require('morgan');
const app = express();
const controller = require('./controller');
const profiler = require('v8-profiler');
const fs = require('fs');
// Middlewares