Skip to content

Instantly share code, notes, and snippets.

@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");
}
@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 / 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 / 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 / CartPoleDataPreperation.py
Last active January 9, 2019 20:10
For preparing data of CartPole game which we need to use for our deep learning model training.
def model_data_preparation():
training_data = []
accepted_scores = []
for game_index in range(intial_games):
score = 0
game_memory = []
previous_observation = []
for step_index in range(goal_steps):
action = random.randrange(0, 2)
observation, reward, done, info = env.step(action)
@tankala
tankala / CartPoleGamePlayWithDeepLearning.py
Last active October 19, 2018 12:51
With deep learning model playing CartPole game
scores = []
choices = []
for each_game in range(100):
score = 0
prev_obs = []
for step_index in range(goal_steps):
env.render()
if len(prev_obs)==0:
action = random.randrange(0,2)
else:
@tankala
tankala / MountainCarDataPreperation.py
Last active October 19, 2018 16:47
For preparing data of MountainCar game which we need to use for our deep learning model training.
def model_data_preparation():
training_data = []
accepted_scores = []
for game_index in range(intial_games):
score = 0
game_memory = []
previous_observation = []
for step_index in range(goal_steps):
action = random.randrange(0, 3)
observation, reward, done, info = env.step(action)
@tankala
tankala / animalSoundsFeeder.js
Created January 9, 2019 07:22
Node.js Example for Redis Hashes
const readline = require('readline');
const redisClient = require('redis').createClient();
const userInteractor = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var initiateUserInteraction = async function() {
while(true) {
@tankala
tankala / asyncQueueExample.js
Created February 11, 2019 07:35
Async Queue Example
const async = require('async');
var processQueue = function (message, callback) {
setTimeout(function() {
console.log(`Task ${message} completed`);
callback();
}, 500);
}
var queue = async.queue(processQueue, 3);
@tankala
tankala / asyncQueueExample.js
Last active February 11, 2019 07:40
Async Queue Example
const async = require('async');
//Code for processing the task
var processQueue = function (message, callback) {
setTimeout(function() {
console.log(`Task ${message} completed`);
callback();
}, 500);
}