Wednesday, August 20, 2014

How to Configure Embedded Jetty Server with Maven

Hi Guys,

Through this post, I will show how to configure the embedded jetty server plugin with maven projects. First let's see what is Jetty. Jetty is a light weight web server. In it you can deploy your web application during the development phrase.

The Jetty Maven plugin is useful for rapid development and testing. You can add it to any webapp project that is structured according to the usual Maven defaults. The plugin can then periodically scan your project for changes and automatically redeploy the webapp if any are found. This makes the development cycle more productive by eliminating the build and deploy steps.

Lets see how to setup the jetty server into maven projects

First step, Create a maven web app project.  use the following command in to create a new hello world project.



Once your project creation successful, a new web application project named “hello-webapp“, and the entire project directory structure is created automatically. Then go to that project root directory and open the pom.xml and then add the following code block within the build tag.

Once you add this plugin, you can deploy your hello-webapp application into jetty-server. To deploy the webapp in to jetty server, you the command as follows


then to view your web app in your browser localhost:8080/hello-webapp then try more complicated examples.

Saturday, July 26, 2014

Intro about D3js

In this post I'm going to write an introduction about one of the JavaScript library called D3js. 
The D3js JavaScript library helps us to make beautiful, interactive, browser-based data visualizations. And this D3js allows us to manipulate elements of a web page in the context of a data set. These elements can be HTML, SVG (Scalable Vector Graphics) , or Canvas elements, and can be introduced, removed, or edited according to the contents of the data set.

Before moving to an example on this, we should know some fundamentals things when we developing a web page. such as HTML, CSS, JavaScript, SVG ans Canvas elements. I assume that you know about those fundamentals.

Let's look at a basic code structures




<!DOCTYPE html>
<html>
<head>    
 <meta charset="utf-8">
 <style>.........</style>   
<script src="d3.js"></script> (1) <script> function draw(data) { (2)
// D3 visualization code goes here
} </script> </head> <body> ...... <script> d3.json("data/some_data.json", draw); (3) </script> </body> </html>

Have a look at the following description of the about blocks

(1) The D3js library is included to give our visualizations access to the D3js methods.

(2) Here, we always call draw function. Once it is called the data has been downloaded to the client. It will contain the bulk of the code necessary to create the visualization.

(3) The d3.json() function makes an HTTP GET request to a JSON file at the URL described by its first argument and once the data has been downloaded, will then call the function passed as the second argument. This second argument is a callback function (which we will always call draw), which is passed, as its only parameter, the contents of the JSON having been turned into an object or an array, whichever is appropriate.

Look at the following codes

Let me explain by showing an example. Here we will make a simple horizontal bar chat with use of D3js. I'm going to use the following code block which is a common standard structure for HTML page with JavaScript and CSS.


<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Bar Chart</title>
    <style>
        .chart div {
            background-color: steelblue;
            text-align: right;
            padding: 3px;
            margin: 1px;
            color: white;
        }
    </style>
    <script src="d3.js"></script>
</head>
<body>

<div class="chart"></div>

<script>
    var data = [4, 8, 15, 16, 23, 42];

    var x = d3.scale.linear()
            .domain([0, d3.max(data)])
            .range([0, 420]);

    d3.select(".chart")
            .selectAll("div")
            .data(data)
            .enter().append("div")
            .style("width", function (d) {
                return x(d) + "px";
            })
            .text(function (d) {
                return d;
            });
</script>
</body>
</html>


Copy and paste above code into a html page. and open it in the browser.

Enjoy with the Graph.

Tuesday, January 7, 2014

Do You Know?

1. Your shoes are the first thing people subconsciously notice about you. Wear nice shoes.

2. If you sit for more than 11 hours a day, there's a 50% chance you'll die within the next 3 years

3. There are at least 6 people in the world who look exactly like you. There's a 9% chance that you'll meet one of them in your lifetime.

4. Sleeping without a pillow reduces back pain and keeps your spine stronger.

5. There are three things the human brain cannot resist noticing - Food, attractive people and danger

6. Right-handed people tend to chew food on their right side

7. You can survive without eating for weeks, but you will only live 11 days without sleeping.

8. People who laugh a lot are healthier than those who don’t.

9. Laziness and inactivity kills just as many people as smoking.

10. A human brain has a capacity to store 5 times as much information as Wikipedia

11 Our brain uses same amount power as 10-watt light bulb!!

12. Our body gives enough heat in 30 mins to boil 1.5 litres of water!!

Monday, January 6, 2014

Power digit sum

If you are a best programmer, can you able to find the answer for the following question?

Q.  215 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.

What is the sum of the digits of the number 21000?

I found the answer using Scala programming.  

BigInt(2).pow(1000).toString().map(_.asDigit).sum

Can you able to write code to find the answer using your preferred programming language except Scala?  

Sunday, January 5, 2014

3D Apple

This 3D apple is designed by myself without using any external images. I used only Photoshop cs5.