Posts

Showing posts from June, 2017

Install mysql in Zip format

Run mysql zip file in windows 1. First create the my.ini 2. Add the paths in myini file    [mysqld] # set basedir to your installation path basedir=E:\\mysql # set datadir to the location of your data directory datadir=E:\\mydata\\data 3. Run mysqld    It will find defaultly my.ini file.    mysqld   --initialize or --initialize-insecure      After completes it created some files in data folder 4. Run sql server    mysqld  --console    mysql -u root  //Default user root https://dev.mysql.com/doc/refman/5.7/en/windows-create-option-file.html Reset the password 1. Create file mysql-ini.txt and add these 2. Add contents  mysql-ini.txt   ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';   SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass'); based on versions Run command mysqld --init-file=D:\\docs\\databases\\sql\\mysql-5.7.10-winx64\\mysql-5.7.10-wi...

Bind , call, callback wrap in JS

var fs = require('fs'); /**  * Going to wrap the fs.readFile method to do this  */ //Make copy of the fs.readFile method var Original = fs.readFile; /**  Wrap the fs.read file, we can use two function one is apply and other is call  */  APPLY fs.readFile = function(){         var startTime = process.hrtime();     console.log('file read method started')     //In apply method pass the arguments as a array of values     var result =  Original.apply(this, arguments);     var endTime =  process.hrtime(startTime)     console.log(endTime)     console.log('file read method ended, total read time =>' + endTime)     return result; } CALL fs.readFile = function(){         var startTime = process.hrtime();     console.log('file read method started using call')  //function.call(thisArg, arg1, arg2, ...) ...

Two return statements in javascript

function test() {     try {         return 'mongo';     } catch (e) {         console.log('error', e)         return 'redis'     } finally {         console.log('finally it returns value as elastic not mongo');         return 'elastic';     } }

Sample data for JSON databases

For sample data for the json databases Movies data { "create": { "_index": "movies", "_type": "movie", "_id": "tt0468569" }} {"title":"The Dark Knight","year":2008,"rated":["PG-13"],"released":"2008-07-18","runtimeMinutes":152,"genres":["Action","Crime","Drama"],"directors":["Christopher Nolan"],"writers":["Jonathan Nolan","Christopher Nolan","David S. Goyer","Bob Kane"],"actors":["Christian Bale","Heath Ledger","Aaron Eckhart","Michael Caine"],"plot":"When Batman, Gordon and Harvey Dent launch an assault on the mob, they let the clown out of the box, the Joker, bent on turning Gotham on itself and bringing any heroes down to his level.","languages...

Javascript tutorials

Today I learned few things in javascript  check for null, undefined, or blank variables in JavaScript? if ( value ) { } will evaluate to  true  if  value  is not: null undefined NaN empty string ("") 0 false !! operator in node js This converts a value to a boolean and  ensures a boolean type . "foo" = "foo" ! "foo" = false !! "foo" = true Truth Table for javascript '' == '0' // false 0 == '' // true 0 == '0' // true false == 'false' // false false == '0' // true false == undefined // false false == null // false null == undefined // true " \t\r\n" == 0 // true NaN === NaN //false !! NaN === !! NaN //true

Thread local in java

Thread Local The ThreadLocal class in Java enables you to create variables that can only be read and written by the same thread. Thus, even if two threads are executing the same code, and the code has a reference to aThreadLocal variable, then the two threads cannot see each other's ThreadLocal variables. public class Threadlocal {     public static class MyRunnable implements Runnable {         private int id;         public MyRunnable(int id) {             // TODO Auto-generated constructor stub             this.id = id;         }         private ThreadLocal threadLocal = new ThreadLocal ();         @Override         public void run() {             threadLocal.set(id);             try { ...

Node js tutorials

Today I learned Total response time To calculate the overall response time of the method we basically use new Date() function but in these functions we cannot able to find the exact time.   if we use the process.hrtime() function we can find the difference accurately till nano seconds Process.hrtime() const NS_PER_SEC = 1e9 ; const time = process . hrtime (); // [ 1800216, 25 ] setTimeout (() => { const diff = process . hrtime ( time ); // [ 1, 552 ] console . log ( `Benchmark took $ { diff [ 0 ] * NS_PER_SEC + diff [ 1 ] } nanoseconds` ); // benchmark took 1000000552 nanoseconds } , 1000 ); ref :  https://nodejs.org/api/process.html#process_process_hrtime_time HTTP & HTTPS request in nodejs There are two modules in nodejs to send the request http, https (for secure request) There is another module called url  in  nodejs  its used for parse, Create request object, find path , resolve path ...

Useful links for javascript and nodejs

Image
To understand the event loop Node.js is a single-threaded application, but it can support concurrency via the concept of  event  and  callbacks . Every API of Node.js is asynchronous and being single-threaded, they use  async function calls  to maintain concurrency. Node uses observer pattern. Node thread keeps an event loop and whenever a task gets completed, it fires the corresponding event which signals the event-listener function to execute. To understand the basics of the event loop please refers these links which are very useful for to under stand the event loop deeply. https://developer.mozilla.org/en/docs/Web/JavaScript/EventLoop https://vimeo.com/96425312 https://www.codementor.io/simenli/demystifying-asynchronous-programming-part-1-node-js-event-loop-7r503akaj https://github.com/nodejs/node/blob/v4.x/doc/topics/the-event-loop-timers-and-nexttick.md#phases-in-detail https://www.dynatrace.com/blog/how-to-track-dow...