Wednesday, 5 April 2017

Quick Sort

WRITE A PROGRAM ON QUICK -SORT:-
#include <stdio.h>
#include <stdbool.h>
#define MAX 7

int intArray[MAX] = {4,6,3,2,1,9,7};

void printline(int count) {
   int i;

   for(i = 0;i <count-1;i++) {
      printf("=");
   }

   printf("=\n");
}

void display() {
   int i;
   printf("[");

   // navigate through all items
   for(i = 0;i<MAX;i++) {
      printf("%d ",intArray[i]);
   }

   printf("]\n");
}

void swap(int num1, int num2) {
   int temp = intArray[num1];
   intArray[num1] = intArray[num2];
   intArray[num2] = temp;
}

int partition(int left, int right, int pivot) {
   int leftPointer = left -1;
   int rightPointer = right;

   while(true) {
      while(intArray[++leftPointer] < pivot) {
         //do nothing
      }

      while(rightPointer > 0 && intArray[--rightPointer] > pivot) {
         //do nothing
      }

      if(leftPointer >= rightPointer) {
         break;
      } else {
         printf(" item swapped :%d,%d\n", intArray[leftPointer],intArray[rightPointer]);
         swap(leftPointer,rightPointer);
      }
   }

   printf(" pivot swapped :%d,%d\n", intArray[leftPointer],intArray[right]);
   swap(leftPointer,right);
   printf("Updated Array: ");
   display();
   return leftPointer;
}

void quickSort(int left, int right) {
   if(right-left <= 0) {
      return;
   } else {
      int pivot = intArray[right];
      int partitionPoint = partition(left, right, pivot);
      quickSort(left,partitionPoint-1);
      quickSort(partitionPoint+1,right);
   }      
}

main() {
   printf("Input Array: ");
   display();
   printline(50);
   quickSort(0,MAX-1);
   printf("Output Array: ");
   display();
   printline(50);
}


OUTPUT:-

Monday, 3 April 2017

VoCore: A Cheap And Coin-sized Linux Computer With Wi-Fi


Short Bytes: VoCore is an open hardware that runs OpenWRT Linux. This tiny computer comes with Wi-Fi, USB, 20+ GPIOs that will help you to make a smart home automation system or use it in other embedded projects. Read more to know about this device and grab one for yourself.
With each passing day, mini computer boards are getting more and more popular. Single board computers like Raspberry Pi, CHIP, OrangePi etc. are being endorsed by makers and DIY enthusiasts to create new innovations. However, if you are looking for an even smaller Linux computer, VoCore is the perfect device for you.
At fossBytes, we love open source technologies and so do the makers of VoCore. It’s an open source hardware that runs OpenWrt on top of Linux. With this mini Linux machine, you can fork your own Wi-Fi router, make smart home automation systems, invent a new device, build a motherboard and whatnot.

In simpler words, you can use it as a standalone device or use it as an embedded component of a larger system. It comes with included Dock that extends the USB and Ethernet ports to enhance its functionality.

Specifications of VoCore Linux computer:

This coin-sized computer is powered by 32MB SDRAM, and 8MB SPI Flash. It provides many interfaces like 10/100M Ethernet, USB, UART, I2C, I2S, PCM, JTAG and over 20 GPIOs.
  • OpenWRT Linux
  • Onboard Wi-Fi adapter
  • Integrates a 802.11n MAC, baseband, radio, FEM & 5-port 10/100Mbps Ethernet switch
  • Processor: Ralink/Mediatek 360 MHz RT5350 MIPS
Here’s the pin map of VoCore:
An open source software and hardware of VoCore means that you will also get its full hardware design and source code. This will allow you to control every part of this tiny Linux computer.



Did we miss something? Let us know in comments below.

what’s an error?

what’s an error?
An error is a type of mistake. We can say an error is a condition of having incorrect or false knowledge or an error is defined as an unexpected, invalid program state from which it is impossible to recover.
Error can also be defined as "a deviation from accuracy or correctness".
A "mistake" is an error caused by a fault: the fault being misjudgment, carelessness, or forgetfulness. An error message with filename, line number and a message describing the error is sent to the browser.
What are the different kinds of errors in PHP?
Basically there are four kinds of errors in PHP, which are as follows:
·         Parse Error (Syntax Error): The parse error occurs if there is a syntax mistake in the script; the output is Parse error. A parse error stops the execution of the script. There are many reasons for the occurrence of parse errors in PHP. The common reasons for parse errors are as follows:
1.       Unclosed quotes
2.      Missing or Extra parentheses
3.      Unclosed braces
4.      Missing semicolon
Example:
<?php
echo
 "Cat";
echo
 "Dog"
echo
 "Lion";
?>
Output:
In the above code we missed the semicolon in the second line. When that happens there will be a parse or syntax error which stops execution of the script.
·         Fatal Error: Fatal errors are caused when PHP understands what you've written, however what you're asking it to do can't be done. Fatal errors stop the execution of the script. If you are trying to access the undefined functions, then the output is a fatal error.
Example:
<?php
function fun1()
{
echo "Vineet Saini";
}
fun2();
echo "Fatal Error !!";
?>
Output:
In the above code we defined a function fun1 but we call another function fun2 i.e. func2 is not defined. So a fatal error will be produced that stops the execution of the script.
·         Warning Error: Warning errors will not stop execution of the script. The main reason for warning error is to include a missing file or using the incorrect number of parameters in a function.
Example:
<?php 
echo "Warning Error!!";
include ("Welcome.php");
?>
Output:


In the above code we include a welcome.php file, however the welcome.php file does not exist in the directory. So there will be a warning error produced but that does not stop the execution of the script i.e. you will see a message Warning Error!!
·         Notice Error: Notice error is the same as a warning error i.e. in the notice error, execution of the script does not stop. Notice that the error occurs when you try to access the undefined variable, then produce a notice error.

Example:
<?php
$a="Vineet kumar saini";
echo "Notice Error !!";
echo $b;
?>
Output:
In the above code we defined a variable which named $a. But we call another variable i.e. $b, which is not defined. So there will be a notice error produced but execution of the script does not stop, you will see a message Notice Error!! 

What are the different types of errors in PHP?
Basically there are 13 types of errors in PHP, which are as follows:
1.       E_ERROR: A fatal error that causes script termination
2.      E_WARNING: Run-time warning that does not cause script termination
3.      E_PARSE: Compile time parse error
4.      E_NOTICE: Run time notice caused due to error in code
5.       E_CORE_ERROR: Fatal errors that occur during PHP’s initial startup (installation)
6.      E_CORE_WARNING: Warnings that occur during PHP’s initial startup
7.       E_COMPILE_ERROR: Fatal compile-time errors indication problem with script
8.      E_USER_ERROR: User-generated error message
9.      E_USER_WARNING: User-generated warning message
10.   E_USER_NOTICE: User-generated notice message
11.    E_STRICT: Run-time notices
12.   E_RECOVERABLE_ERROR: Catchable fatal error indicating a dangerous error
13.   E_ALL: Catches all errors and warnings



Send Email From Server Side

//if "email" variable is filled out, send email
  if (isset($_REQUEST['email']))  {
 
  //Email information
  $admin_email = "someone@example.com";
  $email = $_REQUEST['email'];
  $subject = $_REQUEST['subject'];
  $comment = $_REQUEST['comment'];
 
  //send email
  mail($admin_email, "$subject", $comment, "From:" . $email);
 
  //Email response
  echo "Thank you for contacting us!";
  }
 
  //if "email" variable is not filled out, display the form
  else  {
?>

 <form method="post">
  Email: <input name="email" type="text" /><br />
  Subject: <input name="subject" type="text" /><br />
  Message:<br />
  <textarea name="comment" rows="15" cols="40"></textarea><br />
  <input type="submit" value="Submit" />
  </form>
 
<?php
  }
?>


Inheritance

Inheritance is a mechanism of extending an existing class by inheriting a class we create a new class with all functionality of that existing class, and we can add new members to the new class.
When we inherit one class from another we say that inherited class is a subclass and the class who has inherit is called parent class.
-We declare a new class with additional keyword extends.
- PHP only supports multilevel inheritance.
Best example of multilevel inheritance in PHP

1.       class grandParent
2.       {
3.       //Body of grand parent class
4.       }
5.       class parent extends grandParent
6.       {
7.       //Body Of parent class
8.       }
9.       class child extends parent
10.    {
11.    //Body of child class
12.    }

Above example is so clear to understand, child class is extending parent class and parent class is extending grand parent.This was a very basic example to understand the concept of multilevel inheritance in php oops.

Constructor

Constructor
void __construct ([ mixed $args = "" [, $... ]] )
The constructor is the most useful of the two, especially because it allows you to send parameters along when creating a new object, which can then be used to initialize variables on the object
PHP  allows developers to declare constructor methods for classes. Classes which have a constructor method call this method on each newly-created object, so it is suitable for any initialization that the object may need before it is used.
Note: Parent constructors are not called implicitly if the child class defines a constructor. In order to run a parent constructor, a call to parent::__construct() within the child constructor is required. If the child does not define a constructor then it may be inherited from the parent class just like a normal class method (if it was not declared as private).

class Animal
{
    public $name = "No-name animal";
   
    public function __construct()
    {
        echo "I'm alive!";       
    }
}

Output


$animal = new Animal();