Sunday, 18 August 2013

Displaying Battery Status in Android

Hi,

      Lets have some fun in android!
  

Have you ever thought of displaying battery status in % when ever the battery status changes?

 Displaying Alert when battery level reaches below certain level?



      Yes!!! Lets do it in this post right now ;)

      The approach for doing this is,  Yes using BroadcastReceiver Register it to ask android to notify
     you for every %  of battery changes.

     Use this function to accomplish it.


     private void batteryLevel() {
        BroadcastReceiver batteryLevelReceiver = new BroadcastReceiver() {

            public void onReceive(Context context, Intent intent) {
                context.unregisterReceiver(this);
                int rawlevel = intent.getIntExtra("level", -1);
                int scale = intent.getIntExtra("scale", -1);
                int level = -1;
                if (rawlevel >= 0 && scale > 0) {
                    level = (rawlevel * 100) / scale;
                }
                batterLevel.setText("Battery Level Remaining: " + level + "%");
                if(level<30)
                    Toast.makeText(getBaseContext(), "your battery is very low",
                    Toast.LENGTH_LONG).show();
                else
                    Toast.makeText(getBaseContext(), "your battery is fine", Toast.LENGTH_LONG).show();
               
            }
        };
        IntentFilter batteryLevelFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
       registerReceiver(batteryLevelReceiver, batteryLevelFilter);
    }

Call this function and it will register receiver and it will be triggered when every battery level changes.

When battery level changes this receiver will be called and onRecieve() is the default method that gets executed and this function must be overridden.

We unregistered Broadcastreceiver to make sure the function is not interrupted while executing and then
at end of the function we register it again.

I have displayed low when battery level reaches below 30% and fine when it is above that.

Probably you can implement it in your custom way.

It doesn't require any changes in Manifest file.

The output will be like this


 Have a doubt please comment.

You can download complete source code from here
        

Wednesday, 14 August 2013

C program to print INDIA MAP

Happy independence day !!!!!!!!!!!

C program to print INDIA MAP

#include<stdio.h>
void main()
{
int a,b,c;
for (b=c=10;a="- FIGURE?, UMKC,XYZHello Folks,\
TFy!QJu ROo TNn(ROo)SLq SLq ULo+\
UHs UJq TNn*RPn/QPbEWS_JSWQAIJO^\
NBELPeHBFHT}TnALVlBLOFAkHFOuFETp\
HCStHAUFAgcEAelclcn^r^r\\tZvYxXy\
T|S~Pn SPm SOn TNn ULo0ULo#ULo-W\
Hq!WFs XDt!" [b+++21]; ) {
for(; a-- > 64 ; )
{
putchar ( ++c=='Z' ? c = c/ 9:33^b&1);
}
}
}

Here is the output of the above program


Monday, 5 August 2013

Creating CAPTCHA using PHP

What is CAPTCHA?

CAPTCHA stands for Computer Automated Public Turing test to tell Computers and Humans apart

They are used for providing security  in various applications like login forms , registration , password recovery etc .



Now lets Create our own captcha application .


Here goes the html code for the application .
The file is named as Captcha.html



Here goes the  PHP code for image creation.
The file is named as captcha_validation.php.



Here goes the  PHP for image creation.
The file is named as image_creation.php.


Here is the output screen


Just download the files from here and enjoy :-)

All the best :-)

Leave your doubts and suggestions in the comments section :-)

Tuesday, 30 July 2013

How to Build Cross Platform Mobile Applications


How to build single application which works on all mobile platforms? 

Although Android has occupied good market share and blooming, still there are many mobile platforms
like Blackberry, windows, symbion, ios.

For each of this you need to setup a environment and learn each.

Do you know you can just create a mobile application on different platforms just using HTML, CSS,
XML FILE?

Then just build it into any platform you want.

Thats cool!! Want to see how? let me start quickly

You need following things to start

1. Setup Java on your system - Windows or linux

2. Download and Install Node.js from here for windows and Linux users install using sudo command.

3. Download Ant from here
    Extract and Add path to the ant\bin to your PATH variable.

    Ex: I have extracted to apacheant folder so am adding this to my path variable
           ; C:\apacheant\apache-ant-1.9.2\bin

   Now you have Ant configured.

After you configure above properly check typing javac --version, Ant and npm to make sure you have
configured it properly.

when typed above commands it should not output "'**** is not recognized as an internal or external command,operable program or batch file".

 Now install cordova by typing

                         sudo npm install -g cordova

Note: windows users type with out sudo keyword.

This will install cordova.

what is cordova??   That's a obvious question.
 Cordova is API by apache previously called PhoneGap, which contains many libraries or api functions to program easily with out using specific sdk.

converting web app to ios, android, blackberry, webOS


It also has build on cloud option, using this we can build application targeting any platform with out downloading any sdk of any platform.

So now you got some idea right !!!

Once you install cordova as shown above, create a cordova app

create cordova wetechies  com.example.cordova  hellowetechies

where hellowetechies is display text and com.example.cordova is domain name or package name and wetechies is a folder name which will contain HTML, css files platforms etc.

Now two things can be done

1. Developing the application by editing HTML and CSS files and building remotely for any platform and downloading apk or platform specific file then check on your phone

2. Download sdk of platform which you want to target importing project into eclipse and developing where you can use emulator to check you application.

 In this post am going to show how to use first method :)

So after creating a project, you have to change directory (go inside the directory)

cd wetechies

Compress the wetechies folder in zip format ( currently rar is  not accepted)

Now go to this URL  phone gap build and register yourself.

Now after signing in click on  +new app and click on private tab.

Click on upload .zip file and select you compressed file and upload.

After uploading is compeleted you can see that app in apps sections and click on Ready to build.

Click on the platform you need to target

using phonegap, how to use phonegap build, how to develope cross platform applications

 For demo purpose I selected Android, second from left

downloading android apk, building webapp for android blacberry ios webOS
As I selected android as my platform, It has build for android and also for windows,hp,i.

You can click on specific platform extension like for android on apk file to download and test it on
your phone.

As you have got error for ios and others, you can click and fix it, you will be guided to fix it as building ios applications is quite different from rest.

Once you install and run on your phone, you can see the demo application created by phonegap you can edit and further proceed by following there api documentation at phonegap.com.

happy blogging :)

Ask us if you have any doubts or stuck with anything :)



Sunday, 28 July 2013

Creating your own library using GNU's archive (An interesting example for the ar command)

Hi ,

Follow this post if you want to start up with some basic information regarding C library .

In this post  you will be creating your own library and also be using it in your own program , the post will also demonstrate the use of the ar(archive) command.

Lets start Creating and using our library

STEP 1 :- Lets create two files for demonstration .

File 1 } myadd.c

#include<stdio.h>


int myadd(int a , int b)
{
int res;

res = a + b;

return res;
}


File 2 } mysub.c

#include<stdio.h>


int mysub(int a , int b)
{
int res;

res = a - b;

return res;
}


STEP 2 :- Lets create object codes of the above two c codes


 gcc -c myadd.c 


 gcc -c mysub.c 


Follow this post to get some more information about the above command.

STEP 3 :- Lets create our header file having the prototypes of the myadd() and mysub() functions.

myheader.h


#include<stdio.h>

int myadd(int a , int b);

int mysub(int a , int b);


STEP 4 :- Lets create the library file using the ar command .
We specify the name of the library file and the object codes to be grouped together as a library as the arguments to the ar command .



ar cr mylib.a myadd.o mysub.o

The GNU ar program creates, modifies, and extracts from archives.  An archive is a single file holding a collection of other files in a structure that makes it possible to retrieve the original individual files (called members of the archive). The option c creates the archive and the option r inserts the files into the archive by replacing any previouly existing members of the archive .

To view to contents of the mylib.a file we can use the following command

ar t mylib.a

STEP 5 :- Congrats you have created your library , Now lets write our own program with the library we created.

my_program_with_myheader.c

#include"myheader.h"

int main()
{
int res;
res = myadd(10 , 20);
res = mysub(50 , 20);

printf("The result after addition is %d\n",res);

printf("The result after subtraction is %d\n",res);
}

You can see the myheader.h file created by you being used in the program .

Lets compile the above file

gcc my_program_with_myheader.c mylib.a -o my_output

Now execute the output file to get the required output

./my_output

The below figure shows the whole process


























Thats it !!!

Leave your comments and suggestions and doubts in the comments sections

Saturday, 27 July 2013

An introduction to Library files

What is a library ?

In simple terms - a library is obtained by grouping multiple compiled object code files . Libraries are also know as shared components or archive libraries .

When to create/use library?

A library can be created when ever you have some functions or any piece of code that will be used by many applications .

Instead of rewriting that piece of code in every application repeatedly , you can just include the library in a single statement .

Seems to be useful??? read further

Types of libraries

In linux there are 2 c/c++ library types

1 } Static Library - These are files that have the .a extension ( .lib in windows ) . The static library is linked into the executable during the link time . All the codes related to the library will be in this file . A program that makes use of the static library file will take all the codes that uses from the static library and will make it as a part of the program itself.

2 } Shared/Dynamic Library - These are files that have the .so extension ( .dll in windows ) .This can be used in 2 ways .

             a } Dynamically linked at run time . The shared objects will not included  to the executable component but it will be tied to the execution .

             b } Can be loaded and unloaded during execution using the dynamic linking loader system functions .


    
               

Wednesday, 24 July 2013

Creating executable file by linking object files in linux

Hello here is a simple but interesting and useful topic .

Do you want to know how to create object files and link them together to create an executable files??

Well , your in the right place !!!!!

In this post we will be making use of the  gcc compiler .

We will create two files

1 } wetechies.c - does not contain the main function but has the implementation of the add function .

2 } wetechiesmain.c - has the main function and calls the add function present in the wetechies.c file .


 Here is the wetechies.c file

#include<stdio.h>

int add(int c , int d)
{
    int result;

    result = c + d;

    printf("\n\nwetechies.c file has been called\n");

    printf("\n\nThe result after addition is %d\n",result);

    return result;
}




And here is the wetechiesmain.c file

#include<stdio.h>

int main()
{
    int a , b ;

    printf("\n\nwetechiesmain.c file  has been called\n\n\n");

    printf("Enter the two numbers to be added\n");

    scanf("%d %d",&a,&b);

    add(a,b);
}

Now we need to convert the above c files into object files .

We do this by using the gcc compiler using the -c option which compiles or assembles the source files, but does not link them.  The linking stage simply is not done.  The ultimate output is in the form of an object file for each source file.

Now lets see the steps to create the object files and link them to create the final executable file> .

Step 1 : We create the object file (wetechies.o) file using the following command

gcc -c wetechies.c

The above command will create the wetechies.o object file .

The ls command can be used to  check the contents of a directory .

Step 2 : We create the object file (wetechiesmain.o) file using the following command .

gcc -c wetechiesmain.c

The above command will create the wetechiesmain.o object file .


Step 3 : In this step we will link the two object files that we created in the above two steps in order to create the final executable file .



This is done by using the following command .

gcc -o wetechies_executable wetechies.o wetechiesmain.o

The -o option used along with the gcc command will place output in file wetechies_executable .  This applies regardless to whatever sort of output is being produced, whether it be an executable file,an object file, an assembler file or preprocessed C code. When you link a .o file, its contents are copied into the program, whether you call the routines in it or not.



 The above command will create an executable file with the name wetechies_executable .

We execute the executable file as below

./wetechies_executable

The below figure shows the whole procedure .




























Congrats you have obtained the correct output even though you have called the function in one file and got the implementation of it in another file !!!!!!!

It all happened because you created the executable file by linking two objects files .



Thats it !!!!

Leave your doubts and suggestions in the  comments section .

Saturday, 13 July 2013

How to sent mail in php using Gmail SMTP

Hi,

     Have you ever thought how to send mail in PHP with out using mail() ?


     I know you would have used mail() in PHP, then you should also know limitations of it.

     Setting/configuring your outlook,mercury,thunderbird to use  mail() is an hurdle and it doesn't
     provide much flexibiity too.

    Do you know there are many libraries to send mail? indeed power full libraries like
    phpmailer, swiftmailer
.

    These classes or libraries have been written to make sending mail using PHP easier
    and send mail with more flexibility and features.

    In this demo am going to use phpmailer class as swiftmailer is also good but I prefer and
    recommend phpmailer because swiftmailer class has not been updated recently and where
   phpmailer has good documentation and new releases are always on the way.

   Lets start now :)

   First download phpmailer from here .

   Extract it to your local host directory (ex: htdocs in windows xampp).

   Now you have a directory called phpmailer  in your web directory.

   Now write a php script, first include phpmailer class.

         require_once './phpmailer/class.phpmailer.php';
 
   Now instantiate the phpmailer class.
   
          $mail = new PHPMailer(true);

   Now $mail contains instance of PHPMailer class now you can configure all the properties
   of it.

       
$mail->CharSet = 'utf-8'; //sets character set
$to = 'wetechies.2013@gmail.com'; //from whom the mail should be sent

$mail->IsSMTP();  //To inform that we are using SMTP

$mail->SMTPDebug = 2;  //Shows long message set to 1 to avoid it

$mail->Host = "smtp.gmail.com"; // As we are using gmail SMTP

$mail->Port = "465";  // smtp port number

$mail->SMTPSecure = "ssl"; //gmail requires authentication through ssl or tls

$mail->SMTPAuth = true;

// your account details for authentication provide correct user name and password
$mail->Username = "wetechies.2013@gmail.com";

$mail->Password = "mypassword";

$mail->AddReplyTo("wetechies.2013@gmail.com", "nag");

$mail->From = "wetechies.2013@gmail.com";

$mail->FromName = "wetechies blog";

$mail->AddAddress("wetechies.2013@gmail.com", "nagashayan");

$mail->Subject = "hi (PHPMailer test using SMTP)";

$body="Sending mail by using wetechies post on How to use Gmail SMTP to send mail \n";

$mail->WordWrap = 80;

$mail->MsgHTML($body, dirname(__FILE__), true); //Create message bodies and embed images

//you can also add attachments to your mail but change file path
//$mail->AddAttachment('images/phpmailer_mini.gif', 'phpmailer_mini.gif'); // optional name

//$mail->AddAttachment('images/phpmailer.png', 'phpmailer.png'); // optional name



//call send() to send mail
$mail->Send();



PS: The above example sends mail from wetechies.2013@gmail.com to wetechies.2013@gmail.com itself.

      To send to other change $mail->to =" to_whom_you have to send";

If you don't want to take hurdle of writing script don't worry phpmailer helps you in that too.

What? Yes! it generates code for you!!! Amazing right

Once you download phpmailer class go to phpmailer/examples/  check for codegenerator.phps

Change .phps extension to .php run that file, fill out all the details


mail() of PHP, phpmailer class, send mail in php, send mail using external libraries, swift mailer disadvantages, using gmail smtp in php,

 Now fill up your google account details

mail() of PHP, phpmailer class, send mail in php, send mail using external libraries, swift mailer disadvantages, using gmail smtp in php,

SMTP Port - 465
SMTP Server - smtp.gmail.com
SMTP Security - ssl
SMTP Authentication check yes

Provide your username and password of google and click submit.

that's it!!! you are done it gives you the PHP script if authentication is successfull.
you can just run that code and send send the mail.
the generated script just include that in your PHP file :)

You are done, Now send mail to anyone with n no of attachments happily :)

Please leave your doubts or comments below :)



 
 

Thursday, 11 July 2013

Creating PDF files using PHP

Create PDF files using your own PHP code


Welcome ,

I'm sure you would have struggled to convert your Document(doc) file into Portable Document File(pdf) by searching for a converter software and other mean.

Why don't you create a PDF file by your own .

YES you can do it using PHP , want to try ??? Its very simple !!!!!! 

For this purpose we make use of  FPDF --->FPDF is a PHP class using which you can  generate PDF files with pure PHP, that is without using the PDFlib library where F stands for Free

FPDF has a lot of advantages and excellent features .

You can download the FPDF files  and  from here .

To get some more  idea about the functions below , you can refer this manual



Here goes the code !!!!!!

PDF Creation using PHP

AddPage(), convert doc file into pdf, Creating PDF files using PHP, FPDF, Image(), MultiCell(), PageNo(), PDF, PHP, SetFont(), SetY(),

 

/********************************************************************/
 <?php

require('fpdf.php');
class wetechiesPDF extends FPDF {

function Header() {
    $this->SetFont('Times','B',18); //prototype of the setFont function is SetFont(string family [, string style [, float size]])
    $this->SetY(0.5);// Moves the current abscissa back to the left margin and sets the ordinate. If the passed value is negative, it is relative to the bottom of the page.
    $this->Cell(0, .25, "wetechies ".$this->PageNo(), 'T', 2, "R");
    //reset Y
    $this->SetY(1);
}

function Footer() {
//This is the footer; it's repeated on each page.

    $this->Image("wetechies.jpg", (8.5/2)-1.5, 9.8, 3, 1, "JPG", "http://wetechies.blogspot.in");//prototype --> Image(string file [, float x [, float y [, float w [, float h [, string type [, mixed link]]]]]])
}

}

//class instantiation
$pdf=new wetechiesPDF("P","in","A4");//prototype-->
//FPDF([string orientation [, string unit [, mixed size]]]) here P - portrait ,  //in - inches , A4 - size
$pdf->SetMargins(1.5,1.5,1.5);

$pdf->AddPage();
$pdf->SetFont('Times','I',16);

$wetechies1="Group of techies have come together to share there experience in various domains.";
 
$wetechies2="Wetechies is a group of techies post about some technology/domain in
which they are interested, any new thing they learn they will share here ,";
 
$wetechies3 ="its not related to single techi but any one can post here if you want to
share your knowledge and express yourself.";
 
$pdf->SetFillColor(240, 100, 100);

$pdf->SetFont('Times','BU',12);
 

$pdf->Cell(0, .25, "wetechies", 1, 2, "C", 1);
 
$pdf->SetFont('Times','B',12);

//MultiCell(float width, float height, string txt [, mixed border [, string align [, boolean fill]]])

$pdf->MultiCell(0, 0.25,$wetechies1, 1, "J");
$pdf->MultiCell(0, 0.25,$wetechies2, 1, "R");
$pdf->MultiCell(0, 0.25,$wetechies3, 1, "J");

$pdf->AddPage();

$pdf->Write(0.5, $wetechies1.$wetechies2.$wetechies3);
 
$pdf->Output();

?>

/********************************************************************/

You can download the source code  here

Please leave your comments and doubts and suggestions in the comments section :-)

Wednesday, 10 July 2013

Creating and Extracting zip files using PHP

Hi ,

Ever thought of writing your own php code for compressing and extracting your files
??

Then your in the right place , by following this post  you can  zip and unzip your files using a PHP code 
. You can also perform other operations like renaming the  files to be zipped  , getting the index of the file to be zipped , extracting the zipped files to the folder you wish , getting the number of files zipped and the name of the files being zipped etc :-)

Excited ? well here it goes !!!!!!!!!!

Create and Extract zip files using your own PHP program

<?php

$zip = new ZipArchive(); /*creating a variable of the zipArchive class*/ 

$filename = "./wetechies.zip"; /*name of the zip folder you want to create*/


archive, compress, create, extract, extracting zipped file, index of zipped file, PHP, php code for compressing and extracting file, rename, renaming the file to be zipped, unzip, zip, ZipArchive
Compress your files using PHP


/***************Creates the zip folder if it doesn't exists , else it overwrites ***************/

if ($zip->open($filename, ZipArchive::CREATE)!==TRUE) {
    exit("cannot open <$filename>\n");
}

/****************** Lets add 2 files into the zip for demonstration********************/ 

$zip->addFromString("wetechies1.txt" . time(), "#1 welcome to wetechies blog.\n");
$zip->addFromString("wetechies2.txt" . time(), "#2 enjoy reading the blog.\n");

/***********************Just to print some archive details*****************************/
$zip = new ZipArchive();

$zip->open('wetechies.zip');
print_r($zip);
var_dump($zip);
echo "Number of files : " . $zip->numFiles . "\n";
echo "Execution status : " . $zip->status  . "\n";
echo "statusSys : " . $zip->statusSys . "\n";
echo "filename : " . $zip->filename . "\n";
echo "comment : " . $zip->comment . "\n";

for ($i=0; $i<$zip->numFiles;$i++) {
    echo "index : $i\n";
    print_r($zip->statIndex($i));
}

/**************************To print some more additional information**************/

$zip = zip_open("wetechies.zip");

if ($zip) {
    while ($zip_entry = zip_read($zip)) {
        echo "Name of the zip file :               " . zip_entry_name($zip_entry) . "\n";
        echo "Actual Filesize :    " . zip_entry_filesize($zip_entry) . "\n";
        echo "Compressed Size :    " . zip_entry_compressedsize($zip_entry) . "\n";
        echo "Compression Method used : " . zip_entry_compressionmethod($zip_entry) . "\n";

        if (zip_entry_open($zip, $zip_entry, "r")) {
            echo "The File Contents  are :\n";
            $buffer = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
            echo "$buffer\n";

            zip_entry_close($zip_entry);
        }
        echo "\n";

    }

    zip_close($zip);

}

AddPage(), convert doc file into pdf, Creating PDF files using PHP, FPDF, Image(), MultiCell(), PageNo(), PDF, PHP, SetFont(), SetY(),
Extract your files to the folder you wish using PHP



/***************Renaming and extracting the file to  the folder you wish******************/

echo  $zip->locateName('send.php') . "\n";

 $zip->renameIndex(1,'newwetechies.txt');

$zip->extractTo("wetechiesextracted");

$zip->close();
?>

/****************************************************************************************************/


Thats it !!!!


You can download the source code from here
 Any doubts? or suggestion please feel free to comment :-)

Friday, 5 July 2013

what is a heredoc in PHP? want to know read this post

I know many will be curious to know

what is heredoc?


Although I'm expert in PHP I don't know heredoc?

When we learn a new language we will leave some good concepts in that by mistake..

Don't worry here is a short post for you about this

Heredoc was introduced to store large or long text in a variable.

We could do that with a ordinary variable also?

Advantage with heredoc is we can freely use single or double quotes, where ever you need with out a need to remove its special meaning using black slash.

Just use a delimiter which ever you like to specify start and end of the text.

Ex:
               $myheredoc=<<<delimiter
               hi,welcome to "wetechies blog",
               Thanks for visiting :).
               delimiter;

ps: the use of word delimiter is to state the start and end of the
text. Replacing it with any word will not be a problem.

Now if you echo $myheredoc

You will see whole text you have stored..

Impressing right?

 Any doubts? or suggestion please feel free to comment :)

Tuesday, 2 July 2013

Creating a Site in 2 Minutes Using Yes it is (yii) PHP Framework

How to create a simple site using PHP Framework yii

What is Yii?


Yes it is!!! The New PHP Framework

which is very fast than all the existing frameworks :)

The best MVC Framework now..

Lets see how to create a simple site using yii

I always use Netbeans and Dreamweaver for editing PHP files. When it comes to using Framework I prefer Netbeans, very simple to use Frameworks.

For using yii Framework download yii from here


Now in Netbeans

                    goto Tools -> plugins -> Downloaded -> Add plugin

Select the downloaded zip file and click install.

You are done with installing yii framework plugin in netbeans


Now to create a site,

                    click File -> New Project -> PHP -> PHP Application

Then select your localhost folder then click next untill you are prompted to select PHP Frameworks

Select yii Framework !!

Thats it :) You have created a new site yourself feel happy :)

Now a basic introduction to structure of yii, As it is MVC pattern framework

All site control (Actions,Sql commands) will be in controller files -  Protected/Controllers
All logic (access controls,restrictions, validations) will in model files - Protected/models
All files which the user can see (login page, registration page,home page) will be called view files
-Protected/views

This makes things clean and safe and powerfull yii library makes life easier :)

Next thing is when you developed your site and want to host it, make sure you have changed this line

                                         yii='E:\yii-1.1.13.e9e4a0\framework\yii.php';

to point to your current framework location in protected/config/main page :)

Thats all folks :) Now you too a web developer !!!



leave your doubts or suggestions in comments section..

Creating Simple Cloud Based Application

Hi

Having  been obtained a fair enough knowledge about cloud from the previous post .

I am sure you would want to experience the power of cloud by exploring yourself to the cloud .

Here you will learn the basics required to create your own cloud based application .

You may create a commercial app/ game app/ educational app etc , the basic set up that is to be done is more or less the same just with slight changes depending on your requirement .

Here you will be setting up your development environment in the salesforce.com which is one of the cloud service provider , you can choose some other provider like the amazon / vmware / openstack / cloudstack etc

Here it goes !!!!!

Step 1 : Yes its obviously the registration process .
             Get yourself registered from here .

cloud, cloud based Application, cloud environment, cloud serveice provider, cloudstack, commercial application, educational application, game application, openstack, salesforce,


Step 2 : Congrats you have actually completed the set up required . Now to start  using your account in an useful way , read step 3.

Step 3 : Once you have logged in using your account , you can use your cloud environment in three perspective

             1 } Administrator

             2 } Developer

             3 } Monitor

            As an administrator you can perform a wide range of critical/interesting operations like 

                Expand - Manage Users - Level 1Manage Users
                Expand - Manage Apps - Level 1Manage Apps
                Expand - Company Profile - Level 1Company Profile
                Expand - Security Controls - Level 1Security Controls
                Expand - Communication Templates - Level 1Communication Templates
                Expand - Translation Workbench - Level 1Translation Workbench
                Expand - Data Management - Level 1Data Management
                Expand - Mobile Administration - Level 1Mobile Administration
                Expand - Desktop Administration - Level 1Desktop Administration
                Expand - Email Administration - Level 1Email Administration
                Expand - Google Apps - Level 1Google Apps

           Being a developer you have options to Create your own cloud application
and customize it as you wish for your purpose .

           In the perspective of a monitor you have the following options

                  System Overview
                  Imports
                  Case Escalations
                  Mass Emails

Step 4 : What else... customizing your cloud environment for your application .
             Creating the Objects

             To create the objects go to Your user Name, located in the upper-right corner of the
             Main page.        
             Select Setup from the list.

Setup Menu 

               Click on Create and click on Objects and click next and fill in the necessary details
                in the next page .













Step 5 : Similarly you can create your own customized tabs and invoice objects and expand the power of your application to a wide range of areas .



Please feel free to leave your comments or doubts.....

Monday, 1 July 2013

Cloud Computing

CLOUD COMPUTING

cloud, cloud computing, cluster, computing, hardware, iaas, network, OS, paas, rent hardware, rent virtulized servers, saas, server, software delivery, storage, web-based service,

Hello , here is an interesting and very very useful post . I am sure you would have heard the word cloud computing at least a dozen of times. 

Are you confused about the cloud computing world?
well then this post is for you . 

The first and obvious question you would get is what is cloud computing ?

Everything is going to be cloud in a couple of years - In simple words cloud computing is just performing computations in the cloud .

Now worried about the words computations and cloud?

Relax , Cloud is just a cluster of computers.

Cluster is  a group of computers connected to one another to perform some operation as shown in the figure below.
cloud, cloud computing, cluster, computing, hardware, iaas, network, OS, paas, rent hardware, rent virtulized servers, saas, server, software delivery, storage, web-based service,


 Computing can be anything ,
cloud, cloud computing, cluster, computing, hardware, iaas, network, OS, paas, rent hardware, rent virtulized servers, saas, server, software delivery, storage, web-based service,

starting from 1+1=2 to estimating the stock market .
starting from storing your pocket money expense sheet to storing the user profile of 1 billion users.
starting from setting up a LAN for you to chat with your friend to setting up a WAN with a 100 million users

Yes you are reading it right .....and the power of computations in cloud goes on and on ......

Want to know more about it?? Carry on reading , you will end up with interesting facts about the cloud computing world .

Next , you need to understand the 3 main categories of services in the cloud .

1 } Software as a service (SaaS)

2 } Platfrom as a service (PaaS)

3 } Infrastructure as a service (IaaS)


 SaaS is a software delivery method that provides access to software and its functions remotely as a Web-based service. SaaS allows organizations to access their business functionality at a cost which is  less than the cost required for licensed applications.

Advantages of SaaS

Since the software is hosted on remotely , there is no need for additional hardware hence the cost reduces .

The organizations need not perform the installation or set up and maintenance . The cloud providers will do everything on behalf of their clients . etc

Examples

Amazon Rackspace .

*******************************************************************************
 PaaS is a way to rent hardware, operating systems, storage and network capacity over the Internet. This service allows the customer to rent virtualized servers and services for running existing applications or developing and testing new ones.

Advantages of PaaS

This service eliminates the need for purchasing any storage devices and operating systems and other devices required for the network setup .

The client can make use of all the resources of the cloud just by having an internet connection to access the cloud provider's services.

Examples

MS Azure .

*************************************************************************


IaaS is a  model in which an organization outsources the equipment used to support operations, including storage, hardware, servers and networking components. The service provider owns the equipment and is responsible for housing, running and maintaining it. The client typically pays on a per-use basis.

Advantages of IaaS

The user is free from owning and maintaining the storage and hardware and servers .

Examples

Google Apps .

*************************************************************************

Please feel free to leave your comments or doubts
thank you :)


Sunday, 30 June 2013

Synchronization of threads in JAVA

Welcome folks ,

Here's an important topic in the field of programming - Synchronization of threads .

Thread - A thread is a single sequence stream within in a process. Threads have some  properties of processes, therefore they are also  called as lightweight processes .

Thread synchronization is very important because unsynchronized threads lead to race condition .

Lets see how to synchronize the execution of threads in JAVA.

Execute the below program and check the output

class WeTechies
{
    public static void main(String args[])
    {
        WeTechies1 t1 = new WeTechies1("t1: ");
        WeTechies1 t2 = new WeTechies1("t2: ");
        t1.start();
        t2.start();
        boolean t1IsAlive = true;
        boolean t2IsAlive = true;
        do {
           if (t1IsAlive && !t1.isAlive()) {
               t1IsAlive = false;
    System.out.println("t1 is not alive.");
           }
           if (t2IsAlive && !t2.isAlive()) {
               t2IsAlive = false;
               System.out.println("t2 is not alive.");
           }
        } while(thread1IsAlive || thread2IsAlive);
    }
}

class WeTechies1 extends Thread
{
static String message[] = { "Welcome", "to", "we", "techies ."};

    public WeTechies1(String th)
    {
        super(th);
    }

    public void run()
    {
        String threadname = getName();
        for (int i=0;i<message.length;++i) {
           letsWait();
           System.out.println(threadname + message[i]);
        }
    }

    void letsWait()
    {
        try {
           sleep((long)(3000*Math.random()));
        } catch (InterruptedException ex) {
           System.out.println("Thread has been Interrupted!" + ex);
        }
    }
}

This is the output obtained from the above program

t1: Welcome
t1: to
t1: we
t2: Welcome
t2: to
t1: techies .
t1 is not alive.
t2: we
t2: techies .
t2 is not alive.

But the expected output is      Welcome
                                                to
                                                we
                                                techies


We get this un expected output due to the non synchronization between the threads t1 and t2.

In the above program we have created a multi threaded program by creating the WeTechies1 as a  subclass of  the Thread class , which is done using the keyword extend.

Now lets create a program with similar behavior, but we create our threads as objects of the class WeTechies1, which is not a subclass of Thread. WeTechies1 will implement the Runnable interface and objects of WeTechies1 will be executed as threads by passing them as arguments to the Threadconstructor.

class WeTechies
{
    public static void main(String args[])
    {
        Thread t1 =  new Thread(new WeTechies2("thread1: "));;
        Thread t2 =  new Thread(new WeTechies2("thread2: "));;
        t1.start();
        t2.start();
        boolean t1IsAlive = true;
        boolean t2IsAlive = true;
        do {
           if (t1IsAlive && !t1.isAlive()) {
               t1IsAlive = false;
    System.out.println("t1 is not alive.");
           }
           if (t2IsAlive && !t2.isAlive()) {
               t2IsAlive = false;
               System.out.println("t2 is not alive.");
           }
        } while(t1IsAlive || t2IsAlive);
    }
}

class WeTechies2 implements Runnable
{
static String message[] = { "Welcome", "to", "we", "techies ."};
String threadname;
    public WeTechies2(String id)
    {
        threadname = id;
    }

    public void run()
    {
     
        for (int i=0;i<message.length;++i) {
           letsWait();
           System.out.println(threadname + message[i]);
        }
    }

    void letsWait()
    {
        try {
           Thread.currentThread().sleep((long)(3000*Math.random()));
        } catch (InterruptedException ex) {
           System.out.println("Thread has been Interrupted!" + ex);
        }
    }
}

The output of the above program is


thread1: Welcome
thread2: Welcome
thread1: to
thread2: to
thread1: we
thread2: we
thread2: techies .
t2 is not alive.
thread1: techies .
t1 is not alive.

You will find the output to be similar to the previous program but the difference lies in the way the threads are created , this program does not extend the Thread class to create the thread like the previous program did ,  rather it implements the Runnable interface in order to create the thread.


Now lets synchronize the threads in order to get our expected output.

This can be done using the synchronized keyword.

Consider the below program where we synchronize the execution of the threads 1 and 2 using the keyword synchronized in the output() method

class WeTechiesSynchronization
{
    public static void main(String args[])
    {
        WeTechies thread1 = new WeTechies("thread1: ");
        WeTechies thread2 = new WeTechies("thread2: ");
        thread1.start();

        thread2.start();
        boolean thread1IsAlive = true;
        boolean thread2IsAlive = true;
        do {
           if (thread1IsAlive && !thread1.isAlive()) {
               thread1IsAlive = false;
               System.out.println("Thread 1 is dead.");
           }
           if (thread2IsAlive && !thread2.isAlive()) {
               thread2IsAlive = false;
               System.out.println("Thread 2 is dead.");
           }
        } while(thread1IsAlive || thread2IsAlive);
    }
}

class WeTechies extends Thread
{
static String message[] = { "Welcome", "to", "we", "techies ."};

    public WeTechies(String id)
    {
        super(id);
    }

    public void run()
    {
        WeTechiesSynchronizedOutput.output(getName(),message);
    }

    void randomWait()
    {
        try {
           sleep((long)(3000*Math.random()));
        } catch (InterruptedException x) {
           System.out.println("Interrupted!");
        }
    }
}

class WeTechiesSynchronizedOutput
{
           public static synchronized void output(String name,String list[])
          {
                   for(int i=0;i<list.length;++i) {
                   WeTechies t = (WeTechies) Thread.currentThread();
                    t.randomWait();
                    System.out.println(name+list[i]);
                   }
          }
}

The ouput of the above program is

thread1: Welcome
thread1: to
thread1: we
thread1: techies .
Thread 1 is dead.
thread2: Welcome
thread2: to
thread2: we
thread2: techies
Thread 2 is dead.

Now we have got the expected output by making use of the synchronized keyword.

This way the race conditions can be handled hence leading to synchronized execution of the threads.

Please feel free to leave your comments or doubts

thank you :)