Sunday 21 February 2016

Solve the bisection method equation using C


The bisection method is based on the following result from calculus:

The Intermediate Value Theorem: Assume f : IR→IR is a continuous function and there are two real numbers a and b such that f (a)f (b) < 0. Then f (x) has at least one zero between a and b.

In other words, if a continuous function has different signs at two points, it has to go through zero somewhere in between!

The bisection method consists of finding two such numbers a and b, then halving the interval [a,b] and keeping the half on which f (x) changes sign and repeating the procedure until this interval shrinks to give the required accuracy for the root.

An algorithm could be defined as follows. Suppose we need a root for f (x) = 0 and we have an error tolerance of ε (the absolute error in calculating the root must be less that ε).

Bisection Algorithm:
  1. Find two numbers a and b at which f has different signs. 
  2. Define c = a+b  
  3. If b−c ≤ε then accept c as the root and stop. 
  4. If f (a)f (c)≤0 then set c as the new b. Otherwise, set c as the new a. Return to step 1.
Error bounds
Let α be the value of the root, a≤α≤b. Let an, bn and cn be the values of a, b and c on the nth iteration of the algorithm.

Then the error bound for cn is given by
|α−cn| ≤  (1/2n) (b−a)

This inequality can give us the number of iterations needed for a required accuracy ε
n ≥  ((log(b−a)/ε)) / log2

Advantages and disadvantages of the bisection method

  1. The method is guaranteed to converge.
  2. The error bound decreases by half with each iteration.
  3. The bisection method converges very slowly.
  4. The bisection method cannot detect multiple roots



Example Code:

Bisection Method x2-5
root between 2 and 3


File name : bisection.c

#include<stdio.h> #include<conio.h> #include<stdlib.h> #include<math.h> float f(float x) { return (x*x)-5; } main() { float x0,x1,x2,E; int count=1; charch; clrscr(); xyz: printf("\nEnter value of x0"); scanf("%f",&x0); printf("\nEnter value of x1"); scanf("%f",&x1); printf("\nEnter value of error interation:"); scanf("%f",&E); clrscr(); printf("\n NO\tx0\tx1\tx2\tf(x0)\tf(x1)\tf(x2)"); if(f(x0)*f(x1)<0) { x2=(x0+x1)/2; while(fabs(x1-x0)>E) { printf("\n %d\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f\t%.3f",count,x0,x1,x2,f(x0),f(x1
),f(x2)); if(f(x0)*f(x2)<0) { x1=x2; } else { x0=x2; } count++; x2=(x0+x1)/2; } printf("\nRoot is %f",x2); } else { clrscr(); printf("\nYour value is incorrect...\nPlease enter a new value then Press 'Y' key otherwise any key press to exit!...."); fflush(stdin); scanf("%c",&ch); if(ch=='y'||ch=='Y') { goto xyz; } else { exit(0); } } getch(); }

Friday 19 February 2016

Find the root of quadratic equation using C



A quadratic equation is a second-order polynomial equation in a single variable x with ax2+bx+c=0, a!=0.

The Quadratic Formula uses the "a", "b", and "c" from "ax2 + bx + c", where "a", "b", and "c" are just numbers; they are the "numerical coefficients" of the quadratic equation they've given you to solve.

The Quadratic Formula is derived from the process of completing the square, and is formally stated as:

For ax2 + bx + c = 0, the value of x is given by:

x  =  [ -b ± sqrt(b2 - 4ac) ] / 2a

Because it is a second-order polynomial equation, the fundamental theorem of algebra guarantees that it has two solutions. These solutions may be both real, or both complex.

For Example Code:

File name : qurdation.c
   

#include<stdio.h> #include<conio.h> #include<math.h> void main() { float a,b,c,d,x1=0,x2=0; clrscr(); printf("Enter the value of A:="); scanf("%f",&a); printf("Enter the value of B:="); scanf("%f",&b); printf("Enter the value of C:="); scanf("%f",&c); d=((b*b)-(4*a*c)); clrscr(); printf("\n| A | %.2f ",a); printf("\n| B | %.2f ",b); printf("\n| C | %.2f ",c); printf("\n-----------------"); printf("\n| D | %.2f",d); if(d==0) { printf("\n\n| Roots are real and equal"); x1=((-b+sqrt(d))/(2*a)); x2=((-b-sqrt(d))/(2*a)); } else if(d>0) { printf("\n\n| Roots are real and distict"); x1=((-b+sqrt(d))/(2*a)); x2=((-b-sqrt(d))/(2*a)); } else if(d<0) { printf("\n\n| Roots are imegnand "); } printf("\n\n| Value of X1 | %.2f",x1); printf("\n| Value of X2 | %.2f",x2); getch(); }

Angularjs Create Own Field with Validation using custom directives


For Example Code:

File name : index.html
<!doctype html>
<html ng-app="MyApp" >
<head>
  <meta charset="utf-8">
  <title></title>
  <link rel="stylesheet" href="style.css">
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.2/angular.js"></script>
  <link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet">
  <script src="app.js"></script>
  <script src="field.js"></script>
  <script src="submitvalid.js"></script>
</head>
<body ng-controller="mainController">
      <form submit-valid="submitForm()" name='customer-form' novalidate>
          <field ng-model='student.phone' type='text' label='Phone:' data-required ng-pattern="/^[0-9]+$/">
            <validator key='required'>Phone is required</validator>
            <validator key='pattern'>Phone is invalid</validator>
          </field>
    
    <field ng-model='student.name' type='text' label='First Name:' data-required >
            <validator key='required'>Firstname is required</validator>
          </field>
    <field ng-model='student.gender' template='select' type='text' label='Gender:' data-required ng-options="item for item in Gender">
            <validator key='required'>Gender is required</validator>
          </field>
     <field ng-model='student.address' type='text'  template='textarea' label='Address:' data-required >
            <validator key='required'>Address is required</validator>
          </field>
        <input type="submit" value="submit" id="submit" name="submit"/>
      </form>  
      <pre>{{ student | json }}</pre>
</body>
</html>

File name : style.css

.pristine.true, .dirty.true, .invalid.true {
  background: gray;
}
.valid.false {
  background: red;
}
.valid.true {
  background: green; 
}
.error {
  color: red; 
}

File name : app.js

var app = angular.module('MyApp', []);

app.controller('mainController', function($scope) {
  $scope.student = {};
  $scope.student.phone = "7778899845";
  $scope.Gender = ["Male", "Female"];
  $scope.submitForm = function() {
    alert('Data Submitted');
  };
});


File name : field.js

  var app = angular.module('MyApp');

  app.directive('field', function($compile, $http, $templateCache, $interpolate) {
    var templatePath = ''; 
    var findInputElement = function(element) {
  return angular.element(element.find('input')[0] || element.find('textarea')[0] || element.find('select')[0]);
    };
    return {
      restrict:'E',        
      terminal: true,       
      require: '?^form',    
      compile:function compile(element, attrs) {

        var validationMessages = [];
        angular.forEach(element.find('validator'), function(validatorElement) {
          validatorElement = angular.element(validatorElement);
          validationMessages.push({
            key: validatorElement.attr('key'),
            getMessage: $interpolate(validatorElement.text())
          });
        });

        var labelContent = '';
        if ( element.attr('label') ) {
          labelContent = element.attr('label');
          element[0].removeAttribute('label');
        }
        if ( element.find('label')[0] ) {
          labelContent = element.find('label').html();
        }
        if ( !labelContent ) {
          throw new Error('No label provided');
        }

        var template = attrs.template || 'input';   
        var getFieldElement = $http.get(templatePath + template + '.html', {cache:$templateCache}).then(function(response) {
          var newElement = angular.element(response.data);
    //console.log(response.data);
          var inputElement = findInputElement(newElement);

          angular.forEach(element[0].attributes, function (attribute) {
            var value = attribute.value;
            var key = attribute.name;
            inputElement.attr(key, value);
          });

          var labelElement = newElement.find('label');
          labelElement.html(labelContent);

          return newElement;
        });

        return function (scope, element, attrs, formController) {
          getFieldElement.then(function(newElement) {
            var childScope = scope.$new();

            childScope.$modelId = attrs.ngModel.replace('.', '_').toLowerCase() + '_' + childScope.$id;

            var inputElement = findInputElement(newElement);
            inputElement.attr('name', childScope.$modelId);
            inputElement.attr('id', childScope.$modelId);
            newElement.find('label').attr('for', childScope.$modelId);

            childScope.$validationMessages = {};
            angular.forEach(validationMessages, function(validationMessage) {
              scope.$watch(validationMessage.getMessage, function (message) {
                childScope.$validationMessages[validationMessage.key] = message;
              });
            });
   $compile(newElement)(childScope, function(clone) {
              element.after(clone);
              element.remove();
            });
   if ( formController ) {
              childScope.$form = formController;
              childScope.$field = formController[childScope.$modelId];
            }
          });
        };
      }
    };
  });



File name : submitvalid.js

  var app = angular.module('MyApp');

  app.directive('submitValid', function($parse) {
    return {
      require: 'form',
      link: function(scope, formElement, attributes, form) {
        form.attempt = false;
        formElement.bind('submit', function (event) {
          form.attempt = true;
          if (!scope.$$phase) scope.$apply();

          var fn = $parse(attributes.submitValid);

          if (form.$valid) {
     console.log(scope);
            scope.$apply(function() {
              fn(scope, {$event:event});
            });
          }
        });
      }
    };
  });

File name : input.html

<div class="control-group" ng-class="{'error' : $field.$invalid && ( $field.$dirty || $form.attempt )}"> <label class="control-label" >{{label}}</label> <div class="controls"> <input> <div ng-repeat="(key, error) in $field.$error" ng-show="error && ( $field.$dirty || $form.attempt )" class="validation-label">{{$validationMessages[key]}}</div> </div> </div>

File name : select.html

<div class="control-group" ng-class="{'error' : $field.$invalid && $field.$dirty}"> <label class="control-label">{{label}}</label> <div class="controls"> <select></select> <div ng-repeat="(key, error) in $field.$error" ng-show="error && $field.$dirty" class="validation-label">{{$validationMessages[key]}}</div> </div> </div>

File name : textarea.html

<div class="control-group" ng-class="{'error' : $field.$invalid && $field.$dirty}"> <label class="control-label">{{label}}</label> <div class="controls"> <textarea></textarea> <div ng-repeat="(key, error) in $field.$error" ng-show="error && $field.$dirty" class="validation-label">{{$validationMessages[key]}}</div> </div> </div>


Angular JS `Array Push + Pop

AngularJS Table Data display with Pagination, Sorting, Serching, and inline edit


For Example Code:

File name : index.html
<html>
 <head>
  <script src="http://code.angularjs.org/1.4.8/angular.min.js"></script> 
  <script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.11.0.js"></script> 
  <link rel="stylesheet" href="style.css"> 
                <script src="main.js"></script> 
 </head>
 <body>
  <div class="tablecenter" ng-app="app" ng-controller="editController">
      <div>
       <table>
           <thead>
               <th><a href="" ng-click="order('name')" style="font-size: 18px; text-decoration: none; color: #fff; font-weight: 600;">Name</a></th>
               <th><a href="" ng-click="order('age')" style="font-size: 18px; text-decoration: none; color: #fff; font-weight: 600;">Age</a></th>
               <th></th>
           </thead>
           <tbody>
               <tr>  
                <td><input type="text" class="textbox" ng-model="search.name" /></td>  
                <td><input type="text" class="textbox" ng-model="search.age" /> </td>
                <td></td>
              </tr> 
               <tr ng-repeat="contact in model.contacts | orderBy:predicate:reverse| filter:paginate | filter:search " ng-include="getTemplate(contact)" ng-class-odd="'odd'">
               </tr>
           </tbody>
       </table>
        <pagination total-items="totalItems" ng-model="currentPage"  
               max-size="5" boundary-links="true"  
               items-per-page="numPerPage" class="pagination-sm">  
         </pagination> 
         <select ng-model="numPerPage" class="dropdown">
              <option value="5">5</option>
              <option value="10">10</option>
              <option value="15">15</option>
              <option value="20">20</option>
         </select> 
      </div>
      <script type="text/ng-template" id="display">
          <td>{{contact.name}}</td>
          <td>{{contact.age}}</td>
          <td>
              <button class="btn btn-info" ng-click="editContact(contact)">Edit</button>
          </td>
      </script>
      <script type="text/ng-template" id="edit">
          <td><input type="text" class="textbox" ng-model="model.selected.name" /></td>
          <td><input type="text" class="textbox" ng-model="model.selected.age" /></td>
          <td>
              <button class="btn btn-info" ng-click="saveContact(model.selected.id)">Save</button>
              <button class="btn btn-info" ng-click="reset()">Cancel</button>
          </td>
      </script>
  </div>
 </body>
</html>

File name : style.css

.dropdown
{
    position: absolute;
    margin-top: 21px;
    right: 20%;
    width: 65px;
    padding: 4px;
    border: 1px solid #7E6B6B;
    border-radius: 4px;
}
.textbox
{
    background-color: rgba(53, 49, 49, 0.13);
    width: 95%;
    padding: 6px;
    border: 1px solid #000000;
    border-radius: 4px;
    color: #000;
    font-weight: 600;
    font-size: 14px;
}
.tablecenter
{
    margin-left: 20%;margin-right: 20%;
}
.btn {
    display: inline-block;
    padding: 1px 12px;
    margin-bottom: 0;
    font-size: 14px;
    font-weight: 400;
    line-height: 1.42857143;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
    cursor: pointer;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    background-image: none;
    border: 1px solid transparent;
    border-radius: 4px;
}
.btn.btn-info {
    background-color: #00c0ef;
    border-color: #00acd6;
}
table{
    border: 1px solid black;
    width: 100%;
}  
.odd {  
    background-color: rgb(215, 215, 215);
    color: #0E24BB;
}  
th{  
   height: 30px;  
   min-width: 100px;
   border: 1px solid;  
 }
 td{  
    text-align: center;
   height: 30px;  
   min-width: 100px;
   border: 1px solid;
   padding: 5px;  
 }  
 thead {  
   background-color: darkgray;  
   color: white !important;  
   height: 30px;  
 } 
.pagination{
    display:inline-block;
    padding-left:0;
    margin:20px 0;
    border-radius:4px
}
.pagination>li{
    display:inline
}
.pagination>li>a,.pagination>li>span{
    position:relative;
    float:left;padding:6px 12px;
    line-height:1.42857143;
    text-decoration:none;
    color:#428bca;
    background-color:#fff;
    border:1px solid #ddd;
    margin-left:-1px
}
.pagination>li:first-child>a,.pagination>li:first-child>span{
    margin-left:0;
    border-bottom-left-radius:4px;
    border-top-left-radius:4px
}
.pagination>li:last-child>a,.pagination>li:last-child>span{
    border-bottom-right-radius:4px;
    border-top-right-radius:4px
}
.pagination>li>a:hover,.pagination>li>span:hover,.pagination>li>a:focus,.pagination>li>span:focus{
    color:#2a6496;
    background-color:#eee;
    border-color:#ddd
}
.pagination>.active>a,.pagination>.active>span,.pagination>.active>a:hover,.pagination>.active>span:hover,.pagination>.active>a:focus,.pagination>.active>span:focus{
    z-index:2;
    color:#fff;
    background-color:#428bca;
    border-color:#428bca;
    cursor:default
}
.pagination>.disabled>span,.pagination>.disabled>span:hover,.pagination>.disabled>span:focus,.pagination>.disabled>a,.pagination>.disabled>a:hover,.pagination>.disabled>a:focus{
    color:#999;
    background-color:#fff;
    border-color:#ddd;
    cursor:not-allowed
}
.pagination-lg>li>a,.pagination-lg>li>span{padding:10px 16px;font-size:18px}.pagination-lg>li:first-child>a,.pagination-lg>li:first-child>span{
    border-bottom-left-radius:6px;
    border-top-left-radius:6px
}
.pagination-lg>li:last-child>a,.pagination-lg>li:last-child>span{
    border-bottom-right-radius:
    6px;border-top-right-radius:6px
}
.pagination-sm>li>a,.pagination-sm>li>span{
    padding:5px 10px;
    font-size:12px
}
.pagination-sm>li:first-child>a,.pagination-sm>li:first-child>span{
    border-bottom-left-radius:3px;
    border-top-left-radius:3px
}
.pagination-sm>li:last-child>a,.pagination-sm>li:last-child>span{
    border-bottom-right-radius:3px;
    border-top-right-radius:3px
}

File name : main.js

var demo = angular.module("app", ['ui.bootstrap']);
demo.controller("editController",function($scope) {
    $scope.predicate = 'name';  
    $scope.reverse = true;  
    $scope.currentPage = 1;  
    $scope.order = function (predicate) {  
        $scope.reverse = ($scope.predicate === predicate) ? !$scope.reverse : false;  
        $scope.predicate = predicate;  
    };  
    $scope.model = {
        contacts: [{id: 1, name: "Rahul", age: 28}, {id: 2, name: "Kaushik", age: 24}, 
                   {id: 3, name: "Sanjay", age: 32}, {id: 4, name: "Sagar", age: 40},
                   {id: 5, name: "Ajay", age: 28}, {id: 6, name: "Vijay", age: 24},
                   {id: 7, name: "Ketan", age: 28}, {id: 8, name: "Karan", age: 24},
                   {id: 9, name: "Gautam", age: 28}, {id: 10, name: "Heena", age: 24},
                   {id: 11, name: "Gaurang", age: 28}, {id: 12, name: "Gaurav", age: 24},
                   {id: 13, name: "Naresh", age: 28}, {id: 14, name: "Dinesh", age: 24},
                   {id: 15, name: "Suresh", age: 28}, {id: 16, name: "Mitesh", age: 24},
                   {id: 17, name: "Raman", age: 28}, {id: 18, name: "Hitesh", age: 24},
                   {id: 19, name: "Neha", age: 28}, {id: 20, name: "Sandhya", age: 24}],
        selected: {}
    };
    $scope.totalItems = $scope.model.contacts.length;  
    $scope.numPerPage = 5;
    
    $scope.paginate = function (value) {  
        var begin, end, index;  
        begin = ($scope.currentPage - 1) * $scope.numPerPage;  
        end = begin + $scope.numPerPage;  
        index = $scope.model.contacts.indexOf(value);  
        return (begin <= index && index < end);  
    };

    $scope.getTemplate = function (contact) {
        if (contact.id === $scope.model.selected.id) return 'edit';
        else return 'display';
    };

    $scope.editContact = function (contact) {
        $scope.model.selected = angular.copy(contact);
    };

    $scope.saveContact = function (idx) {
        for (var i = 0; i < $scope.model.contacts.length; i++) {
            if ($scope.model.contacts[i].id === idx) {
                $scope.model.contacts[i] = angular.copy($scope.model.selected);
                break;
            }
        }
        $scope.reset();
    };

    $scope.reset = function () {
        $scope.model.selected = {};
    };
});



AngularJS CRD Application $http + PHP


For Example Code:

File name : index.html
<html>
 <head>
  <script src="http://code.angularjs.org/1.4.8/angular.min.js"></script> 
  <script src="http://angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.11.0.js"></script> 
  <script src="main.js"></script>
 </head>
 <body ng-app="app" ng-init="getData()" ng-controller="dataCtrl" >
  <div>
   <form ng-submit="addRow()" method="post">
    <label>First Name</label>
     <div>
      <input type="text" name="firstname" ng-model="firstName" />
     </div>
    </div>
    <label>Last Name</label>
     <div>
      <input type="text" name="lastname" ng-model="lastName" />
     </div>
    </div>
    <br>
    <div>        
     <div style="padding-left:110px">
      <input type="submit" value="Submit" style="border-radius: 30px;padding: 5px 10px;"/>
     </div>
    </div>
   </form>
  </div>
  <br>
  {{message}}
<br><br>
  <div>
   <table border="1" cellpadding="5">
     <tr ng-repeat="x in users">
       <td>{{x.firstname}}</td>
       <td>{{x.lastname}}</td>
       <td><button ng-click="deleteRow(x.id)" style="border-radius: 30px;padding: 5px 10px;">Delete</button></td>
     </tr>
   </table>
  </div>
 </body>
</html>

File name : main.js

var app = angular.module("app", []);
  
app.controller("dataCtrl", ['$scope', '$http', function($scope, $http)
{
 $scope.users = [{}]; 
 $scope.addRow = function()
 {
  var firstName = $scope.firstName;
  var lastName = $scope.lastName;
  if(firstName != "")
  {
   if(lastName != "")
   {
    var dataObj = {firstName : firstName, lastName :lastName}; 
    var res = $http.post('add.php', dataObj);
    res.success(function(data) {
     var data = data;
     if(data=="1")
     {
      $scope.message="Data Added Successfully";
      $scope.getData();
     } 
     else if(data=="0")
     {
      $scope.message="Data not Added Successfully"; 
     }
    });
    res.error(function(data) {
     alert( "Error: " + JSON.stringify({data: data}));
    });  
    $scope.firstName = '';
    $scope.lastName = '';
   }
   else
   {
    $scope.message="Enter Last Name"; 
   }
  }
  else
  {
   $scope.message="Enter First Name"; 
  }
 };
 $scope.getData = function()
 {
  $http.get('get.php').then(function(response) 
  {
   console.log(response.data.records);
   $scope.users = response.data.records;
  });
 };
 $scope.deleteRow = function(id)
 {
  var dataObj = {id : id}; 
  var res = $http.post('delete.php', dataObj);
  res.success(function(data, status, headers, config) {
   var data = data;
   if(data=="1")
   {
    $scope.message="Data Delete Successfully";
    $scope.getData();
   } 
   else if(data=="0")
   {
    $scope.message="Data not Delete Successfully"; 
   }
  });
 }
}]);


File name : dbconfig.php

<?php
$mysqli = new mysqli("localhost", "root", "", "users");
?>

File name : add.php

<?php
    include("dbconfig.php");
 
    $postdata = file_get_contents("php://input");
    $request = json_decode($postdata);
    $firstName = $request->firstName;
    $lastName = $request->lastName;
    if($firstName !="" && $lastName != "")
    {
 $query="INSERT INTO `user`(`id`, `firstname`, `lastname`) VALUES (null,'".$firstName."','".$lastName."')";
 $result = $mysqli->query($query);
    if($result == 0)
 echo "0";
    else
     echo "1"; 
    }
    else
     echo "2";
?>

File name : get.php

<?php
 include("dbconfig.php");
 $query="select * from user";
 $result = $mysqli->query($query);
 $arr = array(); 
 if($result->num_rows > 0)
 {
  while($row = $result->fetch_assoc()) { $arr[] = $row; }
 }
 $ajaxdata = array("records"=>$arr);
 echo $json_response = json_encode($ajaxdata);
?>

File name : delete.php

<?php
    include("dbconfig.php");
    $postdata = file_get_contents("php://input");
    $request = json_decode($postdata);
    $id = $request->id;
    if($id !=""){
     $query="delete from `user` where `id`=".$id;
     $result = $mysqli->query($query);
         if($result == 0)
      echo "0";
         else
          echo "1"; 
    }
    else{
     echo "2";
    }
?>

Saturday 13 February 2016

Get Weather Information using Angularjs


For Example Code:

File name : index.html
<html ng-app="weatherApp">

  <head>
    <meta charset="utf-8" />
    <title></title>
   = <link rel="stylesheet" href="style.css" />
    <script src="https://code.angularjs.org/1.2.16/angular.js" data-semver="1.2.16"></script>
    <script src="http://code.jquery.com/jquery-2.0.3.min.js"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="weatherCtrl">
    <form>
      <div class="form-group">
        <input class="form-control" type="number" ng-model="zip" placeholder="e.g. 84105" />
        <input class="btn btn-default" type="submit" value="Search" ng-click="findWeather(zip)" />
      </div>
    </form>
    <p ng-show="zip">Searching the forecasts for: {{zip}}</p>
    <div>
      <h1>Forecast For {{ place.location.city }}</h1>
      <a ng-click="findWeather('84106'); zip = ''">reset</a>
      <h3><img class="img-thumbnail forecast-img" src="http://l.yimg.com/a/i/us/we/52/{{place.item.condition.code}}.gif" />Current: {{ place.item.condition.text }} | {{ place.item.condition.temp }}</h3>
      <div>
        <div  ng-repeat="forecast in place.item.forecast">
          <h4><img class="img-thumbnail forecast-img" src="http://l.yimg.com/a/i/us/we/52/{{forecast.code}}.gif" /><strong>{{ forecast.date }}</strong></h4>
              <p>{{ forecast.text }}</p>
              <p>H: {{ forecast.high }} | L: {{ forecast.low }}</p>
        </div>
      </div>
    </div>
  </body>
</html>


                

File name : style.css

/* Put your css in here */
body {
  padding: 10px;
}

a {
  cursor: pointer;
}

.form-control {
  float: left;
  margin-right: 10px;
  width: 70%;
}

.forecast-img {
  margin-right: 10px;
  width: 45px;
}

                

File name : app.js

var app = angular.module('weatherApp', []);

app.controller('weatherCtrl', ['$scope', 'weatherService', function($scope, weatherService) {
  function fetchWeather(zip) {
    weatherService.getWeather(zip).then(function(data){
      $scope.place = data;
   console.log(data);
    }); 
  }
  fetchWeather('84105');
  $scope.findWeather = function(zip) {
    $scope.place = '';
    fetchWeather(zip);
  };
}]);
app.factory('weatherService', ['$http', '$q', function ($http, $q){
  function getWeather (zip) {
    var deferred = $q.defer();
    $http.get('https://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20weather.forecast%20WHERE%20location%3D%22' + zip + '%22&format=json&diagnostics=true&callback=')
      .success(function(data){
        deferred.resolve(data.query.results.channel);
      })
      .error(function(err){
        console.log('Error retrieving markets');
        deferred.reject(err);
      });
    return deferred.promise;
  }
  return {
    getWeather: getWeather
  };
}]);


                



Create Thumbnail in Video in Spring and ffmpeg

import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; import org.jcodec.api.Fr...