Monday, 23 November 2015

Friday, 13 November 2015

Carousel Plugin not Working

<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  <style type="text/css">
  .item
  {
  background-color: blue;
  }
  </style>
</head>
<body>

<div id="myCarousel" class="carousel slide" data-ride="carousel">
    <!-- Indicators -->
    <ol class="carousel-indicators">
      <li data-target="#myCarousel" data-slide-to="0" class="active"></li>
      <li data-target="#myCarousel" data-slide-to="1"></li>
      <li data-target="#myCarousel" data-slide-to="2"></li>
      <li data-target="#myCarousel" data-slide-to="3"></li>
    </ol>

    <!-- Wrapper for slides -->
    <div class="carousel-inner" role="listbox">
      <div class="item active">
        <center><h1>First</h1></center>
      </div>

      <div class="item">
        <center><h1>Second</h1></center>
      </div>

      <div class="item">
         <center><h1>Third</h1></center>
      </div>

      <div class="item">
        <center><h1>Fourth</h1></center>
      </div>
    </div>

    <!-- Left and right controls -->
    <a class="left carousel-control" href="#myCarousel" role="button" data-slide="prev">
      <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
      <span class="sr-only">Previous</span>
    </a>
    <a class="right carousel-control" href="#myCarousel" role="button" data-slide="next">
      <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
      <span class="sr-only">Next</span>
    </a>
  </div>

<script src="js/jquery.min.js"></script>
</body>
</html>

Wednesday, 4 November 2015

Java - What throws an IOException

Assume the scenarios as below:
  1. You were reading network file and got disconnected.
  2. Reading local file which is not available any more.
  3. Using some stream to read the data and some other process closes the stream.
  4. You are trying to read/write a file and don't have permission
  5. You were writing a file and disk space is not available anymore
All these scenarios result into IOException

Tuesday, 3 November 2015

How to round double / float value to 2 decimal points in Java

package xyz.jayakumar.test1;

import java.text.DecimalFormat;

public class RoundOf {

public static void main(String[] args)
{
double kilobytes = 1205.6358;

System.out.println("kilobytes : " + kilobytes);

double newKB = Math.round(kilobytes*100.0)/100.0;
System.out.println("kilobytes (Math.round) : " + newKB);

DecimalFormat df = new DecimalFormat("###.##");
System.out.println("kilobytes (DecimalFormat) : " + df.format(kilobytes));
}

}

Wednesday, 28 October 2015

How To Set Up Apache Virtual Hosts on Ubuntu 14.04 LTS

You will also need to have Apache installed in order to work through these steps. If you haven't already done so, you can get Apache installed on your server through apt-get:
sudo apt-get update
sudo apt-get install apache2
After these steps are complete, we can get started.
For the purposes of this guide, my configuration will make a virtual host for test1.com and another for test2.com. These will be referenced throughout the guide, but you should substitute your own domains or values while following along.
Step 1: Create the Directory Structure
For instance, for our sites, we're going to make our directories like this:
sudo mkdir -p /var/www/test1.com/public_html
sudo mkdir -p /var/www/test2.com/public_html
The portions in red represent the domain names that we are wanting to serve from our VPS.

Step 2: Grant Permissions

Now we have the directory structure for our files, but they are owned by our root user. If we want our regular user to be able to modify files in our web directories, we can change the ownership by doing this:
sudo chown -R $USER:$USER /var/www/test1.com/public_html
sudo chown -R $USER:$USER /var/www/test2.com/public_html
The $USER variable will take the value of the user you are currently logged in as when you press "ENTER". By doing this, our regular user now owns the public_html subdirectories where we will be storing our content.

We should also modify our permissions a little bit to ensure that read access is permitted to the general web directory and all of the files and folders it contains so that pages can be served correctly:
sudo chmod -R 755 /var/www

Step 3: Create Demo Pages for Each Virtual Host

nano /var/www/test1.com/public_html/index.html
<html>
  <head>
    <title>Welcome to Test1.com!</title>
  </head>
  <body>
    <h1>Success!  The test1.com virtual host is working!</h1>
  </body>
</html>
cp /var/www/test1.com/public_html/index.html /var/www/test2.com/public_html/index.html
<html>
  <head>
    <title>Welcome to Test2.com!</title>
  </head>
  <body>
    <h1>Success!  The test2.com virtual host is working!</h1>
  </body>
</html>

Step 4: Create New Virtual Host Files

Virtual host files are the files that specify the actual configuration of our virtual hosts and dictate how the Apache web server will respond to various domain requests.
Apache comes with a default virtual host file called 000-default.conf that we can use as a jumping off point. We are going to copy it over to create a virtual host file for each of our domains.
We will start with one domain, configure it, copy it for our second domain, and then make the few further adjustments needed. The default Ubuntu configuration requires that each virtual host file end in .conf.

Create the First Virtual Host File

Start by copying the file for the first domain:
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/test1.com.conf
Open the new file in your editor with root privileges:
sudo nano /etc/apache2/sites-available/test1.com.conf
The file will look something like this (I've removed the comments here to make the file more approachable):
<VirtualHost *:80>
    ServerAdmin admin@test1.com
    ServerName test1.com
    ServerAlias www.test1.com
    DocumentRoot /var/www/test1.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Save and close the file.


Copy First Virtual Host and Customize for Second Domain

Now that we have our first virtual host file established, we can create our second one by copying that file and adjusting it as needed.
Start by copying it:
sudo cp /etc/apache2/sites-available/test1.com.conf /etc/apache2/sites-available/test2.com.conf
Open the new file with root privileges in your editor:
sudo nano /etc/apache2/sites-available/test2.com.conf
You now need to modify all of the pieces of information to reference your second domain. When you are finished, it may look something like this:
<VirtualHost *:80>
    ServerAdmin admin@test2.com
    ServerName test2.com
    ServerAlias www.test2.com
    DocumentRoot /var/www/test2.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Save and close the file when you are finished.

Step 5: Enable the New Virtual Host Files

Now that we have created our virtual host files, we must enable them. Apache includes some tools that allow us to do this.
We can use the a2ensite tool to enable each of our sites like this:
sudo a2ensite test1.com.conf
sudo a2ensite test2.com.conf

Step 6: Disable the Default Virtual Host Files

sudo a2ensite 000-default.conf
 
When you are finished, you need to restart Apache to make these changes take effect:
sudo service apache2 restart
 

Step 7: Set Up Local Hosts File (Optional)

sudo nano /etc/hosts
 
edit hosts file
127.0.0.1   localhost
127.0.0.1   test1.com
127.0.0.1   test2.com
Save and close the file when you are finished.

Step 8: Test your Results

Now that you have your virtual hosts configured, you can test your setup easily by going to the domains that you configured in your web browser: http://test1.com
You should see a page that looks like this:

Success! The test1.com virtual host is working!
Likewise, if you can visit your second page:

http://test2.com

You should see a page that looks like this:

Success! The test2.com virtual host is working!

You will see the file you created for your second site:
If both of these sites work well, you've successfully configured two virtual hosts on the same server.

Git merge branch to another branch

$ git checkout develop $ git pull $ git checkout test-branch $ git merge develop $ git push