Sunday, July 16, 2017

REACT


React is a declarative, efficient, and flexible JavaScript library for building user interfaces.
It's used for handling view layer for web and mobile apps. ReactJS allows us to create reusable UI components. It is currently one of the most popular JavaScript libraries and it has strong foundation and large community behind it.


React Features

  • JSX − JSX is JavaScript syntax extension. It isn't necessary to use JSX in React development, but it is recommended.
  • Components − React is all about components. 
  • Unidirectional data flow and Flux − React implements one way data flow which makes it easy to reason about our app. 
  • License − React is licensed under the Facebook Inc. 


    React Advantages

  • React uses virtual DOM which is JavaScript object. This will improve apps performance since JavaScript virtual DOM is faster than the regular DOM.
  • React can be used on client and server side.
  • Component and Data patterns improve readability which helps to maintain larger apps.

    React can be used with other frameworks.

     React JSX

    React uses JSX for templating instead of regular JavaScript. It is not necessary to use it, but there are some pros that comes with it.

  • JSX is faster because it performs optimization while compiling code to JavaScript.
  • It is also type-safe and most of the errors can be caught during compilation.
  • JSX makes it easier and faster to write templates if you are familiar with HTML.
 
import React from 'react';

class App extends React.Component {
   render() {

      var i = 1;

      return (
         <div>
            <h1>{i == 1 ? 'True!' : 'False'}</h1>
         </div>
      );
   }
}

export default App;
 
 
 
  React component
 
This component is owner of Header and Content. We are creating Header and Content separately and just adding it inside JSX tree in our App component. Only App component needs to be exported.

App.jsx

import React from 'react';

class App extends React.Component {
   render() {
      return (
         <div>
            <Header/>
            <Content/>
         </div>
      );
   }
}

class Header extends React.Component {
   render() {
      return (
         <div>
            <h1>Header</h1>
         </div>
      );
   }
}

class Content extends React.Component {
   render() {
      return (
         <div>
            <h2>Content</h2>
            <p>The content text!!!</p>
         </div>
      );
   }
}
 
React State 

State is the place where the data comes from.If we have, for example, ten components that need data 
from the state, we should create one container component that will keep
 the state for all of them.


App.jsx

import React from 'react';

class App extends React.Component {
   constructor(props) {
      super(props);
		
      this.state = {
         header: "Header from state...",
         content: "Content from state..."
      }
   }
	
   render() {
      return (
         <div>
            <h1>{this.state.header}</h1>
            <h2>{this.state.content}</h2>
         </div>
      );
   }
}

export default App;

AJAx




     AJAX stands for Asynchronous JavaScript and XML. AJAX is a new technique for creating better, faster, and more interactive web applications with the help of XML, HTML, CSS, and Java Script.

How Ajax is working?

     AJAX is a technique for creating fast and dynamic web pages. AJAX allows web pages to be updated asynchronously by exchanging small amounts of data with the server behind the scenes. This means that it is possible to update parts of a web page, without reloading the whole page.



    AJAX cannot work independently. It is used in combination with other technologies to create interactive web pages.
  • JavaScript
  • DOM
  • CSS
  • XML HttpRequest
           JavaScript object that performs asynchronous interaction with the server.

Steps of AJAX Operation

  • A client event occurs.
  • An XMLHttpRequest object is created.
  • The XMLHttpRequest object is configured.
  • The XMLHttpRequest object makes an asynchronous request to the Webserver.
  • The Webserver returns the result containing XML document.
  • The XMLHttpRequest object calls the callback() function and processes the result.
  • The HTML DOM is updated.

The XMLHttpRequest Object is Created

         The XMLHttpRequest object is the key to AJAX.

var ajaxRequest;  // The variable that makes Ajax possible!
function ajaxFunction(){
   try{
      
      // Opera 8.0+, Firefox, Safari
      ajaxRequest = new XMLHttpRequest();
   }catch (e){
   
      // Internet Explorer Browsers
      try{
         ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
      }catch (e) {
      
         try{
            ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
         }catch (e){
      
            // Something went wrong
            alert("Your browser broke!");
            return false;
         }
      }
   }
}


 jQuery  AJAX

      With the jQuery AJAX methods, you can request text, HTML, XML, or JSON from a remote server using both HTTP Get and HTTP Post - And you can load the external data directly into the selected HTML elements of your web page!

   jQuery load() Method

       The load() method loads data from a server and puts the returned data into the selected element.
 
Syntax:

$(selector).load(URL,data,callback); 
The required URL parameter specifies the URL you wish to load.

 <script>
$(document).ready(function(){
    $("button").click(function(){
        $("#div1").load("demo_test.txt #p1");
    });
});
</script>



jQuery $.get() Method

    The $.get() method requests data from the server with an HTTP GET request.

Syntax:

$.get(URL,callback);

<script>
$(document).ready(function(){
    $("button").click(function(){
        $.get("demo_test.asp", function(data, status){
            alert("Data: " + data + "\nStatus: " + status);
        });
    });
});
</script>


    jQuery $.post() Method

The $.post() method requests data from the server using an HTTP POST request.

Syntax:

$.post(URL,data,callback);

 <script>
$(document).ready(function(){
    $("button").click(function(){
        $.post("demo_test_post.asp",
        {
          name: "Donald Duck",
          city: "Duckburg"
        },
        function(data,status){
            alert("Data: " + data + "\nStatus: " + status);
        });
    });
});
</script>


Sound Cloud API


             Sounds (in the API these are called tracks) are core to SoundCloud. Sound Cloud  API give we the ability to upload, manage and share sounds on the web. our app can take an audio file and upload it to a user's SoundCloud account.
that enables its users to upload, record, promote, and share their originally-created sounds.

Mongoose


 Mongoose acts as a front end to MongoDB, an open source NoSQL database that uses a document-oriented data model. A “collection” of “documents”, in a MongoDB database, is analogous to a “table” of “rows” in a relational database.

       why we wrote Mongoose.

 var mongoose= require ('mongoose');
mongoose.connect('mongodb://localhost/test');

var cat = mongoose.model('cat', {name: string});

var kitty = new Cat({ name: 'Zildjian' });
kitty.save(function (err) {
  if (err) {
    console.log(err);
  } else {
    console.log('meow');
  }
});
 
Mongoose provides a straight-forward, schema-based solution to model your application data. It includes built-in type casting, validation, query building, business logic hooks and more, out of the box.
 

Sunday, June 18, 2017

Good Friends are like Stars









Big Data & Machine learning

   
       Today we were learning  about Big Data & Machine learning. Mr Uthayasangar (lecturer in Moraduwa university)  taught about communication, machine learning & Big Datas.

💥Machine learning




             Machine learning focuses on the development of computer programs that can change when exposed to new data. The process of machine learning is similar to that of data mining.In machine learning, computers apply statistical learning techniques to automatically identify patterns in data. These techniques can be used to make highly accurate predictions. Keep scrolling.

 ðŸ’¥What are the different types of machine learning?

     These algorithms can be applied to almost any data problem:
  • Linear Regression.
  • Logistic Regression.
  • Decision Tree.
  • SVM.
  • Naive Bayes.
  • KNN.
  • K-Means.
  • Random Forest.

    💥categorization of machine learning tasks arises when one considers the desired output of a machine-learned system


  • In classification inputs are divided into two or more classes, and the learner must produce a model that assigns unseen inputs to one or more  of these classes. This is typically tackled in a supervised way. Spam filtering is an example of classification, where the inputs are email (or other) messages and the classes are "spam" and "not spam".

  • In regression also a supervised problem, the outputs are continuous rather than discrete.

  • In clustering a set of inputs is to be divided into groups. Unlike in classification, the groups are not known beforehand, making this typically an unsupervised task.

💥What is meant by machine learning algorithms?
   Evolved from the study of pattern recognition and computational learning theory in artificial intelligence, machine learning explores the study and construction of algorithms that can learn from and make predictions on data – such algorithms overcome following strictly static program instructions by making data-driven .


💥 BIG DATA
Data which are very large in size is called Big Data. Normally we work on data of size MB(WordDoc ,Excel) or maximum GB(Movies, Codes) but data in Peta bytes i.e. 10^15 byte size is called Big Data.

💥From where this data comes from

These data come from many sources like

  • Social networking sites: Facebook, Google, LinkedIn all these sites generates huge amount of data on a day to day basis as they have billions of users worldwide.

  • E-commerce site: Sites like Amazon, Flipkart, Alibaba generates huge amount of logs from which users buying trends can be traced.

  • Weather Station: All the weather station and satellite gives very huge data which are stored and manipulated to forecast weather.

  • Telecom company: Telecom giants like Airtel, Vodafone study the user trends and accordingly publish their plans and for this they store the data of its million users.

  • Share Market: Stock exchange across the world generates huge amount of data through its daily transaction.
      💥   Hadoop is an open source framework. It is provided by Apache to process and analyze very huge volume of data. It is written in Java and currently used by Google, Facebook, LinkedIn, Yahoo, Twitter etc.
💥Communication



Communication is the act of expressing (or transmitting) ideas, information, knowledge, thoughts, and feelings, as well as understanding what is expressed by others.
💥How to Develop Good Communication Skills
  

💥How do you communicate well with others?

  1. Pause before responding. 
  2. Be trustworthy and honest. 
  3. Don't rush communication.
  4. Adapt your ideas to others. 
  5. Stay in the moment. 
  6. Pay attention to non-verbal cues. 
  7. Intend to understand. 
  8. Be patient and open-minded.

HTTP Method



          The number of HTTP methods we'll use is quite small—there are just four HTTP "verbs" we'll need to know! They are:

💢 GET: retrieves information from the specified source (you just saw this one!)

💢 POST: sends new information to the specified source.

💢 PUT: updates existing information of the specified source.

💢 DELETE: removes existing information from the specified source.

💥Endpoints
      Endpoints are API-defined locations where particular data are stored. Just as we'll GET a pair of pants from PantsWorld or we'll GET a bag of peanuts from PeanutHut, we'll GET something different depending on the endpoint we use.

💥Authentication & API Keys
     Many APIs require an API key. Just as a real-world key allows we to access something, an API key grants we access to a particular API. Moreover, an API key identifies we to the API, which helps the API provider keep track of how our service is used and prevent unauthorized or malicious activity.
Some APIs require authentication using a protocol called OAuth. We won't get into the details, but if we've ever been redirected to a page asking for permission to link an application with our account, we've probably used OAuth.

HTTP




The Hypertext Transfer Protocol (HTTP) is an application protocol for distributed, collaborative, and hypermedia information systems. HTTP is the foundation of data communication for the World Wide Web. Hypertext is structured text that uses logical links (hyperlinks) between nodes containing text.

 ðŸ’¥Why we have to use HTTP?


HTTPS is used to protect transmitted data from eavesdropping. It is the default protocol for conducting financial transactions on the web, and can protect a website's users from censorship by a government or an ISP.

💥The Client/Server Relationship


            The Internet is full of clients who ask for various resources (web pages, files, and so on), and servers, who store that information (or know where to get it). When we make an HTTP request, it zips through the Internet until it finds the server that knows how to fulfill that request. Then the server sends a response back to we.



 ðŸ’¥REST
 client/server relationship is a prerequisite of a set of principles called REST (or Representational State Transfer).

💥RESTful

        Every major development language now includes frameworks for building RESTful Web services. As such, it is important for Web developers and architects to have a clear understanding of REST and RESTful services.
          A service based on REST is called a RESTful service. REST is not dependent on any protocol, but almost every RESTful service uses HTTP as its underlying protocol.

         A RESTful design promises that and more. In general, RESTful services should have following properties and features.
  • Representations
  • Messages
  • URIs
  • Uniform interface
  • Stateless
  • Links between resources
  • Caching

 ðŸ’¥An API or web service to be RESTful, it must do the following: 

👱Separate the client from the server  

👱Not hold state between requests (meaning that all the information necessary to respond to a request is available in each individual request; no data, or state, is held by the server from request to request) 

👱Use HTTP and HTTP methods (as explained in the next section).



💥Request & Response

     Clients send a request to the server, and the server replies with a response. Apart from the actual data, these messages also contain some metadata about the message. It is important to have some background about the HTTP 1.1 request and response formats for designing RESTful Web services.

Example:
 


      



Host: www.w3.org
Accept: text/html,application/xhtml+xml,application/xml; …
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 …
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8,hi;q=0.6
 
  HTTP request
 


<VERB> is one of the HTTP methods like GET, PUT, POST, DELETE, OPTIONS, etc 

<URI> is the URI of the resource on which the operation is going to be performed 

<HTTP Version> is the version of HTTP, generally "HTTP v1.1" .

<Request Header> contains the metadata as a collection of key-value pairs of headers and their values. These settings contain information about the message and its sender like client type, the formats client supports, format type of the message body, cache settings for the response, and a lot more information. 

<Request Body> is the actual message content. In a RESTful service, that's where the representations of resources sit in a message.

 HTTP response

HTTP/1.1 200 OK
Date: Sat, 23 Aug 2014 18:31:04 GMT
Server: Apache/2
Last-Modified: Wed, 01 Sep 2004 13:24:52 GMT
Accept-Ranges: bytes
Content-Length: 32859
Cache-Control: max-age=21600, must-revalidate
Expires: Sun, 24 Aug 2014 00:31:04 GMT
Content-Type: text/html; charset=iso-8859-1


 HTTP response:




The server returns <response code>, which contains the status of the request. This response code is generally the 3-degits HTTP status code.

<Response Header> contains the metadata and settings about the response message.

<Response Body> contains the representation if the request was successful.