Ruby Course – Worldwideasy – 04

Ruby lesson 4. I will focus on Getting Control Statements (IF statement, Case Expressions, loops), Comments, and File Control. It can provide extensive knowledge.

Control Statements

A control statement is a statement that determines whether other statements are active. If a statement decides whether another statement should be executed, or one of the two statements to be executed. A loop determines the number of times another expression should be executed.

Basically have 3 control statement

  • IF
  • Switch
  • Loops

IF Statement in Ruby

If a statement is used to check the condition, it can be a condition or more. The special feature of it is that you can check any gap. The following example will make it clear to you.

ismale = false 
if ismale
   puts "you are male"
else
   puts "you are not male"
end

This Code output is you are not male.

Case Expressions

The Case Expressions is used to check several non-gap conditions. This works very fast and gets the idea below

def get_day_name(day)
day_name=" "

case day
when "mon"
day_name = "Monday"
when "tue"
day_name = "Tuesday"
when "wed"
day_name = "Wednesday"
when "tur"
day_name = "Thursday"
when "fri"
day_name = "Friday"
when "sat"
day_name = "Saturday"
when "sun"
day_name = "Sunday"
else
day_name = "Invalid"
end
return day_name
end
puts get_day_name("wed")

This code output is Wednesday.

Loops

Loops have main 3 loops in php

  • For loop
  • While loop

Now I show the First 3 loops using Code. See Below all code output is the same. output is : 1,2,3,4,5,6,7,8,9,10.

For Loop with Arry

num = [1,2,3,4,5,6,7,8,9,10]
for num in num 
puts num
end

While Loop

index = 1
while index < 8
puts index 
index + = 1
end

Ruby Comment

Comments are a special character in programming.

# single line comment
= multiline
  comment =

File Control using Ruby

Here we show you how to handle files without opening them. see below

Reading File
file.open("test.txt",r) do |tile|
puts file.read
end
Write File
File.open("employee.txt","a") do |file|
file.write ("sanka")
end
Create File
File.open ("index.html","w") do |file|
file.write("<h1>Hello</h1>")
end
Read and Write
File.open ("employee.txt","rt") do |file|
file.readline()
file.write ("overridden")
end

Class & Object

Class is collection of objects and functions. In computer programming, a function object is a construct that allows an object with the same syntax to be called or called a normal function. Active objects are often referred to as funksters.

This is the mining of the object and class. now we can try to add it ruby. look below example.

class Book
attr_accessor :title, :author, :pages
end

book1 = Book.new()
book1.title = "Harry Potter"
book1.auther = "JK"
book1.pages = 400
puts book1.pages

Output is 4000.

Method

See the below example. that use code reuses it easy for developing softwares.

Class
attr_accessor:name, :major, :gpa
def initialize (name,major,gpa)
@ name = name
@ major = major
@ gpa = gpa
end
end
student1 = student.new ("harry","bio","3.6")
student2 = student.new ("jhone","chem","2.1")

puts.student1.name

Output is harried.

Create a Ruby 2D Game

First, install ruby 2d gem. open cmd

gem install ruby2d

Click Here to get the Source code.

you can see the below output in-game.

Now over the Ruby basic course. you go to this link and answer the question and get a Ruby certificate. Get Certificate

Thank you for all!

More Ruby ClickHere!

See you Next Lesson Soon!

Ruby Course – Worldwideasy – 03

Ruby Programming lesson 3. Today we going to learn more about it. Today I will focus on Getting User Input, Hashes, Method and If Statement. Finally, Create a simple Calculator. It can provide extensive knowledge.

Getting User Input in Ruby Programming

Uses any computer language user input is how Ruby does it. But it happens here in a very different way. We are focusing on that step by step.

First, you need to install Platformio-ide-terminal on Atom text editor.

  1. Go Settings
  2. >> install
  3. Search “Platformio-ide-terminal”
  4. Install it
  5. Search “Ruby Ide” and install it

The code below explains it to you.

puts "Enter Name "
name = gets
puts ("hello" + name)

Run using CMD this code output is hello with your entered name. see below another example

puts "Enter Your Name: "
name = gets.chomp()
puts "Enter Your Age: "
age = gets.chomp()
puts ("hello" + name + "you are " +age)

Hashes in Ruby Programming

A hash function is any function that can be used to map data of arbitrary size to fixed-size values. The values ​​given by a hash function are called hash values, hash codes, digests, or simply hashes. Values ​​are used to index a fixed-size table called a hash table.

Hashes are used to shorten a word or line of words and make it very easy to code. The following example illustrates this for you.

New York >> NY
Sri Lanka >> SL
Hello World >> HW 

As mentioned above, those words are short but the output is long.

Method

Object-oriented programming is a method of action related to a message and an object. An object consists of data and behaviors; These have an interface that specifies how the object can be used by its various customers.

You have an understanding of the method Now let us see how to use this for ruby

def sayhi
  puts "Hello user"
end

puts 'top'
sayhi
puts 'bottom'

see below code output

Output

Another example

def sayhi (name)
  puts ("Hi " + name)
end

sayhi ("harry")

This Code Output is Hi harry

Create Calculator Using Ruby

We create a very good Calculator based on the knowledge we have learned about ruby ​​so far. Here you also have to learn about if

puts "Enter First Number : "
num1 = gets.chomp().to_f
puts "Enter Opartor : "
op = gets.chomp()
puts "Second Number : "
num2 = gets.chomp().to_f

if op == '+'
  puts (num1 + num2)
else if op == "-"
  puts (num1 - num2)
else if op == "*"
  puts (num1 * num2)
else if op == "/"
  puts (num1 / num2)
else
  puts "invalid Enter"
end

Here you can input two numbers as output and select an operator and perform some action

Thank you for all!

More Ruby ClickHere!

See you Next Ruby Lesson Soon!

Ruby Course – Worldwideasy – 02

Ruby programming lesson 2. Today we going to learn more about Ruby. In this tutorial, we will focus on variables, Strings, Numbers, and Operations. It can provide extensive knowledge.

Use Variable

Variables are used to store information to be referenced and manipulated in a computer program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information. Their sole purpose is to label and store data in memory. This data can then be used throughout your program.

launchschool.com

Now you know what is variable, let’s use it Ruby Programming

character_name = "jenny"
character_age = "23"
puts "my name is "+ character_name
puts "my age is "+ character_age

This Code output is My Name is jenny my age is 23. you can try this code in your pc.

Working with Strings Ruby Programming

Threads are traditionally alphabetical. Now you can see how it works. see the below table and get an idea about ruby strings.

Phone = "Apple Iphone"
CodeOutput
puts Phone.upcaseAPPLE IPHONE
puts Phone.downcaseApple iPhone
puts Phone.stripApple iPhone
puts Phone.length12
puts Phone.include?"Apple"true
puts Phone.include?"cake"false
puts Phone.[3,5]le Ip
puts "hp".upcase()HP

Work with Strings

Working With Numbers

Every computer language uses numbers in particular. This is because it allows you to easily control the data. let me show you how to work with numbers in Ruby.

SyntaxCode
puts -5.43215-5.43215
puts 5+914
puts 5/90
puts 2*36
puts 2**38
puts 10%31
puts 5-23

Operations & Math in Ruby Programming

In mathematics, we use different operations, i.e. maximum value, square root, fall. They are also used differently in programming. The following example will give you a broader understanding.

Operations
num = 30.67
CodeOutput
puts num.abs()30.67
puts num.round()30
puts num.ceil()31
puts num.floor()30

Operations

Math

it is a hard mathematics part but using ruby we can do it easily. see below table.

SyntaxOutput
puts Math.sqrt (2)1.4142135623730951
puts Math.log (2)0.6931471805599453

Math

Now you have developed some knowledge about Ruby. Try typing this code on your computer as well. Practice

Thank you for all!

More Ruby ClickHere!

See you Next Ruby Lesson Soon!

Ruby Course – Worldwideasy – 01

Ruby programing is a defined, high-level, general-purpose programming language. It was designed and developed by Yukihiro “Mats” Matsumoto of Japan in the mid-1990s. is dynamically typed and uses garbage collection.

Ruby programming is a high-level programming language. The implementation language here is c. This was created in 1995 by Yukihiro Matsumoto. The file extension here is .rb. Editors used for this are Atom, Komodo IDE, and RubyMine. This language is a language that can do all the work of web design & software development. Let us now learn about this step by step.

How to install Ruby in your pc!(Windows).

  1. First Download & Install Atom Editor.
  2. Open Atom.exe
  3. Find head bar >> Packages >> Settings View >> Install Package.
  4. Now search bar search “Atom-runner.
  5. And install this package close Atom.
  6. Download Ruby Pack.
  7. Install base install.
  8. Check installation
    1. open cmd
    2. type ruby -v
    3. you can see ruby version.

Ruby Frameworks

What is the framework? This is software. This helps to make the website easier. It has more options to easily develop any program. has web services, web resources, and web APIs. It helps us to develop a good website. But to work with Ruby Framework you need to have a basic knowledge of Ruby. See below its top 10 frames in 2020.

  1. Ruby on Rails
  2. Sinatra
  3. Padrino
  4. Hanami
  5. NYNY
  6. Scorched
  7. Hobbit
  8. Cuba
  9. Crepe
  10. Nancy

I recommend developing using Ruby on Rails and Sinatra is good. I put a link below you can go its site,

How to Make First Ruby File

Hello World

  • First Open Atom Editor.
  • This language is similar to Python and R. No blocks.
  • Ruby have 2 main text output method it is puts or print you can use both of them.
  • Special Ruby code line end not use semicolon ( ; ).
  • See below full code of hello world in Ruby,
print "Hello "
puts "World"
  • Save now (ctrl + s)
  • Run code (alt + r)
  • You can see below output Hello World.

Thank you for all!

More Ruby ClickHere!

See you Next Ruby Lesson Soon!

Php Course – Worldwideasy – 05

php lesson 5. I will focus on Class, Construct, Object, getter, setters, and Inheritance. Finally, we can complete today’s php basic course.

Php Class

Class is collection of objects and functions.

This is simple mining for the class. We find a class in object-oriented programming. The use of this concept revolutionized the software development industry. This made it possible to create very fast software with a small amount of code. The specialty here is the ability to reuse code. Let’s see how to use it for php. The following example shows how to declare and execute a class.

<?php
class Book {
var $name;
var $author;
var $price;               //class assing
}
$book1 = new book;
$book1 = name = "Harry Potter";
$book1 = price = "1700";          //make objects
$book1 = author = "JK";

echo $book1 -> name;
echo $book1 -> price;
?>

This code output is Harry Potter 1700.

Constructor

In class-based object-oriented programming, a constructor is a special type of subroutine called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables

You can get a good idea using the following example about php constructor.

<?php
class Book{
var $name;
var $price;
var $author;
function__construct(){
echo"this is book<br>";
}
}
$book1 = new Book;
$book2 = new Book;
?>

This code output is is book two-time print.

Object and Functions

In computer programming, a function object is a construct that allows an object with the same syntax to be called or called a normal function. Active objects are often referred to as funksters.

This is the mining of the object and functions. now we can try to add it php. look below example.

<?php
class student {
var $name;
var $stream;
var $gpa;
 function__construct ($name,$stream,$gpa){
$this->name = $name;
$this->stream = $stream;
$this->gpa = $gpa;
}
function hasHonors(){
if ($this->gpa>2.5){
return "true";
}
else{
return "false";
}
}
}
$student1 = new student ("jane","Maths","3.2");
$student2 = new student ("mick","Biology","2.4");

echo $student1 -> hasHonors();
echo $student2 -> hasHonors();
?>

This code answer is truly false.

Getters and Setters

get create a function function getRating(){}

using if statement function setRating($rating)

Private can not be changed. The public can be change.

Inheritance

Object-oriented programming, inheritance, is the mechanism by which an object or class retains a similar function based on another object or class. Also defined as taking new classes from existing classes, such as the superclass or the basic class, and converting them into a hierarchy of classes.

see below you can get an idea for inheritance.

<?php
class chef{
function makechicken(){
echo "make chicken";
}
function make salad(){
echo "make salad";
}
function make bbq(){
echo "make bbq";
}
}
$italianchef = new italianchef;
echo $italiancheff->makechicken();
echo $italiancheff->makebbq();
?>

output is made chicken and makes bbq.

Now over the php basic course. you go to this link and answer the question and get PHP certificate. Get Certificate

Thank you for all!

More php ClickHere!

See you Next Lesson Soon!

Php Course – Worldwideasy – 04

php lesson 4. I will focus on Getting Control Statements (IF statement, Switch, loops). Finally, Create a simple Grading Calculator. It can provide extensive knowledge.

Control Statements

A control statement is a statement that determines whether other statements are active. If a statement decides whether another statement should be executed, or one of the two statements to be executed. A loop determines the number of times another expression should be executed.

Basically have 3 control statement

  • IF
  • Switch
  • Loops

IF Statement in php

If a statement is used to check the condition, it can be a condition or more. The special feature of it is that you can check any gap. The following example will make it clear to you.

<?php
$name = "apple";
if ($name="apple"){
echo "true";
}
else{
echo "false";
}
?>

This Code output is true.

Switch

The switch expression is used to check several non-gap conditions. This works very fast and gets the idea below

<?php
$ grade = $_POST["grade"];
switch ($grade) {
	case 'A':
		echo "A";
		break;
		case 'B':
		echo "B";
		break;
		case 'C':
		echo "C";
		break;
		case 'S':
		echo "S";
		break;
		default:
		# code...
		break;
}

Loops

Loops have main 3 loops in php

  • For loop
  • While loop
  • Do While loop
  • Foreach Loop

Now I show the First 3 loops using Code. See Below all code output is the same. output is : 1,2,3,4,5,6,7,8,9,10

For Loop

this is a simple and easy loop in any programming language.

<?php
for ($int = 0; $int <= 10; $int++) {
  echo "$int <br>";
}
?>

While Loop

<?php
$int = 1;

while($int <= 10) {
  echo "$int <br>";
  $int++;
}
?>

Do while Loop

<?php
$int = 1;

do {
  echo "$int <br>";
  $int++;
} while ($int <= 10);
?>

Foreach Loop

This is a special loop for php. This is commonly used for arrays. see below example

<?php
$laptops = array("Dell", "Apple", "Hp", "Azus");

foreach ($laptops as $value) {
  echo "$value <br>";
}
?>

Include

you can see below example it do include HTML and php file.

<?php
include "header.html"
include "index.php"
?>

Simple Grading Calculator

See the example below and give it a try. This is a simple hierarchical calculator code. It has an HTML code that you can try on your computer. This calculator is made using what we have learned so far. So you can get a very good experience by practicing this.

<!DOCTYPE html>
<html>
<head>
	<title>Grading Calculator</title>
</head>
<body>
	<h2>Grading Calculator</h2><br>
    <form action="site.php" method="POST">
    	Marcks : <input type="number" name="num">
    	<input type="submit">
    	<br>
    	Grade is : 
    	<!--php code-->
    	<?php
    	$num = $_POST["num"];
    	if($num>=75){
    		echo "A";
    	}elseif ($num>=65) {
    		echo "B";
    	}elseif ($num>=65) {
    		echo "C";
    	}elseif ($num>=65) {
    		echo "S";
    	}else{
    		echo "F";
    	}
    	?>
    	
    </form>


</body>
</html>

Save this file. filename is site.php.

Thank you for all! do you have any questions Click here!

More php ClickHere!

See you Next Lesson Soon!

Php Course – Worldwideasy – 03

Php lesson 3. Today we going to learn more about it. Today I will focus on Getting User Input, Declaring, Arrays, Functions, and Return Type. Finally, Create a simple Calculator. It can provide extensive knowledge.

Getting User Input in php

Uses any computer language user input is how php does it. But it happens here in a very different way. We are focusing on that step by step.

To get the input you first need to create a form using HTML. The code below explains it to you.

<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>

  <form action="site.php" method="get">
  Name:<input type="text" name="name">
  <input type="submit" name="submit"> 
   </form>

</body>
</html>

Next, we need to create a php file. When you click submit as mentioned above, it will link to the file site.php. Now let’s create that file. Below is the code.

<?php
echo $_GET["name"];
?>

Declaring

It has two methods. it is the get method and post method.

  • Post method is not show Details in URL.
  • Get method is Show Details in URL.
  • Post method have good Security.
<?php
$color = $_GET["color"];
?>

Arrays

An array is a large group or number of things. Numbers, symbols, etc. arranged in rows and columns Below is the code.

now you what is an array. now we doing how to apply array in php. you can see below the example array declaring. array counting starts at 0. (output also given below)

<?php
$friends = array ("kevin","lance","tom","apple","charls");
echo "friends[1]";                 // lance
echo count ($friends);             //5
?>

Array Using Key

You can Understand that using the example below.

<?php
$grade = array ("sanka"=>"A+","milinda"=>"B-","kasun"=>"C");
echo $grade["sanka"];
?>

This code output is A+.

Functions in php

A function is an organized, reusable code that performs a single and related function. Tasks reuse better modularity and higher code for your application.

Now we apply the function for the php. Using functions we can easily type a small number of code and create a very good program.

you can get an idea for using this code about functions.

<?php
function sayhi ($name){
echo "Hello $name";
}
sayhi("Tom");  //Hello Tom
sayhi("Jack"); //Hello Jack
?>

You can see the output in this code, Hello Tom and Hello Jack.

Return Type

This is the output of the function. See the below Example.

<?php
function num ($num){
return $num * $num * $num;
}
$result = num(4);  // 64
echo "result";
?>

this code answer is 64.

Calculator Example

<!DOCTYPE html>
<html>
<head>
  <title>Calculator</title>
</head>
<body>
  <center>
    <h1>Calculator</h1>
    <form action="site.php" method="get">
      <input type="number" name="num1">
      <br><br>
      <input type="number" name="num2">
      <br><br>
      <input type="submit">
    </form>
  </center>

  <?php
  echo $_GET["num1"]+$_GET["num2"];
  ?>

</body>
</html>

Thank you for all!

More php ClickHere!

See you Next Lesson Soon!

Php Course – Worldwideasy – 02

php lesson 2. Today we going to learn more about php. In this tutorial, we will focus on HTML, Variable, Strings, Numbers, and Operations. It can provide extensive knowledge.

Use HTML For PHP

You can see below the HTML tag used in your php file.

<?php
echo "<h1>Micke</h1>";
echo "<hr>";
echo "<h1>"Jhone</h1>";
?>

Use Variable

Variables are used to store information to be referenced and manipulated in a computer program. They also provide a way of labeling data with a descriptive name, so our programs can be understood more clearly by the reader and ourselves. It is helpful to think of variables as containers that hold information. Their sole purpose is to label and store data in memory. This data can then be used throughout your program.

launchschool.com

Now you know what is variable, let’s use php.

<?php
$charname ="Jhone";
$charage = '18';
echo "my name is" $charname;
echo "my age " $charage;
?>

Working with Strings

the string is traditionally a sequence of characters. now you can see how to work it. Look at Example.

<?php
$pharase = "Hello World";
CodeOutput
echo strtoupper ($pharase);HELLO WORLD
echo strtolower ($pharase);hello world
echo strlen ($pharase);10
echo pharase[1];e
echo str_replace("Hello","Hay",$pharase);Hay World
echo substr ($pharase,6);ld
echo substr ($pharase,4,7);owor

Syntax

Working With Numbers

Every computer language uses numbers in particular. This is because it allows you to easily control the data. let show you how to work with numbers in php.

<?php
echo 5;    //5
echo 5 + 9;   //14
?>
<?php
$num = 10;
$num ++;
echo $num;  //11

Operations

In mathematics, we use different operations i.e. maximum value, square root, fall. They are also used differently in programming. The following example will give you a broader understanding.

NameSyntaxOutput
Powerecho pow(2,4);16
Square rootecho sqrt(144);12
Max Numberecho max(10,20,30);30
Min Numberecho min (10,20,30);10
Roundecho round (3.2);3
NOTecho abs(-100);100
Max Roundecho ceil(3.2);4
Min Roundecho floor(3.8);3

Operations

Special Example for Lesson 02

Q1

  • First get square root in x.
  • y is max round number.
  • z is positive number.
  • R is X+Z/Y.
  • (X=144, Y=2.2, Z=-33)
  • Find R?
<?php
$x = 144;
$y = 2.2;
$z = -33;
$x1 = sqrt($x);
$y1 = ceil($y);
$z1 = abs($z);
$R1 = $x1 + $z1;
$R = $R1 / $y1;
echo "R";
<?php
$x = 144;
$y = 2.2;
$z = -33;
$x1 = sqrt($x);
$y1 = ceil($y);
$z1 = abs($z);
$R1 = $x1 + $z1;
$R = $R1 / $y1;
echo "R = ";
echo $R;
?>

Thank you for all!

More php ClickHere!

See you Next php Lesson Soon!

Php Course – Worldwideasy – 01

php lesson is about php. PHP is a general-purpose scripting language. specifically designed for web development. It created by the Rasmus Lerdorf. PHP: Hypertext Preprocessor for an iterative startup.

The implementation language of php is C. It works for any OS ex: Unix, Windows.
Additional information is available at www.php.net. ATOM, Sublime Text, Php Strome as php editors. php is the server-side language.

How to install php in your pc!(Windows).

  1. First we need to download php debug pack (www.php.net).
  2. After Download Extract in C Drive.
  3. Edit the System Environment Variable.
    • Environment Variable.
    • Path
    • Edit
    • New
    • Type C:php
    • Click Ok
  4. Test Using CMD
    • php -v

How to create CMD local host and run

  1. Open CMD
    • php -s localhost:4000

(example file path in Desktop file name site.php)

Open Web Browser and type this URL,

localhost:4000//www/site.php

Now you know how to run php file on your windows pc.

PHP Frameworks

What is the framework? this is software. this helps to make the website easy. it has more options to develop any program easily. It has web services, web resources, and web APIs. It helps us develop a good website. But to work with php framework you must have basic knowledge of php. See below its is top 10 php framework in 2020.

  1. Laravel
  2. Symfony
  3. Zend
  4. Yii
  5. Phalcon
  6. CodeIgniter
  7. CakePHP
  8. FuelPHP
  9. PHPixie
  10. Slim

I recommend for develop a website use CodeIgniter and Laravel it is good. I put a link below you can go it site,

How to Make First Php File

Hello World

  • First Step is Open any Shoutable editor.
  • php code have block <?php ?> any function you can type with this block.
  • php have 2 main text output method it is echo or print you can use both of them.
  • special php code line end use semicolon ( ; ).
  • See below full code of hello world in php,
<?php
echo ("Hello World");
?>

Save and run the file you can see hello world for output.

Thank you for all!

More php ClickHere!

See you Next php Lesson Soon!