Sunday, 27 August 2017

FCFS scheduling program in C with arrival time

/*
    FCFS (First Come First Serve) Scheduling Algorithm with Arrival time
    Created By: Pirate
*/



#include<stdio.h>
#include<conio.h>
void main()
{
    float process[500],aTime[500],bTime[500],abTime[500],wTime[500],tat_time[500];
    int n = 0,i = 0 ;
    float aw_time = 0, atat_time = 0;
    printf("*** FCFS Scheduling Algorithm Using Arrival Time ***\n");
    printf("\nEnter the number of process : ");
    scanf("%d",&n);

    printf("Enter the Arrival time and Burst time.\n\n");
    printf("\tA_Time B_Time\n");
    for(i = 0 ; i < n ; i++){
        process[i]=i+1;
        printf("P%d :\t", i+1);
        scanf("%f\t%f",&aTime[i],&bTime[i]);
    }
    printf("\n\nProcess\tA_Time\tB_Time\n");
    for(i = 0 ; i < n ; i++){
        printf("P[%d]\t%.2f\t%.2f\n",i,aTime[i],bTime[i]);
    }
    wTime[0] = 0;
    tat_time[0] = bTime[0];
    abTime[0] = bTime[0]+aTime[0];
    for( i = 1 ; i < n ; i++){
        abTime[i] = abTime[i-1] + bTime[i];
        tat_time[i] = abTime[i] - aTime[i];
        wTime[i] = tat_time[i] - bTime[i];
    }
    for(i = 0 ; i < n ; i++){
        aw_time = aw_time + wTime[i];
        atat_time = atat_time + tat_time[i];
    }
    printf("\tA_time\tB_time\tC_time\tTat_time  W_time\n");
    for(i = 0 ; i < n ; i++){
        printf("P[%d]\t%.2f\t%0.2f\t%0.2f\t%0.2f\t%0.2f\n",i,aTime[i],bTime[i],abTime[i],tat_time[i],wTime[i]);
    }
    printf("\nAverage waiting time : %0.2f",aw_time/n);
    printf("\nAverage turn around time : %0.2f",atat_time/n);
}

Output



Tuesday, 22 August 2017

How to send mail from php from local host using gmail smtp

Hi Friends,

How are you all? Good. I'm also good. Today I'll tell you how to send mail from local host in php.

I'm using php mailer to send mail. PHPMailer is a class library for PHP that provides a collection of functions to build and send email messages. PHPMailer supports several ways of sending email: mail(), Sendmail, qmail & direct to SMTP servers. You can use any feature of SMTP-based e-mail, multiple recepients via to, CC, BCC, etc. In short: PHPMailer is an efficient way to send e-mail within PHP.

PHP has a built-in mail() function. So why use PHPMailer? Isn't it slower? Not really, because before you can send a message you have to construct one correctly, and this is extremely complicated because there are so many technical considerations. PHPMailer makes it easy to send e-mail, makes it possible to attach files, send HTML e-mail, etc. With PHPMailer you can even use your own SMTP server and avoid Sendmail routines used by the mail() function on Unix platforms.
You can download phpmailer from here. 
After downloading the file, you need to extract the content and save it under your server folder. For me I'm saving in htdocs because i'm using XAMPP. The best practice is save it inside your website folder. My website folder name is test. So I saved it inside test folder.
To send mail you need a html file in which you can provide the details, Google id and password and php file in which all the mail logic written.
Lets create a simple html form,
<html>
    <body>
        <form name="email" method="post" action="test.php">
            <table>
                <tr>
                    <td>To</td>
                    <td><input type="text" name ="to" required></td>
                </tr>
                <tr>
                    <td>From</td>
                    <td><input type="text" name="from" required></td>
                </tr>
                <tr>
                    <td>CC</td>
                    <td><input type="text" name="cc"></td>
                </tr>
                <tr>
                    <td>Subject</td>
                    <td><input type="text" name ="subject"></td>
                </tr>
                <tr>
                    <td>Message</td>
                    <td><textarea rows="5" cols="22" name="message" required>
                    </textarea></td>
                </tr>
                <tr>
                    <td><input type="submit"></td>
                    <td><input type="reset"></td>
                </tr>
        </form>
    </body>
</html>
I'm not adding any validation in the form. Just one that is you have to enter something. You can also email validation if the email id is valid or not.
You can save the file with any name. I'm saving it test1.html. It will look like,

I did not added any css. If you want you can add and modify code according to your need. Now we created html file. Lets write some php code.

<?php
    require 'PHPMailer/PHPMailerAutoload.php';

    if (!empty($_POST["to"]) && !empty($_POST["from"]) 
        && !empty($_POST["message"])){
        $to = $_POST["to"];
        $from = $_POST["from"];
        $message = $_POST["message"];
        $subject = $_POST["subject"];
        //Create a new PHPMailer instance
        $mail = new PHPMailer;   
        $mail->isSMTP();
        $mail->SMTPDebug = 0;
        $mail->Debugoutput = 'html';
        $mail->Host = 'smtp.gmail.com';
        $mail->Port = 587;
        $mail->SMTPSecure = 'tls';

        //use SMTP authentication
        $mail->SMTPAuth = true;

        //Username to use for SMTP authentication
        $mail->Username = "yourEmail@gmail.com";
        $mail->Password = "yourEmailIdPass";
        $mail->setFrom($from);
        $mail->addReplyTo($to);
        $mail->addAddress($to);
        $mail->Subject = $subject;
        // $message is gotten from the form
        $mail->msgHTML($message);
        $mail->AltBody = "";
        if (!$mail->send()) {
            echo "Error while sending mail";
        } else {
            echo "Congratulations. Success";
            }
    }
    else
        header('Location: http://localhost/test/test1.html')
?> 

when you write your php mail code, check require 'PHPMailer/PHPMailerAutoload.php' . If you saved PHPMailer in another folder then you have to give proper path.

After checking path, see these two lines,
        $mail->Username = "yourEmail@gmail.com";
        $mail->Password = "yourEmailIdPass";
Replace yourEmail@gmail.com with your email id and yourEmailIdPass with your password for that email id. Two-Step verification should be disable on the account that you are using in php file. If two-step verification is enabled then you have to disable it from your gmail settings.

Now save your file with the name of test.php.

You almost completed. But you have make some setting in your Gmail. For less secure apps you need to change account access. Go to following link.


It is turn off by default. You have to turn it on.


So everything is setup. It's time to test our mail if it is working or not.

Enter the email id in To and From, Enter a subject and a message and then click on Submit button.

If everything works as expected then you will get the success message,

Now go to your mailbox to check if you really get the email or is it just showing success message Congratulations. Success .

Great, I got the mail.

Enjoy :)





Saturday, 19 August 2017

Program to implement FCFS (First Come First Serve ) Algorithm in C

/*
    FCFS (First Come First Serve) Scheduling Algorithm
    Created By: Pirate
*/

#include<stdio.h>
#include<conio.h>
void main(){
    float input[500],process[500],tat[20];
    float avg_wt=0,avg_tat=0;
    int n,i,j;
    printf("*** FCFS Process Scheduling Algorithm ***\n");
    printf("\nEnter number of Processes : ");
    scanf("%d",&n);

    printf("\nEnter Process Burst Time\n");
    for(i=0;i<n;i++){
        printf("P%d : ",i+1);
        scanf("%f",&input[i]);
    }

    process[0]=0;

    for(i=1;i<n;i++){
        process[i]=0;
        for(j=0;j<i;j++)
            process[i]+=input[j];
    }
    printf("\nProcess\t\tBurst Time\tWaiting Time\tTurnaround Time");

    for(i=0;i<n;i++){
        tat[i]=input[i]+process[i];
        avg_wt+=process[i];
        avg_tat+=tat[i];
        printf("\nP[%d]\t\t%.2f\t\t%.2f\t\t%.2f",i+1,input[i],process[i],tat[i]);
    }

    avg_wt/=i;
    avg_tat/=i;
    printf("\n\nAverage Waiting Time     :  %.2f",avg_wt);
    printf("\nAverage Turnaround Time  :  %.2f\n",avg_tat);

}

Output


Program to implement SJF (Shortest Job first) algorithm in C


/*
    SJF (Shortest Job First) Scheduling Algorithm
    Created By: Pirate
*/

#include<stdio.h>
#include<conio.h>
void main(){
    int input[500],process[500];
    int wt[500],tat[500],total=0;
    int i,j,n,pos,temp;
    float avg_wt,avg_tat;
    printf("*** SJF Process Scheduling Algorithm ***\n");
    printf("Enter the number of Process: ");
    scanf("%d",&n);

    printf("\nEnter Burst Time:\n\n");
    for(i=0;i<n;i++){
        printf("P%d: ",i+1);
        scanf("%d",&input[i]);
        process[i]=i+1;
    }

    for(i=0;i<n;i++){
        pos=i;
        for(j=i+1;j<n;j++){
            if(input[j]<input[pos])
                pos=j;
        }
        temp=input[i];
        input[i]=input[pos];
        input[pos]=temp;

        temp=process[i];
        process[i]=process[pos];
        process[pos]=temp;
    }

    wt[0]=0;

    for(i=1;i<n;i++){
        wt[i]=0;
        for(j=0;j<i;j++){
            wt[i]+=input[j];
        }
        total+=wt[i];
    }

    avg_wt=(float)total/n;
    total=0;

    printf("\nProcess\t Burst Time \tWaiting Time\tTurnaround Time");
    for(i=0;i<n;i++){
        tat[i]=input[i]+wt[i];
        total+=tat[i];
        printf("\nP%d\t\t%d\t\t%d\t\t%d",process[i],input[i],wt[i],tat[i]);
    }

    avg_tat=(float)total/n;
    printf("\n\nAverage Waiting Time    =   %f",avg_wt);
    printf("\nAverage Turnaround Time =   %f\n",avg_tat);

}

Output



Wednesday, 2 August 2017

[Solved] Cannot create ActiveX component in Vb.net

Hi Friends,
                
Today I'll tell you how to solve "ActiveX component can't create object" Exception in VB.net. You can use the same logic in any other application also.

So I'm getting the this exception when I try to create a obect of  Internet Explorer. When creting the object for first time, it works fine, I can see the given link in the browser, but for second time if I again create the object I got this error.

Here is the code :

Dim browser As Object = CreateObject("InternetExplorer.Application")
browser = CreateObject("InternetExplorer.Application")
And I'm getting the Cannot create ActiveX component error.




So I searched and find a solution, and it is working like charm. Here is the solution.

Dim browser As Object = CreateObject("InternetExplorer.Application")
Try
   browser = CreateObject("InternetExplorer.Application")
Catch ex As Exception
    For Each explorer_process As Process In Process.GetProcesses 
        If String.Compare(explorer_process.ProcessName, "iexplore", True) = 0 Then 
            Try 
                explorer_process.Kill() 
            Catch exp As Exception 
                Exit For 
            End Try 
        End If 
    Next 
    browser = Nothing     
    browser = CreateObject("InternetExplorer.Application")
End Try

Enjoy :)