Friday, July 1, 2016

Saturday, April 2, 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

Friday, April 1, 2016

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


Saturday, March 26, 2016

Start XAMPP Apache and others from Terminal ( Command Line )


$ ./xampp apache start
Usage: xampp <action>

start         Start XAMPP (Apache, MySQL and eventually others)
startapache   Start only Apache
startmysql    Start only MySQL
startftp      Start only ProFTPD

stop          Stop XAMPP (Apache, MySQL and eventually others)
stopapache    Stop only Apache
stopmysql     Stop only MySQL
stopftp       Stop only ProFTPD

reload        Reload XAMPP (Apache, MySQL and eventually others)
reloadapache  Reload only Apache
reloadmysql   Reload only MySQL
reloadftp     Reload only ProFTPD

restart       Stop and start XAMPP
security      Check XAMPP's security

enablessl     Enable SSL support for Apache
disablessl    Disable SSL support for Apache

backup        Make backup file of your XAMPP config, log and data files

oci8          Enable the oci8 extenssion

fix_rights    Resets file permissions.

Wednesday, March 16, 2016

make alias to setup VirtualHosts using XAMPP on MacOSX (Simple way)

Simple & Quick

Add these following lines in ~/.bash_profile file

1)  alias goextra='cd /Applications/xampp/xamppfiles/etc/extra'
2). alias editvhost='sublime httpd-vhosts.conf'

and run " . ~/.bash_profile " .

and please run goextra and editvhost in your terminal respectively.

When you run editvhost httpd-vhosts.conf will be opened.

Add following lines to the file. You can also use the dummy lines in the file as reference.

#dummy.local
<VirtualHost *:80>
    ServerName dummy.local
    DocumentRoot "/Users/You/Your_Projects/dummyproject"
    <Directory "/Users/You/Your_Projects/dummyproject">
        Options Indexes FollowSymLinks Includes ExecCGI
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog "logs/dummy.local-error_log"
</VirtualHost>

3). alias edithost='sudo sublime /etc/hosts'

Add following line in #Virtual Hosts section of the hosts file.
# Virtual Hosts
127.0.0.1 dummy.local

Restart your Apache on xampp.

You are good to go. 

If you have any question or better way to do this or to share your ideas, please leave a comment or send me an email at lynnnayko@gmail.com or tweet me @lynnnayko

Thank you very much for your time.



Sunday, February 21, 2016

upgrade nodejs mac and npm update error module js

I had a problem updating npm after installing new version of node and this solved my problem
Note: If you get "301 Moved Permanently" then try curl -0 -L http://npmjs.org/install.sh | sudo sh to follow redirects. Also notice I added sudo before the sudo sh command depending on your users permissions.

If you want to update stable version of nodejs. n is another nodejs version manager. or you can just go to nodejs.org, download and install it.

##Install module n

$ npm install -g n

$ n stable
We are going to need sudo to do this.

Resources :
https://github.com/tj/n/issues/101
http://mazharahmed.me/upgrade-node-js-version-in-mac/
https://github.com/tj/n

Friday, February 19, 2016

npm refusing to install as a dependency of itself

Cause : 
The name of the module you are trying to install cannot be same as the name you defined in package.json

Let's say, you are trying to install hapi module in hapi directory, rename the name to something other than hapi

{
  "name": "hapi-test",
  "version": "1.0.0",
  "description": "this is a test",
  "main": "server.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node server.js"
  },
  "keywords": [
    "test"
  ],
  "author": "wai",
  "license": "ISC",
  "dependencies": {
    "hapi": "^13.0.0"
  }
}

Here's more on package.json at https://docs.npmjs.com/files/package.json




Life is a journey