** AMAZING APPS**

On Saturday, I had attended an unconference meeting regarding Apps. It was
a great event. Unfortunately, I was not a participant in that event but still
gained alot of knowledge.

A no. of Apps were discussed there by the participants, here I am going to
tell a few of them which I found most interesting.

1.  Unified Remote

Its an App through which we can control our laptop and computer system. I 
found it interesting because if in case you are not able to sit on chair to 
operate your computer system or your peripherals are not working. In these 
cases this App is magical for you.
This App is available for Android, iPhone and Windows phone.
You need to install this app on your phone as well as on the system which you
want to control.

2. Smart Tools

This app is having near about 38 functions in it. I am here explaning 
a few of them. One is its having a RULER inside, Hence, it removes the need 
of having a protactor in your bag. Other is you can check the height or
length of anything,Hence removes the need of Scale, Measuring tape.
Its having a truth tester inside for fun. It can also calculate Distance, 
Width,area etc.

3. Hackers Keyboard

Its an app having keyboard exactly as of your computer system. In case
you want your PC keypad in your phone as you remember that keypad much and
found it easier as all the keys are easily seen there. In this case you
can use this app. You can also adjust the size of the keyboard. There are 
different themes available in this app.

4. App Lock
I use this app personally and found it very useful. You can hide your 
personal data like photos, videos, Apps using this app. You can hide
this app too from the icons and by typing #your_password in the call log
you can directly jump to this app. There is another app AUDIO MANAGER, from 
the name no one can guess that it can lock apps, photos etc.

There are many other Apps like, Measure your land, Photo math , Single Equation,
Google translate ,heartbeat, Orbut etc which can reduce human efforts.
Advertisements

MORE USING CGI

HOW TO RUN A C++ SOURCE CODE PROGRAM IN BROWSER?

There are many ways of displaying output of a c++ program on browser.

One of the way (without script) using HTML is already discussed in my previous blog.

Here are two ways of displaying only c++ source code program on browser.

I. Screenshot from 2016-02-23 19-16-37

There is a header called as Content-Type

Content-Types
The following are the common formats/content-types:

Format/Content-Type
HTML- text/html
Text- text/plain
Gif- image/gif
JPEG- image/jpeg
Postscript- application/
MPEG- video/mpeg

To declare the Content-Type, the CGI script must output:

Content-Type: content-type specification

Typically the Content-Type will be declared to produce HTML. So, the first line of our CGI script will look like this:

Content-Type: text/html

Depending on the Content-Type defined, the data that follows the header declaration will vary.

here, we are using

Content-Type: text/plain

OUTPUT:

Screenshot from 2016-02-23 19-26-47

II. Moving on to Second Method

Screenshot from 2016-02-23 20-18-14

Explanation of above code

Here, I have made two files:

  1. fact.cpp
  2. fact

Both these files should be in the same directory “/usr/lib/cgi-bin”.

Give permissions to both the files .

The file with name “fact” is a script file.

1. In the line “#!/bin/sh” #!(i.e. hash bang) means to include the shell “sh” to interpret the following code and execute the script. In place of “sh” we can write “bash”, “dash”. All these are shells to interpret the code.

2.  The word “echo” is used to output status text to the screen or a file. It is used to get the feedback.

3.   The HTML <pre> element (or HTML Preformatted Text) represents preformatted text. Text within this element is typically displayed in a non-proportional font exactly it is laid out in a file. Here “new.cpp” is the file with output filename “n”. Whitespace inside this element is displayed as typed.

4.   The HTML </pre> is the closing element.

Now compile the c++ program through “sudo g++ fact.cpp -o n”,where “n” is the output filename.

At web browser search the URL “localhost/cgi-bin/fact”.

Screenshot from 2016-02-23 20-18-43

Above are the ways of displaying a simple c++ program on the browser.

 

Much more is yet to come about CGI. So keep an eye 😉

**TASK 2: MY 2nd BLOG POST**

A.HOW TO MAKE YOUR PC A WEB SERVER?

B.HOW TO RUN A C++ PROGRAM THROUGH CGI?

A. THE Ist PART……….

WEB SERVER: A web server is an information technology that processes requests via HTTP, the basic network protocol used to distribute information on the World Wide Web. The term can refer either to the entire computer systemor specifically to the software that accepts and supervises the HTTP requests.

I am here going to do it on ubuntu..
INSTALLATION PROCESS

GO to the TERMINAL.

GIVE Commands like these to install APACHE2(A Web Server)

sudo apt-get update

sudo apt-get install apache2

IT WILL TAKE SOME TIME TO INSTALL..

You can check whether its instaled properly or not by typing the command

service apache2 statusScreenshot from 2016-02-11 20:37:30

You can check it other way too by typing localhost or your IP ADDRESS in any browser,then it will show this page

Screenshot from 2016-02-11 20:39:15

THAT’S IT, its so simple within 2 steps… your system is a WEB BROWSER now

B.NOW, THE 2nd PART…

There are many ways to configure apache2 under different directories,one way is explained here:

By default apache2 is stored under etc folder in ubuntu

  • cd  /etc/apache2
  • ls
  • cd sites available ‘or’ cd conf-enabled
  • ls
  • cat 000-default.conf ‘or’ cat serve-cgi-bin.conf
  • cd /usr/lib/cgi-bin

 

 

IMPORTANT:

For giving PERMISSIONS to your cgi bin and to your saved program you need to give these commands other wise you can not save your program under CGI-BIN

sudo a2enmod cgi

sudo/etc/init.d/apache2 restart

sudo service apache2 restart

CGI: It stands for common gateway interface.Its a standard way for web server to pass web user’s request to an application program and to receive data back to forward to the user

STEP1: PROGRAM

U need to save your program in cgi-bin folder so that it can run on LOCALHOST……..

The common MIME(multipurpose internet mail extensions) types are text/plain for unformatted text and text/html for HTML formated content.

Short for Multipurpose Internet Mail Extensions, a specification for formatting messages so that they can be sent over the Internet. Many e-mail clients now support MIME, which enables them to send and receive graphics, audio, and video files via the Internet mail system.

Screenshot from 2016-02-11 21:21:05

this is a simple program written using html content too.

now , i had saved this program with name second.cgi..so

in terminal type these commands now

STEP2: EXECUTION

Screenshot from 2016-02-11 21:25:34

STEP3: DISPLAY THROUGH CGI

Screenshot from 2016-02-19 15:37:21

or you can change the background colour by using this instruction in program

cout<< “<body bgcolor= blue> “

Screenshot from 2016-02-19 16:01:51

Now, TO RUN A C++ USER INPUT PROGRAM THROUGH CGI………

What’s new here is the part after the “?”. The information after the “?” character is known as a query string. When the server is passed a URL with a query string, it calls the CGI program identified in the first part of the URL (before the “?”) and then stores the part after the “?” in the environment variable QUERY_STRING. A Query String, by its name suggest that it is a string used to ‘Query’. The query string begins after the first ‘?’ character. Query strings are usually used to pass a list of variables

The following is a CGI program called fact.cpp that uses query information supplied by the form. (form is dicussed after this)

#include <iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
int main()
{
string value, s; // declaration
s = getenv(“QUERY_STRING”); // s stores the query string extracted from URL
int a =s.length(); // a stores length of query string
int b =s.find(“=”); // b stores the index number or simply number where “=” is found in the string
value = s.substr(b+1,a); // value stores the value part of the string specified after “=”
double fact = 1;
double factorial;
int n= atof(value.c_str()); // atof() converts string to int which gets stored in n

for (int i=1; i<=n; i++) // for loop for calculating factorial
{
fact= fact*i;
}
factorial = fact;

cout<< “Content-Type : text/html \n\n”;

cout<< “<html> <head> <title> factorial </title> </head>”;

cout<< “<body bgcolor= green> “;

cout<< “<h2 color= blue> Factorial of “<< n <<” is: “<< factorial << “</h2>”;
cout<< ” </body> </html>”;
return 0;
}

 

 

This program is placed in /usr/lib/cgi-bin

Compile it using the command :
g++ fact.cpp -o fact.cgi
This creates an executable file fact.cgi in /usr/lib/cgi-bin
Make sure, fact.cgi has executable permissions. If not, Change the permissions of this file as :
chmod 777 fact.cgi

Explanation:Every file and folder contain a 8-bit data that control the permissions. At its basic binary form, it will be “000”, which means no permissions of any form is granted. When you set a “Read” permission, it will add 4-bit to the data, making it “100” (in binary format) or a “4” in the usual decimal format. Setting a “Write” permission will add 2-bit to the data, making it “010” and “2” in decimal form. Lastly, setting an “Execute” permission adds 1-bit to the data, which will result in “001”, or “1” in decimal form. In short:

  • Read is equivalent to ‘4’.
  • Write is equivalent to ‘2’.
  • Execute is equivalent to ‘1’

When we want to set permissions, we just add up the number. For example, to set the permissions to read and write, we will use ‘6’ (4 + 2) for the permission. For read, write and execute, we will use ‘7’ (4 + 2 + 1) for the permission. Here’s the different permutation:

0 – no permission
1 – execute
2 – write
3 – write and execute
4 – read
5 – read and execute
6 – read and write
7 – read, write, and execute

now,
Make sure the cgi-bin directory has executable permissions. If not, change them by executing the chmod command in the directory /usr/lib as:
chmod 777 cgi-bin

Form supplies the query string to this CGI program. The following is the program, named as form.cpp that contains the form in CGI format.

#include<iostream>
using namespace std;

int main()
{
cout<<“Content-Type: text/html \n\n”;
cout<<” <html><head><title>C++</title></head>”;
cout<<“<body bgcolor = green ><form action=/cgi-bin/fact.cgi method=get><p> <h3>Enter any Number</h3></p><input type=text name=n><p><h4><input type = submit value= Submit ></h4> </p></form></body></html>”;
return 0;
}

This program is also placed in /usr/lib/cgi-bin
Compile it using the command :
g++ form.cpp -o form.cgi
This creates an executable file form.cgi in /usr/lib/cgi-bin
Make sure, form.cgi has executable permissions. If not, Change the permissions of this file as :
chmod 777 form.cgi
Some of these commands may require root permissions. For this, use sudo before the command.

Screenshot from 2016-02-17 21:30:16Screenshot from 2016-02-17 21:30:20

NOTE..

GIVE DATATYPE LONG OR DOUBLE INSTEAD OF INT . SO, THAT UA PROGRAM CAN SHOW OUTPUT UPTO MORE NUMBERS……

Another program is to print a table…

#include <iostream>
#include<stdlib.h>
#include<string.h>
using namespace std;
int main()
{
string value, s; // declaration
s = getenv(“QUERY_STRING”); // s stores the query string extracted from URL
int a =s.length(); // a stores length of query string
int b =s.find(“=”); // b stores the index number or simply number where “=” is found in the string
value = s.substr(b+1,a); // value stores the value part of the string specified after “=”
int c=1,table;
int n= atof(value.c_str()); // atof() converts string to int which gets stored in n
int m=10;
cout<< “Content-Type : text/html \n\n”;

cout<< “<html> <head> <title> table </title> </head>”;
cout<< “<body bgcolor= green> “;
for (int i=0; i<=m; i++) // for loop for calculating factorial
{
c=n*i;
table=c;
cout<< “<h2 color= blue>”<< i <<” * “<<n<<“=”<< table << “</h2>”;}

cout<< ” </body> </html>”;
return 0;
}

 

and let tb here is one which supplies QUERY STRING to CGI.. its saved as tb.cgi

#include<iostream>
using namespace std;

int main()
{
cout<<“Content-Type: text/html \n\n”;
cout<<” <html><head><title>C++</title></head>”;
cout<<“<body bgcolor = red ><form action=/cgi-bin/tab.cgi method=get><p> <h3>Enter any Number</h3></p><input type=text name=n><p><h4><input type = submit value= Submit ></h4> </p></form></body></html>”;
return 0;
}

Screenshot from 2016-02-19 20:08:29Screenshot from 2016-02-19 20:08:34

STRUGGLES:

  1. Didn’t know first about give permissions to cgi folder and program.
  2. TERMINAL is case sensitive. do write commands properly
  3. check the location where cgi-bin is stored
  4. got to know litttle bit about html by doing this task as i m not familiar with this language.

 A presentation copy of  this project is available on

presentation on reveal.js

THANKS…….. 🙂