Thursday, September 22, 2016

Must Have Features in the Social and Mail Sites

I use gmail and other social sites like LinkedIn, Facebook, Twitter on the daily basics each of them have lots and lots of their own features but I think they would be more productive if they have some extra plugins or features too. Here is the list of plugins/features which may help users to make their work more easier as well as to use this social sites.

Gmail
Lets say I have to send email to the hundreds of the people daily with the same text. So what if Gmail introduces some small plugins like notes in the compose area so that user can save their texts in that and can copy and paste those text just by clicking one button like Dropbox and select the text.

Facebook
From beginning to now Facebook have done lots and lots of improvements and also added lots of new features. Its new feature about video is awesome but sometime I feel annoy because the volume level is not saved for other video once I change it as like in YouTube. And while uploading the video if there was a option to make a playlist will also be awesome.

Friday, June 3, 2016

Understanding Spring Enterprise Intregation

It is a lightweight messaging solution that will add integration capabilities to our spring application. As a messaging strategy, it provide a way of sharing information quickly and with the high level of decoupling between the involved components or applications.

It allows us to 

  1. Allows communication between the components within our application using the in-memory messaging. Which allows this components to be loosely coupled and share the message using the message channel.
  2. It also allows us to communicate with external system. Here we just need to send the information and spring integration will take care rest of it, if response is necessary then it will also take care of that.
The advantages of using EI are: 
  1. Loose coupling within the components
  2. Event Oriented Application
  3. Integration logic is separated from the business logic.





References::
1. JavaCodeGeeks

Difference between the Hadoop HDFS and Google GFS

In Hadoop, the reducer is presented with a key and an iterator over all values associated with the particular key. The values are arbitrarily ordered.

Google's implementation allows the programmer to specify a secondary sort key for ordering the values (if desired) in which case values associated with each key would be presented to the developer's reduce code in sorted order.

Some of the key differences are listed below:

HDFS
  • Initiated by yahoo and later on made open source
  • Developed in Java
  • it consists of NameNode and DataNode
  • default block size is 128 mb
  • it follows WORM model : write once read multiple
  • deleted files are renamed into particular folder and are removed by the garbage
  • reducer can emit arbitrary number of key value


GFS
  • Developed by Google Inc.
  • Developed in C++(most likely)
  • it consists of MasterNode and Chunk Server
  • default block size is 64 mb
  • multiple read and write is possible
  • deleted nodes are hide and are removed if not used more then 3 days
  • programmer are not allowed to change the key in the reducer i.e. reducer input key must be the same as in the output


Friday, May 13, 2016

Web Architecture - Explained

What is 3-tier Architecture?


to understand this let us take the example of the shopping cart system where user can do all the shopping related task online. For for understanding this we will focus only on the item selection part of this online system, where user can select the item and add it to the cart. In 3 -tier architecture we have the following 3 layers which are:

Presentation layer: 
This layer will notify the business layer with the action user have taken in the front end which may be like clicking the ADD TO CART button in the page. Here when the user click the button which is for eg. implementing the AJAX will send information to the business layer and when the business layer provides the success response then the user will see the visual effects like Item being added to the cart or the cart item number increase visually. In spring the use of @Controller Annotation is used in this layer.

Business Layer: 
In this layer after getting the request from the presentation layer the this layer will create the Customer Order Object or the Model using the different business criteria. such as:
- is the item available in the inventory.
- calculate the price of the item or calculate the total price of the items
- calculate the shipping cost
- finally store this information in the session
In spring the use of @Service Annotation is used in this layer. The core domain and domain logic is addressed in this layer.


Data Access Layer:
This layer will now finally persist the Customer order in the physical data store like Oracle, MySQL etc. In Spring ORM and Hibernate comes in this layer. In spring the use of @Repository Annotation is used in this layer.

For the extra security we can also add the extra layer i.e. Security layer between the Presentation and Business Layer. Spring Security can be used as the security layer.


Monolith N-tier

The monolithic application consists of a single application layer that supports the user interface, the business rules, and the manipulation of the data all in one. It is very simple to develop but not typical architecture for the software engineering. Only applicable if the application is small or does not need future expansion.


Monday, August 24, 2015

Using Polymer 1.0 with AngularJs Route

Step 1:
install polymer form its official site polymer-project.org, best way to download polymer is by using
bower : bower install --save Polymer/polymer#^1.0.0

Step 2:
set up your site's main page i.e index.html using the components what you like. You can see the code of my index.html file here

Step 3:
Now add the angular js plugins in the end of header in index page as below
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.3/angular-route.min.js"></script>

Step 4:
Now create angular app by initiating it by using ng-app="shaharma"in the body tag
<body  unresolved class="fullbleed layout vertical" ng-app="shaharma">

Step 5:
We are going to do route by using the hash(#) routing technique. Now update the link tag with # link tag as below:

     <paper-menu class="list" >
          <a href="#/">
            <iron-icon icon="home"></iron-icon>
            <span>Home</span>
          </a>
          <a href="#/about">
            <iron-icon icon="info"></iron-icon>
            <span>Users</span>
          </a>
          <a href="#/contact">
            <iron-icon icon="mail"></iron-icon>
            <span>Contact</span>
          </a>
        </paper-menu>
Now create a file named angular.js where we are going to add the route technique for our website. The final code is here

Step 6:
define a content area where the view are tobe loaded by using  ng-view
<div class="content" ng-view></div>

Step 7:
Now lets create a webelements which are going to be displayed inthe content section during the routing:
inside the elements folder we can see the web components for the different view which can be view here
example : for contact-form view

<dom-module id="contact-form">
  <style is="custom-style">
      paper-card {width: 100%-20px;margin: 10px;}
      #heading{color: #313131;font-size: 16px;font-weight: bold;
      .content.paper-button {padding: 0; }
  </style>
  <template is="dom-bind">
    <h4>Character counter</h4>
    <div class="vertical-section">
      <paper-input label="label" char-counter></paper-input>
      <paper-input label="at most 10 letters" char-counter auto-validate pattern="[a-zA-Z]*" maxlength="10" error-message="letters only!"></paper-input>
      <paper-textarea label="textarea" char-counter></paper-textarea>
      <paper-textarea label="textarea with maxlength" char-counter maxlength="10"></paper-textarea>
      <paper-textarea label="text area with rows and max-rows" rows="3" max-rows="4"><paper-textarea>
    </div>
  </template>

<script>
(function() {
  Polymer({
    is: 'contact-form' 
  });
})();
</script>
</dom-module>

Step 8: register all the elements in the single elements.html page
 elements/elements.html
Full working code can be found here and demo can be viewd here

Friday, July 10, 2015

Getting Json Data from server and displaying it in Front page

1. For this example I am using php server side code to gather the data from the data base and return it as a Json format. For this we can use the buid in code for php i.e.
json_encode($data);

for eg: (using Codeigniter model)

                $check_sql = "Select * from user where about_status = 1"; //status is flag for the active user
$check = $ci->db->query($check_sql);
$row = $check->result();

echo json_encode($row);

which gives output as:

{
"records": [
  {
    "Name" : "Yubraj Pokharel",
    "City" : "Kathmandu",
    "Country" : "NP"
  },
  {
    "Name" : "Chitra Shrestha",
    "City" : "Pokhara",
    "Country" : "NP"
  },
  {
    "Name" : "Prayag Upd",
    "City" : "California",
    "Country" : "US"
  },
  {
    "Name" : "Sudhan Pokharel",
    "City" : "Nepalgunj",
    "Country" : "NP"
  },
  {
    "Name" : "Mr Tom Cruise",
    "City" : "California",
    "Country" : "US"
  }
]
}

2. calling it from the angular page:

<html>
<head>
<title>Json Data</title>
        call angular js here
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-12" ng-app="myApp" ng-controller="customersCtrl"> 
<table class="table">
<tr>
<th>Name</th>
<th>country</th>
</tr>
<tr  ng-repeat="x in names">
    <td>{{ x.Name }} </td>
    <td>{{ x.Country }}</td>
  </tr>
</table>
</div>
</div>
</div>

<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
    $http.get("http://localhost/angular/news.php")
    .success(function(response) {$scope.names = response.records;});
});
</script>
</body>
</html>

3. Here it is done enjoy happy coding :)


Tuesday, January 13, 2015

Single page Web App using Angular JS

index.html
This is the simple part. We’re using Bootstrap and Font Awesome. Open up your index.html file and we’ll add a simple layout with a navigation bar.

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Single page web app using Angularjs</title>


<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js"></script>
 <script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.3/angular-route.min.js"></script>
  <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
  <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
  <script src="script.js"></script>


</head>
<body ng-app="shaharma">

  <div>
      <div>
          <nav class="navbar navbar-inverse" role="navigation" style="padding-left:130px;">
             <ul class="nav navbar-nav">
                <li class="active"><a href="#/">Home<span class="sr-only">(current)</span></a></li>
                <li><a href="#/about">About us</a></li>
                <li><a href="#/about">Read tutorial</a></li>
              </ul>
          </nav>
      </div>

      <br/>

      <div ng-view class="jumbotron"></div> <!-- div where the dynamic page view will be loaded -->

  </div>
</body>

</html>

Injecting Pages into the Main Layout

ng-view is an Angular directive that will include the template of the current route (/home, /about, or /contact) in the main layout file. In plain words, it takes the file we want based on the route and injects it into our main layout (index.html).
We will add the ng-view code to our site in the div#maito tell Angular where to place our rendered pages.

Configure Routes and Views

Since we are making a single page application and we don’t want any page refreshes, we’ll use Angular’s routing capabilities.
Let’s look in our Angular file and add to our application. We will be using $routeProvider in Angular to handle our routing. This way, Angular will handle all of the magic required to go get a new file and inject it into our layout.
For linking to pages, we’ll use the #. We don’t want the browser to think we are actually travelling to about.html or home.html
First, we have to create our module and controller in javascript. We will do that now in script.js.

script.js.
var app = angular.module('shaharma',['ngRoute']);

app.config(function($routeProvider){

      $routeProvider
          .when('/',{
                templateUrl: 'home.html'
          })
          .when('/about',{
                templateUrl: 'about.html',
                controller:'yubrajcontroller'
          });


});

app.controller('yubrajcontroller', ['$scope', '$http', function($scope, $http){   ---[A]
   $scope.message = 'Welcome to Inspire';
  $http.get("http://www.w3schools.com/website/Customers_JSON.php")
.success(function(response) {$scope.names = response;});
}]);


--[A]- description
here we are fetching the json data from the http server which will be shown in the about.html file



about.html.

<div style="padding-left:130px;padding-right:200px;">

<h1>About us page2. {{message}} </h1>

<p><input type="text" ng-model="searchresult"></p>
<table class="table">
<tr>
<th>Name</th>
<th>City</th>
<th>Country</th>
</tr>
<tr ng-repeat="x in names | filter:searchresult">

<!-- here names comes from the yubrajcontroller which is returning the json data to the about us page -->

<td>{{ x.Name | uppercase }}</td>
<td>{{ x.City | uppercase }}</td>
<td>{{ x.Country | uppercase }}</td>
</tr>

  </table>

 </div>


home.html

 <div style="padding-left:130px;padding-right:200px;">
   <h1>Hello, world!</h1>
  <p>This is simple angular ng-view and ng-route tutorial to demonstrate single page web app development.</p>
  <p>
    This is executed because of this code.
    <pre>
      <code>
        .when('/',{
              templateURl: 'home.html'
        })
      </code>
    </pre>
  </p>
  <p><a class="btn btn-primary btn-lg" href="#" role="button">Read tutorial</a></p>
</div>

--Enjoy