Posts

Showing posts from April, 2016

Fibonacci number using NodeJS

'use strict';
const readline  = require('readline'); const rl = readline.createInterface({   input: process.stdin,   output: process.stdout });
//get fibonacci number using recursive function. let fib = (n) => {   if(n <= 2) {     return 1   } else {     return fib(n - 1) + fib(n - 2);   } };
//read the input from console rl.question('Please enter number ', (readn) => {
  console.log(fib(readn));
  rl.close(); });

More about nodejs and recursion at https://kostasbariotis.com/node-js-recursion/
More recursion patterns for nodejs at : http://metaduck.com/01-asynchronous-iteration-patterns.html

Check if mongdb is running on mac / linux - centos

ps -ef | grep mongod | grep -v grep | wc -l | tr -d ' '

ps -ef | grep mongod | grep -v grep | wc -l | tr -d ' '
alias checkmongo="ps -ef | grep mongod | grep -v grep | wc -l | tr -d ' '"
Set the alias to call it easily.  :)


Check the detail explanation about the ps command here : http://stackoverflow.com/questions/31561098/how-to-check-if-mongo-db-is-running-on-mac
and here
http://linuxcommand.org/man_pages/ps1.html