install JRE/JDK on ubuntu 16.06

For Mac system Download ‘dmg’ file from here and double click on it.

For Linux: 

Don’t install OpenJDK

 $ sudo apt update && sudo apt install openjdk-9-jre-headless
 $ java -version
 openjdk version "9-internal"
 OpenJDK Runtime Environment (build 9-internal+0-2016-04-14-195246.buildd.src)
 OpenJDK 64-Bit Server VM (build 9-internal+0-2016-04-14-195246.buildd.src, mixed mode) 

Install Oracle Java:

 $ sudo add-apt-repository ppa:webupd8team/java
 $ sudo apt-get update
 $ sudo apt-get install oracle-java8-installer
 $ java -version
 java version "1.8.0_171"
 Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
 Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode) 

After installing Java on Linux system, You must have to set JAVA_HOME and JRE_HOME environment variables. Which is used by many Java applications to find Java libraries during runtime. You can set these variables in /etc/environment file using the following command.

 cat >> /etc/environment <<EOL

Enable MongoDB Access Control

The default data directory for MongoDB is /data/db

This can be overridden by a dbpath option specified on the command line or in a configuration file.

If you install MongoDB via a package manager such as Homebrew or MacPorts these installs typically create a default data directory other than /data/db and set the dbpath in a configuration file.

You can check the dbpath by:


in your mongo shell

 "storage" : {
    "dbPath" : "/usr/local/var/mongodb"

The following procedure first adds a user administrator to a MongoDB instance running without access control and then enables access control.

1.  Start MongoDB without access control.

$ mongod --port 27017 --dbpath /data/db1

2. Connect to the instance.

$ mongo --port 27017

3. Create the user administrator.

In the admin database, add a user with the userAdminAnyDatabase role. For example, the following creates the user myUserAdmin in the admin database:

Note: The database where you create the user (in this example, admin) is the user’s authentication database.

 > db.createUser(
 ...   {
 ...     user: "abhilash",
 ...     pwd: “password!“,
 ...     roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
 ...   }
 ... ) 

 Successfully added user: {
 "user" : "abhilash",
 "roles" : [
    "role" : "userAdminAnyDatabase",
    "db" : "admin"

Disconnect the mongo shell.

4. Re-start the MongoDB instance with access control.

$ mongod --auth --port 27017 --dbpath /usr/local/var/mongodb/db1

Clients that connect to this instance must now authenticate themselves as a MongoDB user.

 > db.auth();
 Error: auth expects either (username, password) or ({ user: username, pwd: password })
 > db

** To authenticate during connection:

$ mongo --port 27017 -u "abhilash" -p "password!” --authenticationDatabase "admin"

** To authenticate after connecting

Connect the mongo shell

 $ mongo
 > use admin
 > db.auth("abhilash", “password!“ )
 > mongo
 MongoDB shell version v3.4.7
 connecting to: mongodb://
 MongoDB server version: 3.4.7
 Server has startup warnings:
 2018-01-22T10:32:18.027+0530 I CONTROL  [initandlisten]
 2018-01-22T10:32:18.027+0530 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
 2018-01-22T10:32:18.027+0530 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
 2018-01-22T10:32:18.027+0530 I CONTROL  [initandlisten]
 > use admin
 switched to db admin
 > db
 > db.auth("abhilash", "password!”);
 > use my_dbname;
 > db.createUser(
     user: "vadmin",
     pwd: “pass111!”,
     roles: [ { role: "readWrite", db: "my_dbname" },
              { role: "read", db: "test" } ]

Reference:  Mongodb enable-authentication 

A Ruby on Rails Application without models

This blog is a quick walkthrough of creating a Ruby On Rails application without a model.

Find Rails new options from here:

Find Gemfile options from here:

Install Ruby/Rails using rbenv

$ touch .rbenv-gemsets
$ echo project-name > .rbenv-gemsets
$ rbenv gemset active
$ rbenv install 2.5.3
$ gem install bundler
$ rbenv rehash
$ gem install rails -v 5.2.9
$ rbenv rehash
$ rails new my-new-porject --skip-active-record --skip-bundle -v 5.2.9

Add in Gemfile:

ruby “2.5.3”

comment jbuilder, we don’t need it.

# gem 'jbuilder', '~> 2.8’

Move rbenv gems file to new rails app folder

$ mv .rbenv-gemsets my-new-porject

$ touch .ruby-version

$ echo 2.5.3 > .ruby-version

$ gem install bundler

$ bundle

$ ruby -v
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin18]

Start Rails server:

$ rails s

Gemfile add:

# Bootstrap Theme

gem 'bootstrap', '~> 4.3.0’

# Slim template Engine

gem 'slim', '>=4.0.1’

Do Bundle Install

$ bundle

Rename css to scss because we use bootsrap mixins and variables that work with scss files

$ mv app/assets/stylesheets/application.css app/assets/stylesheets/application.scss

Import Bootstrap styles in app/assets/stylesheets/application.scss:

// Custom bootstrap variables must be set or imported *before* bootstrap.
@import "bootstrap";

Then, remove all the *= require and *= require_tree statements from the Sass file. Instead, use @import to import Sass files.

Bootstrap JavaScript depends on jQuery
Add jquery-rails to Gemfile:

gem 'jquery-rails', '~> 4.3.4’

Bootstrap tooltips and popovers depend on popper.js for positioning.
Add Bootstrap dependencies and Bootstrap to your application.js:

//= require jquery3
//= require popper
//= require bootstrap-sprockets

While bootstrap-sprockets provides individual Bootstrap components for ease of debugging, you may alternatively require the concatenated bootstrap for faster compilation:

//= require jquery3
//= require popper
//= require bootstrap

Sass: Individual components

All Bootstrap opponents will be imported by default.
You can also import components explicitly. To start with a full list of modules copy _bootstrap.scss file into your assets as _bootstrap-custom.scss. Then comment out components you do not want from _bootstrap-custom. In the application Sass file, replace @import ‘bootstrap’ with:

@import 'bootstrap-custom';

Your application.css:

 * This is a manifest file that'll be compiled into application.css, which will include all the files
 * listed below.
 * Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's
 * vendor/assets/stylesheets directory can be referenced here using a relative path.
 * You're free to add application-wide styles to this file and they'll appear at the bottom of the
 * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
 * files in this directory. Styles in this file should be added after the last require_* statement.
 * It is generally better to create a new file per style scope.

/*Custom bootstrap variables must be set or imported *before* bootstrap.
  The available variables can be found:
@import "bootstrap";

Your application.js File:

// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
// vendor/assets/javascripts directory can be referenced here using a relative path.
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
// Read Sprockets README ( for details
// about supported directives.
//= require rails-ujs
//= require turbolinks
//= require_tree .
//= require jquery3
//= require popper
//= require bootstrap-sprockets

You can check sample bootstrap forms here:

Remove cable.js from javascripts # we don’t need this for now

Rails 5.2.0 API Only application with latest Ruby 2.5.1

Check for the new ruby and rails versions

Here we are going to install Ruby – 2.5.1 & Rails – 5.2.0 (API only application)

Get rbenv into action
If you are not installed rbenv, you can install it from here:
After the installation make sure that, your $PATH has included rbenv/shims path. Else rbenv will not work.

1. $ rbenv install --list # Gets the list of ruby versions available

$ rbenv install 2.5.1

ruby-build: definition not found: 2.5.1

The following versions contain `2.5.1' in the name:

See all available versions with `rbenv install --list'.

If the version you need is missing, try upgrading ruby-build:

  brew update && brew upgrade ruby-build


rbenv cannot find the version: 2.5.1

Upgrade ruby-build

Mac OSX:

$ brew upgrade ruby-build --HEAD

Now install ruby 2.5.1

$ rbenv install 2.5.1

Create a new gemset:

Rbenv gemset is a separate script and not coming with rbenv. If you are not installed this, you can install it from here:

$ rbenv gemset create 2.5.1 demo-app
That set up a directory for you in ~/.rbenv/versions/2.5.1/gemsets/demo-app

Set the ruby version to the newest

$ rbenv local 2.5.1

$ rbenv version
=> 2.5.1

    Activate New Gemset

For activating a gemset we need to create a .rbenv-gemsets file in the current directory.

$ touch .rbenv-gemsets
$ echo demo-app > .rbenv-gemsets

Check active gemset:

$ rbenv gemset active

Install Rails 5.2.0 API only Application

$ gem install rails -v '5.2.0'

$ rails -v
Rails 5.2.0

Later we can delete this .rbenv-gemsets file and add a new file named ‘.ruby-gemset’ in the rails project directory. I cannot find any other option for doing this. If anyone know more about this, please give a comment. I appreciate that.

Create a New Rails app

$ rails new demo-app  --api -T # API only skip the testing framework altogether

For Full Rails:

$ rails new demo-app -T -d postgresql # skip the testing framework altogether, uses Postgres Database

-T to exclude Minitest – the default testing framework if you are planning to use RSpec to test your API.

Rspec test framework:

You can use the following with Rspec.
Shoulda Matchers:
Collection of testing matchers extracted from Shoulda (

Database Cleaner:
Strategies for cleaning databases in Ruby. Can be used to ensure a clean state for testing

A library for generating fake data such as names, addresses, and phone numbers.

use option: –no-rdoc –no-ri # skips the documentation

Remove Rbenv Gemset and add Ruby gems file

$ rm .rbenv-gemsets

$ cd demo-app
$ touch .ruby-gemset
$ echo demo-app > .ruby-gemset
$ rails s
=> Booting Puma
=> Rails 5.2.0 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.11.4 (ruby 2.5.1-p57), codename: Love Song
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://
Use Ctrl-C to stop

Goto http://localhost:3000/


Done! Lets go…

Install Learning Locker (NodeJS) in your Mac OSX

Visit the following link to install LL on CentOS, Fedora, Ubuntu, and Debian OS

Mac OS is not supported in the installation process specified above.

You can install Learning Locker in Mac OSX by custom installation.

Steps to Install LL in Mac OSX:

1. Clone the repo from learning locker git repo

$ git clone

Enter into the directory and install the requirements:

$ yarn install

You can be built 5 distinct services with this codebase.
2. Install services

If you want to install all services on the same machine, you can use the following one command:
$ yarn build-all

Install Services separately if you want to install each service in different servers

Install the UI Server
$ yarn build-ui-server

Install the UI Client
$ yarn build-ui-client

Install the API Server
$ yarn build-api-server

Install the Worker
$ yarn build-worker-server

Install CLI
$ yarn build-cli-server

Note: Copy the .env.example into a new .env file and edit as required


Install pm2 , if you have not yet installed
$ npm i -g pm2

To start API, Scheduler, UI, Worker services, navigate to the LL working directory and run:

$ pm2 start pm2/all.json


Step 1: Clone the repo
$ git clone

Step 2: Enter into the directory and install the requirements and build

$ yarn install
$ yarn build

Note: Copy the .env.example into a new .env file and edit as required

To start the xAPI service, navigate to the xAPI Service working directory and run:

$ pm2 start pm2/xapi.json

You can check the service status:

$ pm2 status

$ pm2 restart all # restart all services

$ pm2 logs # view logs

Launch the UI:
http://localhost:3310/login, note that I have change the UI port in .env to 3310, as other services running in default port


Now you have to create User for logging in. Lets create an Admin User by the following command.

$ node cli/dist/server createSiteAdmin [email] [organisation] [password]

In order to use this command you have to install the CLI server for LL, that I already mentioned in the installation steps.

An Admin Example
$ node cli/dist/server createSiteAdmin "MyEmailId" "CoMakeIT" “myPassword”

You can run the migrations by the following command if any pending migrations exists

$ node cli/dist/server migrateMongo


Now try to Login with the credentials.

Ooops… there is an issue, and we can’t login

After doing some research I found the issue. We need to add a secret key base to our Application to work with JWT tokens.
Open .env file and find:

# Unique string used for hashing
# Recommended length, 256 bits

Create a 256 bit length hash key and give as a value. As I am a Rails developer, It is easy for me to create one by going into any my Rails project and type

$ rake secret

I get One! 🙂

Or you can use some online applications like:

And do:
$ pm2 restart all

from LL project folder


Try to sign in again

Wohh, Its done. Great. Now you can try some bit of dashboard items like Graphs. Go on.

Laravel – PHP web framework Vs Rails, Installation

Laravel is a php web framework which following the model–view–controller (MVC) architectural pattern. It is gaining more and more popularity nowadays.

It is almost followed Ruby on Rails framework pattern, not only for MVC structure but also for the pattern that Rails adopt for doing various tasks. It uses composer that installs the software snippets you needed to achieve a particular task as Rails does it with bundler to pick gems.

The drawback of Laravel is it cannot achieve the power of Ruby like metaprogramming through php. So I need to write some more code in Laravel and its actually feels irritating if you want to write less code without the same repetitive patterns and keep it DRY.

Get and install composer

Goto ( Click download.

Run the following:

$ php -r "copy('', 'composer-setup.php');"

$ php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

$ php composer-setup.php

$ php -r "unlink('composer-setup.php');"

This will install ‘composer.phar ‘ in the current directory.

Move that to bin folder to get it globally available as a command and rename it to composer

$ mv composer.phar /usr/local/bin/composer

Open new tab and Type

$ composer

Install Lareval

Using composer

$ composer create-project --prefer-dist laravel/laravel blog "5.4.*"

From laravel/laravel github repo OR via larval installer

$ laravel new blog
-bash: laravel: command not found

Install it:

$ composer global require "laravel/installer"

this makes it globally accessible

Make sure to place the $HOME/.composer/vendor/bin directory (or the equivalent directory for your OS) in your $PATH so the laravel executable can be located by your system.

Open ~/.bash_profile OR ~/.bashrc in Mac

and add the following line:

export PATH="$PATH:$HOME/.composer/vendor/bin"

save and exit

Open New tab type:

$ laravel
Laravel Installer 1.4.1
  command [options] [arguments]

Check Laravel version:

$ php artisan --version
Laravel Framework 5.4.27

You are ready to go!

#Rails 4.2: How to create a full URL with given host and port

Basically if you need to generate url based on the current url during a request OR you can create your own Urls by using Rails ‘ActionDispatch::Integration::Session‘ class.

Rails creates an object ‘app’. It is and action dispatch session object.

You can make use of that object for creating your own URLs like:

> app.root_url(:port => 20)  => ""

> app.root_url(:port => 20, :host => '')
 => ""

During a request you can use like this:

 > request.url(:port => 20)

Launch sublime text 3 from command line in mac

An executable file to open the sublime editor is already contained in the Sublime directory itself. By default this is not added to your $PATH, in your command-line interpreter.

So add that executable file to one of the directory that included in $PATH.

$ ln -s /Applications/Sublime\ /usr/local/bin/sublime

Here ‘/usr/local/bin/’ is present in my $PATH

Then take sublime as following:

$ sublime ~/projects/my-app

Here ‘~/projects/my-app’ is your application path.

Create bootable usb drive of OSX from Mac OS

You can use mac’s createinstallmedia command. The format to create a bootable USB is given below.

$ sudo /Applications/Install\ macOS\ --volume |YOUR-USB-DRIVE-PATH-HERE| --applicationpath |DOT-APP-FILE-MACOS|

In My system the command will be as follows:

$ sudo /Applications/Install\ macOS\ --volume /Volumes/ABHI\'S/ --applicationpath /Applications/Install\ macOS\

You can easily find the corresponding software path in your system, if you have a different OS that mentioned above.

For more details, visit: