/* Ajith - Syntax Higlighter - End ----------------------------------------------- */

9.30.2008

CERN's LHC is also powered by GNU/LINUX

Everyone knew about Large Hadron Collider (LHC) Experiment (a snip at $10 billion) conducted by CERN.
The Large Hadron Collider (LHC) is the world's largest and highest-energy particle accelerator complex, intended to collide opposing beams of protons or lead, two of several types of hadrons, at up to 99.99 percent the speed of light.

CERN played a pivotal part in the evolution of the internet we know and love today. Tim Berners-Lee invented the hypertext link when he was working at CERN as an independent contractor in the 1980s. He saw the opportunity to link his hypertext to the Transmission Control Protocol (TCP) and the Domain Name System (DNS) The rest, as they say, is history.
Berners-Lee designed the first web browser, built the fist server and the first website was launched at CERN in August 1991. And he gave away world wide web to the world as a gift for Free.

CERN is home to not only a spirit of free enquiry, but to the use of free software itself. For starters CERN’s 20,000 servers use GNU/Linux. In fact they developed their own version of Scientific Linux (SL), a recompiled version of Red Hat Enterprise Linux, in conjunction with Fermilab and other labs across the world.


Coming to LHC experiment, LHC will output data on a truly massive scale that threatens to simply overwhelm the bandwidth of the current web: it is reported that the experiment will produce one gigabyte of data every second and that deluge requires a whole new way of handling data and distributing petabytes of information.

To solve that problem CERN came up with the Grid. This is being seen widely as the future of the web. Two large bottlenecks have been identified: the shortage of IP addresses and bandwidth. The former is being solved with the introduction of IPv6 which should render addresses virtually inexhaustible. As the number of users and web-enabled devices grows however and the web churns out more and more data, the other choke point therefore becomes bandwidth. CERN’s solution is The Grid.

The primary architecture of the computing grid is the “TIER” and there are three of them: 0, 1 and 2. The first centres on CERN itself, the second covers various sites across Asia, Europe and North America and the third is represented by individual labs, universities and private companies. Tier 0 - capable of managing up to 10 gigabytes per second across fibre optic cables. Checkout ZDNet's video on CERN's 3D digital camera.


CERN’s choice of GNU/Linux is no one off. To manage such a vast data output from the LHC some controlling software was required to manage the petabytes of data for users sitting at their computers across the world on the computing grid and GNU?LINUX is the best option for it. Users need to access the data transparently even though it is sitting on geographically disparate servers housing those petabytes. It is the opensource community that plays a great role in all the scientific experiments as well as in new innovative stuff. It is quite clear that even if it is a Super computer or a billion dollar Scientific Experiment or a new innovative technology it is the opensource community and GNU/LINUX that comes for the rescue rather than the propreitary stuff.

Actual link where you can have much more information about this topic is at this link.

9.16.2008

Client Server example with PIPES

This example shows a combined use of unnamed and named pipes to produce a client–server relationship. Let us discuss first about the PROBLEM we are going to try.

There is a single Server process which runs continuously in background eventhough if there is no client to interact with it. Client processes runs in foreground and interacts with the server process. Both the client and server processes will run on the same machine (So server process will run background forever until it is manually killed).

The Client process accepts a command (probably a shell command) from the user and send's it to the Server via a FIFO which is a public channel between Client and Server for processing. Let us name this FIFO as PUBLIC fifo since its existence is known to all clients and the server. Once the command is received, the Server executes it using the popen–pclose sequence (which generates an unnamed pipe in the Server process). After execution Server process should return the output of the command executed to the client over a FIFO which is a private channel between the client and server. Let us name this FIFO as PRIVATE fifo. The Client, upon receipt, displays the output on the screen.

NOTE: Each and every Client process should have its own unique PRIVATE fifo to receive information from Server.

Check out the diagrammatic representation of the PROBLEM.


To ensure that both Server and Client processes use the same PUBLIC fifo name and have the same message format for the data sent through the FIFO, a local header file named local.h is created.
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <linux/limits.h>
#include <string.h>
#include <stdio.h>

#define B_SIZE (PIPE_BUF/2)

const char *PUBLIC = "/tmp/PUBLIC";

struct message {
char fifo_name[B_SIZE];
char cmd_line[B_SIZE];
};

The format of the message sent over the PUBLIC fifo is declared within the struct statement. The message structure consists of two character array's namely fifo_name, stores the name of the PRIVATE fifo of the Client process and cmd_line, stores the command to be executed by the Server.

Let us checkout the functionality steps of a newly created Client process.
  [1].  Create a unique name for the PRIVATE fifo and invoke it.
  [2].  Open the PUBLIC fifo in write mode.
  [3].  Prompt for command from user.
  [4].  Write command to PUBLIC fifo for Server to process.
  [5].  Open PRIVATE fifo in read mode to read the contents from Server..
#include "local.h"
int main()
{
int publicfifo, privatefifo, n;
static char buffer[PIPE_BUF];
struct message msg;

/*Using sprintf to create a unique fifo name
and save into message structure*/
sprintf(msg.fifo_name, "/tmp/fifo%d", getpid());

/*Creating the PRIVATE fifo*/
if(mknod(msg.fifo_name, S_IFIFO | 0666, 0) < 0) {
  perror(msg.fifo_name);
  exit(1);
}

/*Opening PUBLIC fifo in WRITE ONLY mode*/
if((publicfifo = open(PUBLIC,O_WRONLY)) < 0) {
  unlink(msg.fifo_name);
  perror(PUBLIC);
exit(1);
}

while(1) {

  write(fileno(stdout), "\n cmd>", 6);
  memset(msg.cmd_line, 0x0, B_SIZE);
  n = read(fileno(stdin), msg.cmd_line, B_SIZE);

if(strncmp("quit", msg.cmd_line, n-1) == 0) {
  break;
}

write(publicfifo, &msg, sizeof(msg));

if((privatefifo = open(msg.fifo_name, O_RDONLY)) < 0) {
  printf("1\n");
  perror(msg.fifo_name);
  goto CLEANUP;
}

while((n = read(privatefifo, buffer, PIPE_BUF)) > 0) {
  write(fileno(stderr), buffer, n);
}

close(privatefifo);
}

CLEANUP:
close(publicfifo);
unlink(msg.fifo_name);

return 0;
}

Now we will check the Server process.
  [1].  Generate a PUBLIC fifo and open it in both read and write mode. Wait for the message from a Client process.
  [2].  Read the message from PUBLIC fifo.
  [3].  Open the Client's PRIVATE fifo in write mode.
  [4].  Execute the command from Client process using popen.
  [5].  Write the output into Client's PRIVATE fifo.
#include "local.h"

int main() {

int privatefifo, dummyfifo, publicfifo, n, done;
struct message msg;
FILE *fin;
static char buffer[PIPE_BUF];

/*creating the PUBLIC fifo*/
mknod(PUBLIC, S_IFIFO | 0666, 0);

/*
Server process opens the PUBLIC fifo in write mode to make sure that
the PUBLIC fifo is associated with atleast one WRITER process. As a
result it never receives EOF on the PUBLIC fifo. The server process
will block any empty PUBLIC fifo waiting for additional messages to
be written. This technique saves us from having to close and reopen
the public FIFO every time a client process finishes its activities.
*/

if( (publicfifo = open(PUBLIC, O_RDONLY)) < 0 ||
(dummyfifo = open(PUBLIC, O_WRONLY | O_NDELAY)) < 0) {
   perror(PUBLIC);
   exit(1);
}

/*Read the message from PUBLIC fifo*/
while(read(publicfifo, &msg, sizeof(msg)) > 0) {

n=0;
done=0;

do {
  if((privatefifo = open(msg.fifo_name, O_WRONLY|O_NDELAY)) == -1) {
    sleep(5);
  }
  else {
    fin = popen(msg.cmd_line, "r");
    write(privatefifo,"\n",1);

    while((n= read(fileno(fin), buffer, PIPE_BUF)) > 0) {
      write(privatefifo, buffer, n);
      memset(buffer, 0x0, PIPE_BUF);
    }

    pclose(fin);
    close(privatefifo);
    done = 1;
  }
}while(n++ < 5 && !done);

if(!done) {
  perror("Not accessed the private fifo\n");
  exit(1);
}

}
return 0;
}

Compile server.c and client.c and generate server, client executable's. A sample execution of the client-server programs is shown below

[bash]$./server &                                  
[1] 27107

[bash]$./client
cmd>ps
PID TTY TIME CMD
14736 pts/3 00:00:00 csh
27107 pts/3 00:00:00 server
27108 pts/3 00:00:00 client
27109 pts/3 00:00:00 6
cmd>who
gray pts/3 Feb 27 11:28
cmd>quit

$./kill -9 27107
[1] Killed server
$

7.15.2008

Blogger: Optimize post title for more visitors and search engine results

When we search for the posts of a blog in google or yahoo we will find out that the post title is displayed as

Blog Title + Post Title

Such titles really doesn't attract much traffic to your blog. But it is the default setting in our blog template code. Now we will tweak the HTML code of our blog template to optimize the post title for search engines in a more attractive format

Post Title + Blog Title

This tweak will take a while for the Formatted titles to appear in search results(will appear when it is reindexed) but I am sure that it will increase the traffic to your blog.

Check out my post "Editing the HTML code of a Blogger Beta Template" to know how to edit the html code of the blogger template.

Search for the code <title><data:blog.pageTitle/></title> and replace the code with the following code
<b:if cond='data:blog.pageType == &quot;index&quot;'>
<title><data:blog.pageTitle/></title>
<b:else/>
<title><data:blog.pageName/> ~ <data:blog.title/></title>
</b:if>

So use the tweak for more traffic.

7.13.2008

Converting .djvu file to .pdf file

DjVu (pronounced déjà vu) is a computer file format designed primarily to store scanned images, especially those containing text and line drawings. Basically some of the ebooks and comics are present in this format.

Portable Document Format (PDF) is a file format created by Adobe Systems as a represention for two-dimensional documents in a manner independent of the application software, hardware, and operating system. This is the most popular file format used for data and ebooks.

Since DjVu is not so popular as PDF I decided to share the cheap and best way to convert the DjVu format file into PDF format file.

1. Download & Install FreePDF which is used to print the documents as pdf files.
http://www.shbox.de/fpxpdownload.htm

2. Download DjVu viewer namely windjview. It is a sourceforge project so it can be downloaded freely and it is a few kilo bytes file.
http://sourceforge.net/projects/windjview

3. Now open the djvu file with windjview.

4. Choose "print" option and SELECT FreePDF as the PRINTER to print the file as PDF file.

So we successfully converted the djvu file into pdf freely and easily.

Blogger: Setting labels as horizontal tabs

In this post I will discuss how to set the labels in blogger as a horizontal tabs.

NOTE: Read this post completely before you start tweaking your blog.

Since we are about to modify the HTML code of your blog template backup your complete blogger template. Check out my post on Editing the HTML code of a Blogger Beta Template to know how to perform template backup. Also make sure that your blog has posts with labels assigned to them if not nothing will be working out.

Step 1:

Download the free CSS navigation menus from the Exploding Boy website. Once you download the entire set unzip it and decide which type of menu you are going to include in your site. Then we have to upload these GIF images to any photosharing site or any place in internet so that we can access them directly. There are many options like Photobucket, Picasa, Googlepages.

Step 2:

Now we have to change the Header so that it can include page elements. Search for id="header" in html code of your blog's template and modify this line:

<b:section class="header" id="header" maxwidgets="1" showaddelement="no">

as

<b:section class="header" id="header" maxwidgets="2" showaddelement="yes">

Step 3:

Now we will prepare the CSS portion of the tweak. I have uploaded the images tableftF.gif and tabrightF.gif which are related to Menu style F at the links

http://www.site.com/tableftF.gif
and
http://www.site.com/tabrightF.gif

So you have to replace those links in the code with the appropriate links where you have uploaded those images. Below is the CSS code for menu style F:
#tabsF
{
float:left;
width:100%;
font-size:80%;
line-height:normal;
border-bottom:1px solid #000;
}

#tabsF ul
{
margin:0;
padding:10px 10px 0 50px;
list-style:none;
}

#tabsF li
{
display:inline;
margin:0;
padding:0;
}

#tabsF a
{
float:left;
background:url(" http://www.site.com/tableftF.gif") no-repeat left top;
margin:0;
padding:0 0 0 4px;
text-decoration:none;
}

#tabsF a span
{
float:left;
display:block;
background:url(" http://www.site.com/tabrightF.gif") no-repeat right top;
padding:5px 15px 4px 6px;
color:#666;
}

/* Commented Backslash Hack hides rule from IE5-Mac \*/
#tabsF a span {float:none;}
/* End IE5-Mac hack */
#tabsF a:hover span
{
color:#FFF;
}

#tabsF a:hover
{
background-position:0% -42px;
}

#tabsF a:hover span
{
background-position:100% -42px;
}

Step 4

Now we have to add the Label Widget. Insert the following Widget code
<b:widget id='Label10' locked='false' title='' type='Label'>
<b:includable id='main'>
<div id='tabsF'>
<ul>
<li><a expr:href='data:blog.homepageUrl'><span>Home</span></a></li>
<b:loop values='data:labels' var='label'>
<li><a expr:href='data:label.url'><span><data:label.name/></span></a></li>
</b:loop>
</ul>
<!-- <b:include name='quickedit'/> -->
</div>
</b:includable>
</b:widget>

NOTE: By using the above code by default tabs for all your labels is created. If you got more number of labels then the tabs for all labels is created by default i.e. If there are 30 labels in your blog then 30 tabs are created which don't looks good. So I modified the green lines in the above code in this way so that we can include only those labels which we want to add.
<b:widget id='Label10' locked='false' title='' type='Label'>
<b:includable id='main'>
<div id='tabsF'>
<ul>
<li><a expr:href='data:blog.homepageUrl'><span>Home</span></a></li>

<b:loop values='data:labels' var='label'>

<!--I am adding the label - Linux in this code -->
<b:if cond='data:label.name == "Linux"'>
<a expr:href='data:label.url'>
<span>
<data:label.name/>
</span>
</a>
</b:if>

<!--I am adding the label - Opensource in this code -->
<b:if cond='data:label.name == "Open Source"'>
<a expr:href='data:label.url'>
<span>
<data:label.name/>
</span>
</a>
</b:if>

</b:loop>

</ul>
<!-- <b:include name='quickedit'/> -->
</div>
</b:includable>
</b:widget>

Depending upon your requirement you can add as many labels you want.

NOTE: If you use a CSS menu style other than F, than make sure id='tabsF' reflects the correct tab, such as id='tabsE' for style E. Later, if you like a different design, just cut-and-paste the style's CSS code, then change this id again to reflect the change. Check out the Tabs in my blog.


Checkout the CSS code for other Menu styles from A to F

/*- Menu Tabs A --------------------------- */

#tabs {
float:left;
width:100%;
background:#BBD9EE;
font-size:93%;
line-height:normal;
}
#tabs ul {
margin:0;
padding:10px 10px 0 50px;
list-style:none;
}
#tabs li {
display:inline;
margin:0;
padding:0;
}
#tabs a {
float:left;
background:url("http://www.site.com/tableft.gif") no-repeat left top;
margin:0;
padding:0 0 0 4px;
text-decoration:none;
}
#tabs a span {
float:left;
display:block;
background:url("http://www.site.com/tabright.gif") no-repeat right top;
padding:5px 15px 4px 6px;
color:#666;
}
/* Commented Backslash Hack hides rule from IE5-Mac \*/
#tabs a span {float:none;}
/* End IE5-Mac hack */
#tabs a:hover span {
color:#FF9834;
}
#tabs a:hover {
background-position:0% -42px;
}
#tabs a:hover span {
background-position:100% -42px;
}

/*- Menu Tabs B--------------------------- */

#tabsB {
float:left;
width:100%;
background:#F4F4F4;
font-size:93%;
line-height:normal;
}
#tabsB ul {
margin:0;
padding:10px 10px 0 50px;
list-style:none;
}
#tabsB li {
display:inline;
margin:0;
padding:0;
}
#tabsB a {
float:left;
background:url("http://www.site.com/tableftB.gif") no-repeat left top;
margin:0;
padding:0 0 0 4px;
text-decoration:none;
}
#tabsB a span {
float:left;
display:block;
background:url("http://www.site.com/tabrightB.gif") no-repeat right top;
padding:5px 15px 4px 6px;
color:#666;
}
/* Commented Backslash Hack hides rule from IE5-Mac \*/
#tabsB a span {float:none;}
/* End IE5-Mac hack */
#tabsB a:hover span {
color:#000;
}
#tabsB a:hover {
background-position:0% -42px;
}
#tabsB a:hover span {
background-position:100% -42px;
}

/*- Menu Tabs C--------------------------- */

#tabsC {
float:left;
width:100%;
background:#EDF7E7;
font-size:93%;
line-height:normal;
}
#tabsC ul {
margin:0;
padding:10px 10px 0 50px;
list-style:none;
}
#tabsC li {
display:inline;
margin:0;
padding:0;
}
#tabsC a {
float:left;
background:url("http://www.site.com/tableftC.gif") no-repeat left top;
margin:0;
padding:0 0 0 4px;
text-decoration:none;
}
#tabsC a span {
float:left;
display:block;
background:url("http://www.site.com/tabrightC.gif") no-repeat right top;
padding:5px 15px 4px 6px;
color:#464E42;
}
/* Commented Backslash Hack hides rule from IE5-Mac \*/
#tabsC a span {float:none;}
/* End IE5-Mac hack */
#tabsC a:hover span {
color:#FFF;
}
#tabsC a:hover {
background-position:0% -42px;
}
#tabsC a:hover span {
background-position:100% -42px;
}

/*- Menu Tabs D--------------------------- */

#tabsD {
float:left;
width:100%;
background:#FCF3F8;
font-size:93%;
line-height:normal;
border-bottom:1px solid #F4B7D6;
}
#tabsD ul {
margin:0;
padding:10px 10px 0 50px;
list-style:none;
}
#tabsD li {
display:inline;
margin:0;
padding:0;
}
#tabsD a {
float:left;
background:url("http://www.site.com/tableftD.gif") no-repeat left top;
margin:0;
padding:0 0 0 4px;
text-decoration:none;
}
#tabsD a span {
float:left;
display:block;
background:url("http://www.site.com/tabrightD.gif") no-repeat right top;
padding:5px 15px 4px 6px;
color:#C7377D;
}
/* Commented Backslash Hack hides rule from IE5-Mac \*/
#tabsD a span {float:none;}
/* End IE5-Mac hack */
#tabsD a:hover span {
color:#C7377D;
}
#tabsD a:hover {
background-position:0% -42px;
}
#tabsD a:hover span {
background-position:100% -42px;
}

/*- Menu Tabs E--------------------------- */

#tabsE {
float:left;
width:100%;
background:#000;
font-size:93%;
line-height:normal;

}
#tabsE ul {
margin:0;
padding:10px 10px 0 50px;
list-style:none;
}
#tabsE li {
display:inline;
margin:0;
padding:0;
}
#tabsE a {
float:left;
background:url("http://www.site.com/tableftE.gif") no-repeat left top;
margin:0;
padding:0 0 0 4px;
text-decoration:none;
}
#tabsE a span {
float:left;
display:block;
background:url("http://www.site.com/tabrightE.gif") no-repeat right top;
padding:5px 15px 4px 6px;
color:#FFF;
}
/* Commented Backslash Hack hides rule from IE5-Mac \*/
#tabsE a span {float:none;}
/* End IE5-Mac hack */
#tabsE a:hover span {
color:#FFF;
}
#tabsE a:hover {
background-position:0% -42px;
}
#tabsE a:hover span {
background-position:100% -42px;
}

/*- Menu Tabs F--------------------------- */

#tabsF {
float:left;
width:100%;
background:#efefef;
font-size:93%;
line-height:normal;
border-bottom:1px solid #666;
}
#tabsF ul {
margin:0;
padding:10px 10px 0 50px;
list-style:none;
}
#tabsF li {
display:inline;
margin:0;
padding:0;
}
#tabsF a {
float:left;
background:url("http://www.site.com/tableftF.gif") no-repeat left top;
margin:0;
padding:0 0 0 4px;
text-decoration:none;
}
#tabsF a span {
float:left;
display:block;
background:url("http://www.site.com/tabrightF.gif") no-repeat right top;
padding:5px 15px 4px 6px;
color:#666;
}
/* Commented Backslash Hack hides rule from IE5-Mac \*/
#tabsF a span {float:none;}
/* End IE5-Mac hack */
#tabsF a:hover span {
color:#FFF;
}
#tabsF a:hover {
background-position:0% -42px;
}
#tabsF a:hover span {
background-position:100% -42px;
}

/*- Menu Tabs G--------------------------- */

#tabsG {
float:left;
width:100%;
background:#666;
font-size:93%;
line-height:normal;
}
#tabsG ul {
margin:0;
padding:10px 10px 0 50px;
list-style:none;
}
#tabsG li {
display:inline;
margin:0;
padding:0;
}
#tabsG a {
float:left;
background:url("http://www.site.com/tableftG.gif") no-repeat left top;
margin:0;
padding:0 0 0 4px;
text-decoration:none;
}
#tabsG a span {
float:left;
display:block;
background:url("http://www.site.com/tabrightG.gif") no-repeat right top;
padding:5px 15px 4px 6px;
color:#FFF;
}
/* Commented Backslash Hack hides rule from IE5-Mac \*/
#tabsG a span {float:none;}
/* End IE5-Mac hack */
#tabsG a:hover span {
color:#FFF;
}
#tabsG a:hover {
background-position:0% -42px;
}
#tabsG a:hover span {
background-position:100% -42px;
}

/*- Menu Tabs H--------------------------- */

#tabsH {
float:left;
width:100%;
background:#000;
font-size:93%;
line-height:normal;
}
#tabsH ul {
margin:0;
padding:10px 10px 0 50px;
list-style:none;
}
#tabsH li {
display:inline;
margin:0;
padding:0;
}
#tabsH a {
float:left;
background:url("http://www.site.com/tableftH.gif") no-repeat left top;
margin:0;
padding:0 0 0 4px;
text-decoration:none;
}
#tabsH a span {
float:left;
display:block;
background:url("http://www.site.com/tabrightH.gif") no-repeat right top;
padding:5px 15px 4px 6px;
color:#FFF;
}
/* Commented Backslash Hack hides rule from IE5-Mac \*/
#tabsH a span {float:none;}
/* End IE5-Mac hack */
#tabsH a:hover span {
color:#FFF;
}
#tabsH a:hover {
background-position:0% -42px;
}
#tabsH a:hover span {
background-position:100% -42px;
}

/*- Menu Tabs I--------------------------- */

#tabsI {
float:left;
width:100%;
background:#EFF4FA;
font-size:93%;
line-height:normal;
border-bottom:1px solid #DD740B;
}
#tabsI ul {
margin:0;
padding:10px 10px 0 50px;
list-style:none;
}
#tabsI li {
display:inline;
margin:0;
padding:0;
}
#tabsI a {
float:left;
background:url("http://www.site.com/tableftI.gif") no-repeat left top;
margin:0;
padding:0 0 0 5px;
text-decoration:none;
}
#tabsI a span {
float:left;
display:block;
background:url("http://www.site.com/tabrightI.gif") no-repeat right top;
padding:5px 15px 4px 6px;
color:#FFF;
}
/* Commented Backslash Hack hides rule from IE5-Mac \*/
#tabsI a span {float:none;}
/* End IE5-Mac hack */
#tabsI a:hover span {
color:#FFF;
}
#tabsI a:hover {
background-position:0% -42px;
}
#tabsI a:hover span {
background-position:100% -42px;
}

/*- Menu Tabs J--------------------------- */

#tabsJ {
float:left;
width:100%;
background:#F4F4F4;
font-size:93%;
line-height:normal;
border-bottom:1px solid #24618E;
}
#tabsJ ul {
margin:0;
padding:10px 10px 0 50px;
list-style:none;
}
#tabsJ li {
display:inline;
margin:0;
padding:0;
}
#tabsJ a {
float:left;
background:url("http://www.site.com/tableftJ.gif") no-repeat left top;
margin:0;
padding:0 0 0 5px;
text-decoration:none;
}
#tabsJ a span {
float:left;
display:block;
background:url("http://www.site.com/tabrightJ.gif") no-repeat right top;
padding:5px 15px 4px 6px;
color:#24618E;
}
/* Commented Backslash Hack hides rule from IE5-Mac \*/
#tabsJ a span {float:none;}
/* End IE5-Mac hack */
#tabsJ a:hover span {
color:#FFF;
}
#tabsJ a:hover {
background-position:0% -42px;
}
#tabsJ a:hover span {
background-position:100% -42px;
}

/*- Menu Tabs K--------------------------- */

#tabsK {
float:left;
width:100%;
background:#E7E5E2;
font-size:93%;
line-height:normal;
border-bottom:1px solid #54545C;
}
#tabsK ul {
margin:0;
padding:10px 10px 0 50px;
list-style:none;
}
#tabsK li {
display:inline;
margin:0;
padding:0;
}
#tabsK a {
float:left;
background:url("http://www.site.com/tableftK.gif") no-repeat left top;
margin:0;
padding:0 0 0 4px;
text-decoration:none;
}
#tabsK a span {
float:left;
display:block;
background:url("http://www.site.com/tabrightK.gif") no-repeat right top;
padding:5px 15px 4px 6px;
color:#FFF;
}
/* Commented Backslash Hack hides rule from IE5-Mac \*/
#tabsK a span {float:none;}
/* End IE5-Mac hack */
#tabsK a:hover span {
color:#FFF;
background-position:100% -42px;
}
#tabsK a:hover {
background-position:0% -42px;
}
#tabsK a:hover span {
background-position:100% -42px;
}

7.11.2008

Blogger: Editing the HTML code of a Blogger Beta Template

In this post we will be checking out How to Edit the HTML code of template of a Blogger BETA.

Once you login into blogger.com by default you will be landing into "Dashboard" which shows the list of blogs that have been created by you.

Since we are editing the layout of the blog we have to click the "Layout" link to check the layout of the blog. Then you will be seeing a page that has a look similar to one shown below.
Now you can see three tabs namely Posting, Settings, Layout. Depending upon your template you will be having different options under Layout tab and I got Page Elements, Fonts & colors, Edit HTML, Pick New Template.

If you have to pick a new predefined template from google you have to click the option "Pick New Template". As I decided to show how to edit the HTML of the existing template I will be clicking "Edit HTML" option.Then you will be seeing a view similar to as shown below.
Before you modify the HTML of the BLOGGER template remember that you have to backup the existing template code so that even if any problem occurs because of modification of HTML code we can revert back to previously working HTML code. Click the "Download Full Template" link to backup the existing template code. The backup is saved as a .xml file. If you have to revert back to previously existing code which is saved in your harddisk just upload it by clicking the upload button.

By default "Expand Widget Templates" is not checked. Before we modify the HTML code we have to check it so that the code related to each and every widget that is present in our blog is shown up.
Once modifying the code present in the HTML editor we have to save the template or preview it using the appropriate button shown in above figure. Even if anything goes wrong we can revert back to the previous code as we already performed the backup of our previous code.

7.09.2008

How to: Checking Hardware Configuration of a Computer

Whenever we buy a Laptop or a Desktop we will configure our DREAM machine with certain hardware specifications .. like x GHz processor, Graphic card with y memory and so on. But once we receive our shipment we don't know whether our DREAM machine is fitted with right configuration or not.

Since there is a chance of getting wrong hardware components during the time of assembly of our PC let us see one of the easy way to check the PC/Laptop hardware configuration without unscrewing it by using a PC audit software named Belarc Advisor.

Coolest thing about Belarc Advisor is it produces a detailed report of not only about the hardware configuration but also builds a detailed profile of the installed software, missing Microsoft hotfixes, anti-virus status, CIS (Center for Internet Security) benchmarks of your PC. The output is finally displayed in a webpage. And all these services are provided by Belarc Advisor in free for personal use.

So stop thinking about how to know the hardware configuration of your Laptop/Desktop and start using the Belarc Advisor.

Checkout the site: http://www.belarc.com/free_download.html"

6.16.2008

Calculate Time in Linux

Calculating time in LINUX in milliseconds and Seconds. We should include sys/time.h header file and the remaining sample code is

struct timeval start;

we wil be using gettimeofday system call whose syntax is
int gettimeofday(struct timeval *tv, struct timezone *tz); where

struct timeval
{
time_t tv_sec;···············/* seconds */
suseconds_t tv_usec;······/* microseconds */
};


/* To calculate time in seconds*/

gettimeofday(&start, NULL);
starttime = start.tv_sec + start.tv_usec/1000000;


/* To calculate time in milliseconds*/

gettimeofday(&start, NULL);
starttime = start.tv_sec*1000 + start.tv_usec/1000;

6.14.2008

Using GOOGLE as proxy to hide IP-Adress

NOTE (UPDATED on FEBRUARY 30th 2009): This trick seems to be no more fool proof as sites like tracemyip tracks down your exact IP-Adress even by using the Google Translation Service.

We know that GOOGLE has changed the way we access the web. It has simply became the stepping stone for any body who want to know information about anything in this world .. offcourse of universe too. It had wide variety of web based applications namely search, maps, gmail, gears, adsense, adwords, analyzers, language translators and many in its arsenal.

Now we can use one of the services of GOOGLE as proxy so that we can access the web anonymously without revealing our ipadress, location of our ISP. You might be wondering how our location is revealed out? Let us try out a simple experiment. Just visit the site

http://www.ip-adress.com/
We can see that the site reveals my ISP ipadress as 59.164.98.133 and my ISP location in a google map as Bangalore. If we further check out the site we can find out that the site has ecen information about our browser version, plugins installed, our screen resolution and many other things got revealed.
So how does GOOGLE service can be used a proxy? Let us check out the language translation service provided by the GOOGLE. You can get the link to this service if you type www.google.com and we can see a link to language tools or just click this link.

http://www.google.co.in/language_tools?hl=en

Once you click you are into that page we can see a option named "Translate a Webpage" with options to translate from one language to other. Note we cant translate same language to the same one i.e. for example from English to English. If we try to do it we get a GOOGLE ERROR.
Not let us try to access the site http://www.ip-adress.com/ asking GOOGLE translation service to convert the site from from French to English. Since nothing French is there in that site is simply displayed in English.
Strange it displays my ISP ip-adress as 209.85.170.136 and its location as United States. If I check out the site further I found out that I am getting redirected via google server present at Mountain View, US which is acting as proxy to access the site http://www.ip-adress.com/.
So we can access the any site in this way without revealing our information much. Thats really cool trick to stay anonymous. But there is a problem by doing so as the images cannot seen properly by using this technique. But even if a site is bocked we can access its content in this way. I tried out this trick on one of the torrent sites that are blocked but I can still access its contents.

5.28.2008

Converting mobilephone into webcam

Camera in a mobilephone is getting better day by day and reached upto 5MP with good clarity and cool features. Until now we have used mobile camera for just taking pictures and recording video's. But now we can even use it as a webcam for chatting online on any popular messenger service available.

Let us check out some of the cool softwares that converts a camera phone into a webcam.

Mobiola
It converts your phone into a webcam via Bluetooth or through USB cable.It consists of two parts - a PC application with virtual camera driver and Symbian sis application for smartphone.Features:
  • Transforms your mobile phone into high-quality PC webcam.
  • Connects through USB or Bluetooth.
  • Screen Capture functionality.
  • Works with Skype, Yahoo, YouTube, MSN, AOL IM, ICQ and many others as standard USB webcam.
List of compatible devices (Check out the home site for updated list)
RIM Blackberry - Any Blackberry devices equipped with camera
Windows Mobile - Windows Mobile 5 and 6 devices equipped with camera including Smartphones
Nokia 6600, 6620, 7610, 6630, 6670, 6260,6680, 6681, 6682, 3230, N70,N90, 3250, 5500, E50, E51, E65, E70, E90, N71, N73, N76, N80, N81, N82, N91,N92, N93, N93i, N95, N96
Sony-Ericsson P1i, P990, M600, W950, W960, P800, P900, P910, P990, G700, G900
Motorola Z8, Z10

If you don't have a webcam, or want a more versatile solution to your current cam, then Mobiola WebCam is an essential download.

Limitations:
30 day Trial Period Limited to 5 minutes connection.

Actual Link: http://www.warelex.com/

WWigo
This is an alternative for Mobiola since it is free to use. It has got all most all the features supported by Mobiola.

Actual Link: http://www.motvik.com/

4.07.2008

TinTin E-Book collection

There are download links available below each and every Image of the TiTle book ... If any problem in seeing them please leave a comment .....

01. Tintin in the Land of the Soviets (1930)



02. Tintin in the Congo (1931)



03. Tintin in America (1932)



04. Cigars of the Pharaoh



05. The Blue Lotus (1936)



06. The Broken Ear



07. The Black Island (1938)



08. King Ottokar's Sceptre (1939)



09. The Crab with the Golden Claws (1941)



10. The Shooting Star (1942)



Checkout TinTin ebook collection part2 for the books from 11 to 20

Checkout TinTin ebook collection part3 for the remaining editions.

4.03.2008

Optimization levels in GCC

Compilers have become pretty smart as they can perform all sorts of code transformations — from simple inlining to sophisticated register analysis — that make compiled code run faster.

In most situations, faster is better than smaller, because disk space and memory are quite cheap for desktop users. However, for embedded systems small is often at least as important as fast because of a commonplace environment consisting of extreme memory constraints and no disk space, making code optimization a very important task.

Optimization is a complex process. For each high-level command in the source code there are usually many possible combination's of machine instructions that can be used to achieve the appropriate final result. The compiler must consider these possibilities and choose among them.

In general, different code must be generated for different processors, as they use incompatible assembly and machine languages. Each type of processor also has its own characteristics -- some CPU's provide a large number of registers for holding intermediate results of calculations, while others must store and fetch intermediate results from memory. Appropriate code must be generated in each case.

Furthermore, different amounts of time are needed for different instructions, depending on how they are ordered. GCC takes all these factors into account and tries to produce the fastest executable for a given system when compiling with optimization.

Turning optimization flags ON makes the compiler attempt to improve the performance and/or code size at the expense of compilation time and possibly the ability to debug the program.

NOTE: While the GCC optimizer does a good job of code optimization, it can sometimes result in larger or slower images (the opposite of what you may be after). It’s important to test your image to ensure that you’re getting what you expect. When you don’t get what you expect, changing the options you provide to the optimizer can usually remedy the situation.

Let us see various optimization levels provided by GCC

LEVEL 0: -O0 Optimization
At this optimization level GCC does not perform any optimization and compiles the source code in the most straightforward way possible. Each command in the source code is converted directly to the corresponding instructions in the executable file, without rearrangement. This is the best option to use when debugging with a source code debugger (such as the GNU Debugger, GDB). It is the default level of optimization if no optimization level option is specified. It can be specified as
[bash]$gcc -O0 hello.c -o hello
or
[bash]$gcc hello.c -o hello

NOTE: -O0 is actually -(Capital O)(Number 0). Similarly -O1 is -(Capital O)(Number 1).

LEVEL 1: -O1 Optimization (-O)
In the first level of optimization, the optimizer’s goal is to compile as quickly as possible and also to reduce the resulting code size and execution time. Compilation may take more time with -O1 (over -O0), but depending upon the source being compiled, this is usually not noticeable. Level 1 also has two sometimes conflicting goals. These goals are to reduce the size of the compiled code while increasing its performance. The set of optimizations provided in -O1 support these goals, in most cases.

The -O1 optimization is usually a safe level if you still desire to safely debug the resulting image. Check out the table given below for optimizations enabled at different levels.

NOTE: Any optimization can be enabled outside of any level simply by specifying its name with the -f prefix, for example, to enable the defer-pop optimization, we would simply define this as
[bash]$ gcc -fdefer-pop hello.c –o hello

We could also enable level 1 optimization and then disable any particular optimization using the -fno- prefix, like this:
[bash]$ gcc -O1 -fno-defer-pop -o test test.c

This command would enable the first level of optimization and then specifically disable the defer-pop optimization.

LEVEL 2: -O2 Optimization
The second level of optimization provides even more optimizations (while including those in -O1, plus a large number of others). Only optimizations that do not require any speed-space tradeoffs are used, so the executable should not increase in size. The compiler will take longer to compile programs and require more memory than with -O1. This option is generally the best choice for deployment of a program, because it provides maximum optimization without increasing the executable size. It is the default optimization level for releases of GNU packages. The second level is enabled as shown below:
[bash]$gcc -O2 hello.c -o hello


LEVEL 2.5: -Os Optimization
The special optimization level (-Os or size) enables all -O2 optimizations that do not increase code size; it puts the emphasis on size over speed. This includes all second-level optimizations, except for the alignment optimizations. The alignment optimizations skip space to align functions, loops, jumps and labels to an address that is a multiple of a power of two, in an architecture-dependent manner. Skipping to these boundaries can increase performance as well as the size of the resulting code and data spaces; therefore, these particular optimizations are disabled.

-Os optimization level simply disables some -O2 optimizations like -falign-labels, -falign-jumps, -falign-labels, and -falign-functions. Each of these has the potential to increase the size of the resulting image, and therefore they are disabled to help build a smaller executable. The size optimization level is enabled as:
[bash]$gcc -Os hello.c -o hello

In gcc 3.2.2, reorder-blocks is enabled at -Os, but in gcc 3.3.2 reorder-blocks is disabled.

LEVEL 3: -O3 Optimization
The third and highest level enables even more optimizations by putting emphasis on speed over size. This includes optimizations enabled at -O2 and rename-register. The optimization inline-functions also is enabled here, which can increase performance but also can drastically increase the size of the object, depending upon the functions that are inlined. The third level is enabled as:
[bash]$gcc -O3 hello.c -o hello

Although -O3 can produce fast code, the increase in the size of the image can have adverse effects on its speed. For example, if the size of the image exceeds the size of the available instruction cache, severe performance penalties can be observed. Therefore, it may be better simply to compile at -O2 to increase the chances that the image fits in the instruction cache.

Architecture Specification
The optimizations discussed thus far can yield significant improvements in software performance and object size, but specifying the target architecture also can yield meaningful benefits.

The -march option of gcc allows the CPU type to be specified

The default architecture is i386. GCC runs on all other i386/x86 architectures, but it can result in degraded performance on more recent processors. If you're concerned about portability of an image, you should compile it with the default. If you're more interested in performance, pick the architecture that matches your own.


References:

1. Optimization in GCC
2. An Introduction to GCC - for the GNU compilers gcc and g++.

2.19.2008

Compilation process in GCC

Compiling a C program - Compiling a simple C program using gcc.

Above article is a high level view of compliation in gcc. In present article let us see in depth view of the compilation order or flow in gcc which is a default C compiler in GCC.

gcc goes through a sequence of different intermediate steps before generating final executable. Those intermediate steps are the result of different tools which are invoked internally to complete the compilation of the source code.

The whole Compilation process is broken down into following phases:

  • Preprocessing
  • Compilation
  • Assembly
  • Linking

As an example, we will examine these compilation stages individually using the same ‘hello.c’ program given below:

#include <stdio.h>
#define STRING "Hello World"

int main (void)
{
printf ("My First program - %s\n",STRING);
return 0;
}

NOTE: We dont need to manually go through all the intermediate stages to generate a executable using gcc. All these stages are directly taken care transparently by gcc internally, and can be seen using the -v option.

Although 'hello.c' program is very simple it uses external header files and libraries, and so exercises all the major steps of the compilation process. If we compile the 'hello.c' with a simple command namely gcc hello.c then we end-up creating an executable file called a.out.

Back in the days of the PDP computer, a.out stood for "assembler output". Today, it simply means an older executable file format. Modern versions of Unix and Linux use the ELF executable file format. The ELF format is much more sophisticated. So even though the default filename of the output of gcc is "a.out", its actually in ELF format.

The Preprocessor
Basically C Preprocessor is responsible for 3 tasks namely:
  • Text Substitution,
  • Stripping of Comments, and
  • File Inclusion.
Text Substitution and File Inclusion is requested in our source code using Preprocessor Directives.

The lines in our code that begin with the “#” character are preprocessor directives.

In 'hello.c' program the first preprocessor directive requests a standard header file, stdio.h, be included into our source file. The other one requests a string substitution to take place in our code.

So in preprocessor stage those included header files and defined macros are expanded and merged within the source file to produce a transitory source file, which the standard calls a Translation unit. Translation units are also known as compilation units.

The C preprocessor, often known as cpp, is a macro processor that is used automatically by the C compiler to transform a C program before compilation. To perform just preprocessing operation use the following command:
[bash]$ cpp hello.c > hello.i
The result is a file named hello.i which contains the source code with all macros expanded.

By convention, preprocessed files are given the file extension ‘.i’ for C programs and ‘.ii’ for C++ programs.

NOTE: By default the preprocessed file is not saved to disk unless the -save-temps option is used in gcc so we are just using the redirection operator to save a copy of preprocessed file.

By using gcc's “-E” flag we can directly do the pre-processing operation.
[bash]$ gcc -E hello.c -o hello.i
Now we will try to check the contents of the preproccessed input file. Since the stdio.h file is fairly large the resultant output is cleaned up a bit.
# 1 "hello.c"
# 1 "/usr/include/stdio.h" 1 3
# 1 "/usr/include/_ansi.h" 1 3
# 1 "/usr/include/sys/config.h" 1 3
# 14 "/usr/include/sys/config.h" 3
# 25 "/usr/include/sys/config.h" 3
# 44 "/usr/include/sys/config.h" 3

# 40 "/usr/include/stdio.h" 2 3
# 1 "/usr/include/sys/reent.h" 1 3

int main(void){

printf ("My First Program - %s\n", "HELLO WORLD" );
return 0;
}
Since our program has requested the stdio.h header be included into our source which in turn, requested a whole bunch of other header files. So, the preprocessor made a note of the file and line number where the request was made and made this information available to the next steps in the compilation process. Thus, the lines,
# 40 "/usr/include/stdio.h" 2 3
# 1 "/usr/include/sys/reent.h" 1 3
indicates that the reent.h file was requested on line 40 of stdio.h. The preprocessor creates a line number and file name entry before what might be "interesting" to subsequent compilation steps, so that if there is an error, the compiler can report exactly where the error occurred.

The Compiler
The next stage of the process is the actual compilation of the preprocessed source code to assembly language, for a specific processor (Depending upon the target processor architecture the source code is converted into particular assembly language and it can be known as cross-compilation).

By using “-S” flag with gcc we can convert the preprocessed C source code into assembly language without creating an object file:
[bash]$ gcc -Wall -S hello.i -o hello.s
The resulting assembly language is stored in the file ‘hello.s’.

NOTE: The assembly code generated depends upon the PC architecture and other reasons. I am just attaching the assembly code generated with the Cygwin - Linux Emulator.


NOTE: Above Assembly code contains a call to the external printf function.

The Assembler
We know that MACHINES (i.e. a computer) can understand only Machine-Level Code. So we require an ASSEMBLER that converts assembly code in "hello.s" file into machine code. Eventhough it is a straightforward one-to-one mapping of assembly language statements to their machine language counterparts, it is tedious and error-prone if done manually.

NOTE: ASSEMBLER was one of the first software tools developed after the invention of the digital electronic computer.

If there are any calls to external functions in the assembly code, the Assembler leaves the addresses of the external functions undefined, to be filled in later by the Linker.

The Assembler as in gcc can be invoked as shown below.
[bash]$ as hello.s -o hello.o
As with gcc, the output file is specified with the -o option. The resulting file ‘hello.o’ contains the machine level code for 'hello.c' program.

or

By using “-c” flag in gcc we can convert the assembly code into machine level code:
[bash]$ gcc -c hello.c
The Linker
The final stage of the compilation process is producing a single executable program file by linking set of object files. An object file and an executable file come in several formats such as ELF (Executable and Linking Format) and COFF (Common Object-File Format). For example, ELF is used on Linux systems, while COFF is used on Windows systems.

In practice, an executable file requires many external functions from system and C run-time libraries. The linker will resolve all of these dependencies and plug in the actual address of the functions.

The linker also does a few additional tasks for us. It combines our program with some standard routines that are needed to make our program run. For example, there is standard code required at the beginning of our program that sets up the running environment, such as passing in command-line parameters and environment variables. Also, there is code that needs to be run at the end of our program so that it can pass back a return code, among other tasks. It turns out that this is no small amount of code.

Actually the mechanism used internally by gcc to link up different files is a bit complicated. For example, the full command for linking the 'hello.c' program might look as shown below:
[bash]$ ld -dynamic-linker /lib/ld-linux.so.2/usr/lib/crt1.o /usr/lib/crti.o /usr/lib/gcc-lib/i686/3.3.1/crtbegin.o-L/usr/lib/gcc-lib/i686/3.3.1 hello.o -lgcc -lgcc_eh -lc -lgcc -lgcc_eh/usr/lib/gcc-lib/i686/3.3.1/crtend.o /usr/lib/crtn.o
Luckily we are never asked to type the above command directly -- the entire linking process is handled transparently by gcc when invoked as follows:
[bash]$ gcc hello.o
This links the object file ‘hello.o’ to the C standard library, and produces an executable file ‘a.out’.
[bash]$ ./a.out
My First Program - Hello World
An object file for a C++ program can be linked to the C++ standard library in the same way with a single g++ command.