Friday, March 30, 2007

AJAX Rot-13 demo

[Technical]

If you don't know what AJAX is:
http://en.wikipedia.org/wiki/AJAX
http://www.w3schools.com/ajax/default.asp

The demo just uses AJAX and CGI (perl) to Rot-13 convert whatever you type in the input field as you keep typing/changing it. The host machine is quite slow, so there might be a considerable delay before you see any change to the output when you're typing.
http://people.csa.iisc.ernet.in/abhijitpai/ajaxdemo.htm

The code of the ajaxdemo.htm and rot13.cgi are pasted below for reference. W3schools holds copyrights of a sizeable portion of the code; but I do think they intended learners to actually use their code; so, I did.

rot13.cgi



#!/usr/bin/perl
use CGI qw(:standard);

$data=param("str");
print "Content-type: text/html","\n\n";

#open(F,">>xx") or die("");
#print F $data;
#print F "\n";
#close(F);

for($i=0;$i<length($data);$i++)
{
$n1=ord(substr($data,$i,1));
if($n1>ord('z') || $n1<ord('A') || ($n1>ord('Z') && $n1<ord('a')))
{next; #C's continue
}

if($n1<=ord('Z'))
{
substr($data,$i,1)=chr(
(
ord(substr($data,$i,1))-ord('A')+1+13
)%26
+ord('A')-1
);
}
else
{
substr($data,$i,1)=chr(
(
ord(substr($data,$i,1))-ord('a')+1+13
)%26
+ord('a')-1
);
}
} #end of for loop
print $data;



ajaxdemo.htm



<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

<head>
<title>Ajax demo</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta http-equiv="Content-Style-Type" content="text/css" />
</head>

<body>

<script type="text/javascript">
function getxobj()
{
var xmlHttp=null;
try
{
// Firefox, Mozilla 1.0(+?),Netscape 7(+?) Opera 8.0+, Safari 1.2(+?)
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{ //IE 6+
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{ //IE 5.5+
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
return xmlHttp;
}

//global
var x;

function mystatechangedfn()
{
/*
0 The request is not initialized
1 The request has been set up
2 The request has been sent
3 The request is in process
4 The request is complete
*/
if(x.readyState==4)
{
//print in perl (after Content-type), echo in php
document.getElementById("myform").resul.value=unescape(x.responseText);
}
}




function docalc()
{

x = getxobj();
x.onreadystatechange=mystatechangedfn;
var url="rot13.cgi?str="+escape(document.getElementById("myform").inpu.value);
//alert(url);
//3rd argument is true if the call is asynchronous.
x.open("GET",url,true);
x.send(null);
}

</script>

<!-- action is needed for xhtml 1.1 compat. -->
<form id="myform" action="">
<!-- onkeydown, call can be with (this.value), but even if not
I can access it as document.getElementById("myform").inpu.value -->
<p>
Input: <input type="text" onkeyup="docalc();" name="inpu" />
Output: <input type="text" name="resul" />
</p>
</form>

<!-- <p>Suggestions: <span id="txtHint"></span></p>
In code: document.getElementById("txtHint").innerHTML="Blah";
-->


<p>
<a href="http://validator.w3.org/check?uri=referer"><img
src="http://www.w3.org/Icons/valid-xhtml11"
alt="Valid XHTML 1.1" height="31" width="88" /></a>
</p>

</body>
</html>


Monday, March 26, 2007

The brilliance of BSNL

My BSNL land line is currently "dead". If I try calling it, I hear the ringing tone. None of my phone-sets ring though; and the caller ID displays are blank. What's brilliant ? The net connection through the same line still works; and it's that line which I'm currently using to type in this post. And it's not a "almost there" internet connection as well. I ran a test at BandwidthPlace and it showed 661.1 kilobits per second, which is about the speed I usually get. (Of course, the phones etc. are connected properly.) This problem had occured earlier too, and had then got sorted out automatically in the course of time (without me complaining).

Update: Phone is fine now after 3+ weeks - apparently "the computer had not registered the complaint" the first time we registered one.

Sunday, March 18, 2007

Abhijit P Pai, B. E.

My degree certificate arrived home at 10:55 a.m. today by Speed Post. It's a laminated sheet, but it's thinner than the marks cards VTU gives. Thankfully, it arrives in a (somewhat) thick blue file which ensured that no damage was done to it in transit.
The rank list (and convocation date) was announced on Feb 7th 2007 was generally known by around Feb 14th. The convocation was on the 25th of Feb in Belgaum, and ordinary (non-rank-holding) students in Bengalooru had started getting their degrees by March 10th.

Saturday, March 10, 2007

Reclaim your GNU/Linux

[Technical]

One of the most common problems that people face with multiple OS's - Windows and GNU/Linux is that the boot loader (Grub) disappears upon re-installing Windows.
This also happens if you have Tux installed in a second hard-disk which you later decide to make your sole hard disk.

For LILO, earlier, with certain versions of Mandrake etc., I used to go through all steps of the installer but the last part where it copies the files (asking it not to make any changes to the partitions), by which time LILO is written on the MBR, after which I boot to Tux and modify its settings.


This is the solution for Grub which works on FC5 (and possibly all other FC distros):
http://www.fedoraforum.org/forum/showthread.php?t=975

For point 4 there, just choose the "Continue" button so that it autodetects.

After this, if the system reports that certain parts only have been mounted into /mnt/sysimage, you might not be able to install Grub on the MBR successfully.

So, vi /mnt/sysimage/etc/fstab or /etc/fstab if you have chroot'ed as mentioned there.
Correct it so that only partitions and drives which actually are present correctly are mentioned.
In the first column of each row, if you have something like "LABEL=/", correct it to the actual device name - i.e. something like "/dev/hda6".
Reboot and repeat; if your hard disk is still ok, most probably the autodetection will come out clean.