Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Thursday, August 26, 2021

Saas

Software AS A Service(SAAS)

Software as a service (SaaS) is a model for the distribution of software where customers access software over the Internet. In SaaS, a service provider hosts the application at its data center and a customer accesses it via a standard web browser.

There are a few major characteristics that apply to most SaaS vendors:
Updates are applied automatically without customer intervention
The service is purchased on a subscription basis
No hardware is required to be installed by the customer

Why we use Saas?

SaaS offers significant benefits for organizations. Firstly, organizations don’t need an initial investment for hardware, as the processing power is supplied by the cloud provider. Likewise, there are no initial setup costs. The scalability features allow you to scale up resources on demand. You can provide privilege-based access by customizing settings. You don’t have to worry about updates or patches, and maintenance is handled by the cloud provider. As the applications are centrally hosted and remotely delivered to devices, you can access resources from any location and at any time. Most importantly, you can use any device to access resources.


Advantages of Sass:

  • It allows writing clean CSS in a programming construct.
  • It helps in writing CSS quickly.
  • It is a superset of CSS, which helps designers and developers work more efficiently and quickly.
  • As Sass is compatible with all versions of CSS, we can use any available CSS libraries.
  • It is possible to use nested syntax and useful functions such as color manipulation, mathematics and other values.



 

PHP

 PHP is a server scripting language and a powerful tool for making dynamic and interactive Web pages.

PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.

PHP 7 is the latest stable release.



<!DOCTYPE html>
<html>
<body>

<?php
echo "My first PHP script!";
?>

</body>
</html>






What is PHP?

PHP is an acronym for "PHP: Hypertext Preprocessor"
PHP is a widely-used, open source scripting language
PHP scripts are executed on the server
PHP is free to download and use

What is a PHP File?

PHP files can contain text, HTML, CSS, JavaScript, and PHP code

PHP code is executed on the server, and the result is returned to the browser as plain HTML

PHP files have extension ".php


What Can PHP Do?

PHP can generate dynamic page content
PHP can create, open, read, write, delete, and close files on the server
PHP can collect form data
PHP can send and receive cookies
PHP can add, delete, modify data in your database
PHP can be used to control user-access
PHP can encrypt data

Why PHP?

  • PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.)
  • PHP is compatible with almost all servers used today (Apache, IIS, etc.)
  • PHP supports a wide range of databases
  • PHP is free. Download it from the official PHP resource: www.php.net
  • PHP is easy to learn and runs efficiently on the server-side



Sunday, July 14, 2019

JSON





  • JSON: JavaScript Object Notation.
  • JSON is a syntax for storing and exchanging data.
  • JSON is text, written with JavaScript object notationJSON


The JSON object, available in all modern browsers, has two very useful methods to deal with JSON-formatted content: parse and stringify. JSON.parse() takes a JSON string and transforms it into a JavaScript object. JSON.stringify() takes a JavaScript object and transforms it into a JSON string.


  1. When exchanging data between a browser and a server, the data can only be text.
  2. And we can convert any JavaScript object into JSON, and send JSON to the server.
  3. We can also convert any JSON received from the server into JavaScript objects.
  4. This way we can work with the data as JavaScript objects, with no complicated parsing and translations.

convert to JSON :-

const myObj = {
 name: 'Skip',
 age: 2,
 favoriteFood: 'Steak'
};
const myObjStr = JSON.stringify(myObj);
console.log(myObjStr);
// "{"name":"Skip","age":2,"favoriteFood":"Steak"}"
console.log(JSON.parse(myObjStr));
// Object {name:"Skip",age:2,favoriteFood:"Steak"}


Sending Data:-
If you have data stored in a JavaScript object, you can convert the object into JSON, and send it to a server:

var myObj = {name: "John", age: 31, city: "New York"};
var myJSON = JSON.stringify(myObj);
window.location = "demo_json.php?x=" + myJSON;

 Recieving Data:-

If you receive data in JSON format, you can convert it into a JavaScript object:

var myJSON = '{"name":"John", "age":31, "city":"New York"}';
var myObj = JSON.parse(myJSON);
document.getElementById("demo").innerHTML = myObj.name;
 Storing Data:-

When storing data, the data has to be a certain format, and regardless of where you choose to store it, the text is always one of the legal formats.
JSON makes it possible to store JavaScript objects as text.
// Storing data:
myObj = {name: "John", age: 31, city: "New York"};
myJSON = JSON.stringify(myObj);
localStorage.setItem("testJSON", myJSON);

// Retrieving data:
text = localStorage.getItem("testJSON");
obj = JSON.parse(text);
document.getElementById("demo").innerHTML = obj.name;

Why use JSON?

Since the JSON format is text only, it can easily be sent to and from a server, and used as a data format by any programming language.

JavaScript has a built in function to convert a string, written in JSON format, into native JavaScript objects:

JSON.parse()

So, if you receive data from a server, in JSON format, you can use it like any other JavaScript object.


What is JSON?

JSON stands for JavaScript Object Notation
JSON is a lightweight data-interchange format
JSON is "self-describing" and easy to understand
JSON is language independent

JSON Values

In JSON, values must be one of the following data types:


  • a string
  • a number
  • an object (JSON object)
  • an array
  • a boolean
  • null


In JavaScript, values can be all of the above, plus any other valid JavaScript expression, including:

a function
a date
undefined

In JSON, string values must be

In jSON:- { "name":"John" }
In js  :- { name:'John' }


JSON Uses JavaScript Syntax

Because JSON syntax is derived from JavaScript object notation, very little extra software is needed to work with JSON within JavaScript.

With JavaScript you can create an object and assign data to it, like this:

var person = { name: "John", age: 31, city: "New York" };

The same way JavaScript objects can be used as JSON, JavaScript arrays can also be used as JSON.

JSON.Parse() 
A common use of JSON is to exchange data to/from a web server.
When receiving data from a web server, the data is always a string.
Parse the data with JSON.parse(), and the data becomes a JavaScript object.



JSON From the Server
You can request JSON from the server by using an AJAX request

As long as the response from the server is written in JSON format, you can parse the string into a JavaScript object.

EX:
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
    var myObj = JSON.parse(this.responseText);
    document.getElementById("demo").innerHTML = myObj.name;
  }
};
xmlhttp.open("GET""json_demo.txt"true);
xmlhttp.send();



Parsing Dates

Date objects are not allowed in JSON.

If you need to include a date, write it as a string.

You can convert it back into a date object ter:


Parsing Functions

Functions are not allowed in JSON.

If you need to include a function, write it as a string.

You can convert it back into a function later:

JSON.Stringify()
A common use of JSON is to exchange data to/from a web server.

When sending data to a web server, the data has to be a string.

Convert a JavaScript object into a string with JSON.stringify()

JSON.OBJECT


JSON objects are surrounded by curly braces {}.

JSON objects are written in key/value pairs.

Keys must be strings, and values must be a valid JSON data type (string, number, object, array, boolean or null).

Keys and values are separated by a colon.

Each key/value pair is separated by a comma.


myObj = "name":"John""age":30"car":null };
x = myObj.name;

Arrays as JSON objects


Arrays in JSON are almost the same as arrays in JavaScript.

In JSON, array values must be of type string, number, object, array, boolean or null.

In JavaScript, array values can be all of the above, plus any other valid JavaScript expression, including functions, dates, and undefined.

{
"name":"John",
"age":30,
"cars":[ "Ford""BMW""Fiat" ]
}

JSON PHP

A common use of JSON is to read data from a web server, and display the data in a web page.

This chapter will teach you how to exchange JSON data between the client and a PHP server.

PHP has some built-in functions to handle JSON.

Objects in PHP can be converted into JSON by using the PHP function json_encode():


Saturday, July 6, 2019

JQuery

Image result for Jquery
jQuery is a JavaScript Library.  jQuery greatly simplifies JavaScript programming. 

What is jQuery?
jQuery is a lightweight, "write less, do more", JavaScript library.
The purpose of jQuery is to make it much easier to use JavaScript on your website.
jQuery takes a lot of common tasks that require many lines of JavaScript code to accomplish, and wraps them into methods that you can call with a single line of code.
jQuery also simplifies a lot of the complicated things from JavaScript, like AJAX calls and DOM manipulation

The jQuery library contains the following features:

  • HTML/DOM manipulation
  • CSS manipulation
  • HTML event methods
  • Effects and animations
  • AJAX
  • Utilities

Why jQuery?
There are lots of other JavaScript frameworks out there, but jQuery seems to be the most popular, and also the most extendable.


Many of the biggest companies on the Web use jQuery, such as:

  1. Google
  2. Microsoft
  3. IBM
  4. Netflix

There are several ways to start using jQuery on your web site. You can:

  • Download the jQuery library from jQuery.com
  • Include jQuery from a CDN, like Google

 jQuery from a CDN

<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>


jQuery Syntax

The jQuery syntax is tailor-made for selecting HTML elements and performing some action on the element(s).
Basic syntax is: $(selector).action()

  • A $ sign to define/access jQuery
  • A (selector) to "query (or find)" HTML elements
  • A jQuery action() to be performed on the element(s)Examples:
  1. $(this).hide() - hides the current element.
  2. $("p").hide() - hides all <p> elements.
  3. $(".test").hide() - hides all elements with class="test".
  4. $("#test").hide() - hides the element with id="test"

MongoDB

Image result for mongodb



What is MongoDB-----:-

MongoDB is a document database with the scalability and flexibility that you want with the querying and indexing that you need

⧫    MongoDB stores data in flexible, JSON-like documents, meaning fields can vary from document to document and data structure can be changed over time

⧫ The document model maps to the objects in your application code, making data easy to work with

⧫ You can make developments easily


Why Use MongoDB?

📄  Document Oriented Storage − Data is stored in the form of JSON style documents.

📄  Index on any attribute

📄  Replication and high availability

📄  Auto-sharding

📄  Rich queries

📄  Fast in-place updates

📄  Professional support by MongoDB

Where to Use MongoDB?

  • Big Data
  • Content Management and Delivery
  • Mobile and Social Infrastructure
  • User Data Management
  • Data Hub

In sql data save as table Mongodb saves as collections.










Basic Commands for the MongoDB

Installation Commands (Ubuntu) :

#1
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4


#2
echo "deb [ arch=amd64 ] http://repo.mongodb.com/apt/ubuntu bionic/mongodb-enterprise/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list

#3
sudo apt-get update

#4
sudo apt-get install -y mongodb-enterprise


How to Start 




#Step 1: Start MongoDB  .
sudo service mongodb start
 #Stop MongoDB
sudo service mongodb stop
#  To Start the Server
sudo mongo
# To Start the Client
sudo mongod



Basic Commands 



1. Finding the current database you’re in 

db 

2. Listing databases

Show dbs



3. Go to a particular database
use Database_name

4. Creating a Database
use Database_name     :- use command used for both action

5. Creating a Collection
db.createCollection("myCollection")


6. Inserting Data
db.myCollection.insert({"name": "john", "age" : 22, "location": "colombo"})
 db.myCollection.insertOne(i      {       "name": "navindu",        "age": 22      })
 db.myCollection.insertMany([      {        "name": "navindu",         "age": 22      },         {        "name": "kavindu",  "age": 20      },    { "name": "john doe",  "age": 25,        "location": "colombo"}     ])
7. Querying Data
db.myCollection.find()
 db.myCollection.find().pretty()

8. Updating documents
db.myCollection.update({age : 20}, {$set: {age: 23}})
db.myCollection.update({name: "navindu"}, {$unset: age});

9. Removing a document
db.myCollection.remove({name: "navindu"});

10. Removing a collection
db.myCollection.remove({});




Some  Funtions















Connecting method With Database and server



Image result for mongodb

Thursday, July 4, 2019

            Nodejs                                    
 

↦Node.js is an open-source server environment
↦Node.js allows you to run JavaScript on the server.

Its help to the user to connect the server and Database  likely it works as an intermediate

 A lot of youth aspires to be a most sought after software developer and so goes on to learn the required programming skills to match to the current market and industrial needs. They have broadly two choices to make
To Be A Front-End Developer
To Be A Back-end Developer.

Node js is a backend develop language. if you want to become a Back-end Developer so you have to study this. It's really hard but if you study hard you will get it soon.

This server-side application directly interacts with the database via an application programming interface (API), which pulls, saves, or changes data.
 Node.js which is the most sought after backend scripting language in the current technology market and is becoming the preferred language options for back-end programmers.

Node.js an asynchronous event-driven JavaScript runtime, which is designed to build scalable network applications. It can handle many concurrent connections at a time, where when connection request are made concurrently for each connection a callback is fired. If there is no task to be performed Node will go to sleep.

History of Node.js

Node.js was first conceived in 2009 by Ryan Dahl and was developed and maintained by Ryan which then got sponsored and supported by Joyent. Dahl was not happy the way Apache Http server used to handle a lot of concurrent connections and the way code was being created which either blocked the entire process or implied multiple execution stacks in the case of simultaneous connections. This leads him to create a Node.js project which he went on to demonstrate at the inaugural European JSConf on November 8, 2009. He used Google Google’s V8 JavaScript engine, an event loop, and a low-level I/O API in his project which won lots of hearts and a standing ovation.

Here is how Node.js handles a file request:


  1. Sends the task to the computer's file system.
  2. Ready to handle the next request.
  3. When the file system has opened and read the file, the server returns the content to the client.
What Can Node.js Do?

  1. Node.js can generate dynamic page content
  2. Node.js can create, open, read, write, delete, and close files on the server
  3. Node.js can collect form data
  4. Node.js can add, delete, modify data in your database.

How to install Node.js on ubuntu

Step #1:
sudo apt-get update

Step #2:
sudo apt-get install build-essential libssl-dev

Step #3:
sudo curl https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

Step #4 (if no curl):
sudo apt-get install curl
https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh | bash

Step #4:
source ~/.profile

Step #5:
nvm --version

Step #6:
nvm install 6.16.0

Step #7:
nvm ls

Step #8:
node --version

Step #9:
npm --version

to install nodemon
:--npm install -g nodemon


                            


Basic commands  for the Nodejs

exports.log =               {
    console: function(msg)  {
        console.log(msg);  },
    file: function(msg)     {
        // log to file here }
                            }
to export module for define by user

some modules:
http               :   http includes classes, methods  to create Node.js http server.
url                 :   url module includes methods for URL resolution and parsing.
querystring   :  querystring module includes methods to deal with query string.
path              :   path module includes methods to deal with file paths.
fs                  :     fs module includes classes, methods, and events to work with file I/O.
util                :   util module includes utility functions useful for programmers.


to create server:

var http = require('http');         // 1 - Import Node.js core module

var server = http.createServer(function (req, res) { } );   
 // 2 - creating server //handle incomming requests here..

Url module:

var url = require('url');
var adr = 'http://localhost:8080/default.htm?year=2017&month=february';
var q = url.parse(adr, true);

console.log(q.host);             //returns 'localhost:8080'
console.log(q.pathname);    //returns '/default.htm'
console.log(q.search);         //returns '?year=2017&month=february'

var qdata = q.query;            //returns an object: { year: 2017, month: 'february' }

console.log(qdata.month); //returns 'february'



Saturday, June 15, 2019

Javascript


Java script is used to programme the behaviour of the website. Its easy to handling and a developer should learn this language.

What is javascript? 
Javascript is a scripting language, mostly used on the web. It's used to increase HTML pages.
commonly found in embedded in Html code. Javascript an interpreted language. Thus, it doesn't
need to be compiled. Javascript renders the web pages by interactive and dynamic fashion.
This allowing the pages to react to events, exhibit special effects, accept variable text, validate data, detect user's browsers.etc.

Many desktop and server programs use JavaScript. Node.js is the best known. Some databases, like MongoDB and CouchDB, also use JavaScript as their programming language.

What can do javascript for u
☝ Javascript is very easy to implement. All you need to do is put your code in the HTML document and tell the browser that is javascript.

☝ Javascript work on a web users computer - even when they are offline.  Javascript allows you to create highly responsive interfaces that improve the user experience


 JavaScript can load content into the document if and when the user needs it, without reloading the entire page


☝ JavaScript can test for what is possible in your browser and react accordingly 

Uses of javascript

👉 Web development
👉 Web applications
👉 Presentations
👉 Server application
👉 Web servers 
👉 Games
👉 Arts
👉 Smartwatch applications
👉 mobile applications
👉 Flying Robots

Javascript must be inserted between <script>and </script> tags 

In javascript we can display data in different ways;

  1. Writing into an HTML element, using innerHTML.
  2. Writting into the html output using document.write()
  3. Writting into an html alert box , window.alert()
  4. Writting into a browser console , console.log()
mostly innerHTML  is used to call the functions.

<script>
document.getElementById("demo").innerHTML = 5 + 6;
</script>

Javascript statements
A list of instructions is to be executed by a computer is called"Computer Programme"
That the programming instructions are called Statements.
<script>
var a ,b,c;
a=5;
b=4;
c=a+b
</script>


script>
var x, y;
x = 5 + 6;
y = x * 10;
document.getElementById("demo").innerHTML = y;

</script>




in programming, just like in algebra, we use variables (like price1) to hold values.

In programming, just like in algebra, we use variables in expressions (total = price1 + price2).

From the example above, you can calculate the total to be 11.


JavaScript Identifiers

All JavaScript variables must be identified with unique names.

These unique names are called identifiers.

Identifiers can be short names (like x and y) or more descriptive names (age, sum, total volume).

The general rules for constructing names for variables (unique identifiers) are:

Names can contain letters, digits, underscores, and dollar signs.
Names must begin with a letter
Names can also begin with $ and _ (but we will not use it in this tutorial)
Names are case sensitive (y and Y are different variables)

Reserved words (like JavaScript keywords) cannot be used as names

Value = undefined
In computer programs, variables are often declared without a value. The value can be something that has to be calculated or something that will be provided later, like user input.

A variable declared without a value will have the value undefined.

The variable carName will have the value undefined after the execution of this statement:


<script>
var carName;
document.getElementById("demo").innerHTML = carName;

</script>

Arithmetic operators

Operator   Description
   
+ Addition
- Subtraction
* Multiplication
**             Exponentiation (ES2016)
/ Division
% Modulus (Division Remainder)
++ Increment
-- Decrement


Comparition Operator

Operator  Description

==             equal to

===           equal value and equal type

!=              not equal

!==            not equal value or not equal type

>               greater than

<               less than

>=             greater than or equal to

<=             less than or equal to

?               ternary operato

<script>
var a = 3;
var x = (100 + 50) * a;
document.getElementById("demo").innerHTML = x;
</script>
out put:450


JavaScript variables can hold many data types: numbers, strings, objects and more:

JavaScript Arrays
JavaScript arrays are written with square brackets.

Array items are separated by commas.

The following code declares (creates) an array called cars, containing three items (car names):
<script>
var cars = ["Saab","Volvo","BMW"];
document.getElementById("demo").innerHTML = cars[0];
</script>


Java script Functions

A JavaScript function is a block of code designed to perform a particular task.

A JavaScript function is executed when "something" invokes it (calls it).


<script>
function myFunction(p1, p2) {
 return p1 * p2;
}
document.getElementById("demo").innerHTML = myFunction(4, 3);
</script>


JavaScript Function Syntax
A JavaScript function is defined with the function keyword, followed by a name, followed by parentheses ().

Function names can contain letters, digits, underscores, and dollar signs (same rules as variables).

The parentheses may include parameter names separated by commas:
(parameter1, parameter2, ...)

The code to be executed, by the function, is placed inside curly brackets: {}

  • Function parameters are listed inside the parentheses () in the function definition.
  • Function arguments are the values received by the function when it is invoked.
  • Inside the function, the arguments (the parameters) behave as local variables.


Function Invocation
The code inside the function will execute when "something" invokes (calls) the function:

  • When an event occurs (when a user clicks a button)
  • When it is invoked (called) from JavaScript code
  • Automatically (self invoked)

You will learn a lot more about function invocation later in this tutorial.


Function Return
When JavaScript reaches a return statement, the function will stop executing.

If the function was invoked from a statement, JavaScript will "return" to execute the code after the invoking statement.

Functions often compute a return value. The return value is "returned" back to the "caller":


<script>
var x = myFunction(4, 3);
document.getElementById("demo").innerHTML = x;

function myFunction(a, b) {
  return a * b;
}
</script>

Objects

Objects can also have methods.

Methods are actions that can be performed on objects.

Methods are stored in properties as function definitions.

Var person = {
 firstName: "John",
 lastName : "Doe",
 id       : 5566,
 fullName : function() {
   return this.firstName + " " + this.lastName;
 }
};


The this Keyword


In a function definition, this refers to the "owner" of the function.

In the example above, this is the person object that "owns" the fullName function.

In other words, this.firstName means the firstName property of this object.

JavaScript Events

HTML events are "things" that happen to HTML elements.

When JavaScript is used in HTML pages, JavaScript can "react" on these events.

HTML Events


An HTML event can be something the browser does, or something a user does.

Here are some examples of HTML events:
  • An HTML web page has finished loading
  • An HTML input field was changed
  • An HTML button was clicked

Often, when events happen, you may want to do something.

JavaScript lets you execute code when events are detected.

HTML allows event handler attributes, with JavaScript code, to be added to HTML elements.


Event                Description
onchange         An HTML element has been changed
onclick              The user clicks an HTML element
onmouseover   The user moves the mouse over an HTML element
onmouseout     The user moves the mouse away from an HTML element
onkeydown       The user pushes a keyboard key
onload              The browser has finished loading the page



String Methods and Properties

Primitive values, like "John Doe", cannot have properties or methods (because they are not objects).

But with JavaScript, methods and properties are also available to primitive values, because JavaScript treats primitive values as objects when executing methods and properties.

String Length

Finding a String in a String

Searching for a String in a String

Extracting String Parts
  • slice(start, end)
  • substring(start, end)
  • substr(start, length)
Replacing String Content

Converting to Upper and Lower Case

The concat() Method

String.trim()

Extracting String Characters
  • charAt(position)
  • charCodeAt(position)
  • Property access [ ]
Converting a String to an Array








Express

In this tutorial, we will also have a look at the express framework. This framework is built in such a way that it acts as a minimal an...