Posts

Showing posts from July, 2017

compare password and sensitive data's in nodejs

previously I did like this to compare the sensitive data's function validatePassword(fromDbPassword, inputPassword){          if( fromDbPassword === inputPassword) return true;           return false; } There is an attack security attack called timing attack . Hackers try to crack the encryption algorithm using the way.  So How to compare password hackers cant use the timing attack V8,  JavaScript engine used by Node.js, tries to optimize the code you run from a performance point of view. It starts comparing the strings character by character, and once a mismatch is found, it stops the comparison operation. So the longer the attacker has right from the password, the more time it takes. function checkApiKey (apiKeyFromDb, apiKeyReceived) {  return cryptiles.fixedTimeComparison(apiKeyFromDb, apiKeyReceived)  } To solve this issue, you can use the npm module c...

Docker tutorials

Docker  Pull the image sudo docker pull ubuntu sudo docker run ubuntu apt-get install -y ping Then get the container id using this command: sudo docker ps -l Commit changes to the container: sudo docker commit   iman/ping  Expose the port  docker run -p 9200:9200 elasticsearch  Then run the container: sudo docker run iman/ping ping  www.google.com Ref https://stackoverflow.com/questions/19585028/i-lose-my-data-when-the-container-exits https://runnable.com/docker/binding-docker-ports

Responsive ui

To create responsive ui Following steps To set view port Html 5 tag This one sets width is device width size use media queries in css3 @media only screen and (max-width: 768px) {     /* For mobile phones: */      .header{        width : 200px;      } } Mobile orientaion view : Potrait / Landscape @media only screen and (orientation: landscape) {     body {         background-color: lightblue;     } }

Wrap external http request in node js

Wrap external http request in node js var http = require('http'); var url = require('url').URL; var shimmer = require('shimmer') var api = {} api.wrapEmitter = require('emitter-listener') var Origional = http.get; shimmer.wrap(http, 'get', function getWrap(get) {     return makeRequestTrace(get); }) function makeRequestTrace(request) {     return function trace(options, callback) {         var req = request.call(this, options, function (res) {             console.log('Response===================' , res)             shimmer.wrap(res, 'on', function onWrap(on) {                 return function on_trace(eventName, cb) {                     if (eventName === 'data') {                         on.call(this, 'data', func...

one way binding vs two way binding

Image
React is one way binding (Uni directional) and its used for View layer Angular is  two way binding and follows MVC pattern One-way binding (React) When properties in the model get updated, so does the UI. Only one watcher exist Virtual dom https: //www.codecademy.com/articles/react-virtual-dom http://reactkungfu.com/2015/10/the-difference-between-virtual-dom-and-dom/ Two-way binding (Angular js) When properties in the model get updated, so does the UI. When UI elements get updated, the changes get propagated back to the model. When angular sets up databinding two "watchers" exist

Application monitoring tool essentials and links

basic APM tool should monitor 1. Down time of the applications 2. Capture  the slow responses 3. Compare the response time metrics for before commit  vs after commit  4. Show distributed transactions (Call trace) 5. Alerting the security issues (Ex: If external library has the security issue then it should indicate the alert )  Good Nodejs  APM  tools https://www.appdynamics.com/ https://newrelic.com/ https://www.dynatrace.com/ https://opbeat.com/ https://www.instana.com/ https://traceview.solarwinds.com/ https://risingstack.com/

__proto__ vs prototype

The  __proto__  property of  Object.prototype  is an accessor property (a getter function and a setter function) that exposes the internal  [[Prototype]]  (either an object or  null ) of the object through which it is accessed. __proto__  is the actual object that is used in the lookup chain to resolve methods, etc.  prototype  is the object that is used to build  __proto__  when you create an object with  new : _proto_ var parent = {   color : 'white' } var child = {} child  = Object.create(parent) child.color //White parent.color = 'black' child.color  // 'black' because of _proto_ chain Prototype function   Soldier ( )   { } Soldier . prototype  =   {   weapons :   [ 'rifle' ,   'grenade' ,   'bayonet' ] ,   weaponOfChoice :   'rifle' } ; var  GIJoe  =   new   Soldier ( ) ; var  Ram...

Inheritance in nodejs

To inherit the properties we can use util.inherits method var util  = require('util') util.inherits(child, parent) /**  * Inherit the prototype methods from one constructor into another.  *  * The Function.prototype.inherits from lang.js rewritten as a standalone  * function (not on Function.prototype). NOTE: If this file is to be loaded  * during bootstrapping this function needs to be rewritten using some native  * functions as prototype setup using normal JavaScript does not work as  * expected during bootstrapping (see mirror.js in r114903).  *  * @param {function} ctor Constructor function which needs to inherit the  * prototype.  * @param {function} superCtor Constructor function to inherit prototype from.  */ exports.inherits = function(ctor, superCtor) {     ctor.super_ = superCtor;     ctor.prototype = Object.create(superCtor.prototype, {         const...