thoughts, ideas, code and other things...

Thursday, June 28, 2007

GTAVC – Appu Ghar Stories

What a memorable, fun-filled day at Appu Ghar and the waterpark with Yash and Jaideep. In a few days I will leave for Bangalore and would possibly live there after 4 years at college. I hear Appu Ghar will be closed down shortly.

Filled with excitement, I made our own version of GTA Vice City cover -

GTAVC - Appu Ghar Stories

Labels: , ,

E-Learning : Online Course wares

We all know about MIT OpenCourseWares, but my friend Deepak Krishnan has got more for you.

E-learning has become popular especially in the last decade. Many universities have started providing online courses and also course materials.
I was just going through some of the university sites to find out some tutorials for myself when I got ... (Click here to get the whole list on his blog)
Courtesy : Deepak Krishnan

Labels: ,

Wednesday, June 27, 2007

Ajax based supercomputing !

What is AJAX? (on Wiki)
Wikipedia states that “AJAX, shorthand for Asynchronous Javascript and XML, is a Webdevelopment technique for creating interactive web applications. The intent is to makeweb pages feel more responsive by exchanging small amounts of data with the serverbehind the scenes, so that the entire web page does not have to be reloaded each timethe user makes a change. This is meant to increase the web page's interactivity, speed,and usability."
checkout more at adaptive path website

And, for me ajax is simply the right combination of javascript and xml that takes user interactivity to a whole new level.

For example when you are surfing an ajaxified webpage, in most cases you won't need to reload the whole page to access a particular content. Ajax will facilitate the transfer of content in the backround! ( see: google search ajaxified )

Even noticed how fast Gmail is, atleast it seems faster than old rediffmail in terms of interactivity. That's because Gmail uses javascripts to get the content in the background instead of reloading the whole page.

You can checkout the Ajax Web Application Model at-

Now comes the Next Big Thing. Ever thought how many hits does Google get in a day. Ever wondered about how many hours people spend watching User Generated Content on Youtube. Okay, think about this - If youtube was totally ajaxified, the main page would never be needed to reload as the content can be transferred through underlying XMLHTTPRequest API using javascript. That means, when an average user spends half an hour, he will never reload the page.

Anyways do checkout the alexa stats for yahoo, google and youtube.

Okay, thats all right, but where is the point ?
The big point is in utilizing the processing power of the web browsers that access these web services on daily basis. What I am talking about is distributed computing through web. Now you might think it will be damn slow and it depends on people's wish to let the browser window remain. But, we do have a solution for that, we can ajaxify all the links, so websites like youtube can easily retain a user for about half an hour for average.
Given the fact that these web giants get a lot of hits a day, we can always assume that we will have a great processing power in this distributed network.

So guys at yahoo, microsoft, google, ibm, ... Think about it dudes!
Anyways don't worry about patents, I'm not gonna file one, you guys proceed.
Well guys, thats all from idea box of a school passout.

Labels: , ,

Thursday, June 21, 2007

The Killer semicolon ';'

We all know what semi-colon does. ';' it terminates. Exactly!!
But sometimes it terminates good things too like a ruthless terminator. Specially in cases of if..else, and loops - while, do while, for.
Lets see -

';' kills if..else
int main() {
int a=5;
int b=0;

if (a < b);
printf ("b is less than a\n");

return 0;
';' kills while loops
int main() {
int a=5;
int b=0;

while (b<5);

printf ("b = %i\n",b);
return 0;
and the tyranny goes on with for and do while loops


Saturday, June 16, 2007

Swapping two vars without using third one

Now this is pretty easy, basically taught to anyone who begins programming BASIC, C, Java etc. More importantly it lets one ponder about how actually the 'swap' function of BASIC works. When you have figured out that, then you say, oh yea, so this is how swap works, maybe next day I can figure out how printf in C works, or what about atoi ?!
And what else ? Besides, all said above, it also teaches you how to optimize our work by eating less memory! so here's our little snippet -
#include <stdio.h>

int main (void) {
int a=5,b=7;
printf (" a = %i , b = %i \n",a,b);

printf ("after swap \n a = %i , b = %i \n",a,b);

return 0;


Wednesday, June 06, 2007

Round brackets save the day!

While constructing logical statements in C/C++, you must care about telling C what you want. And you should tell it as clearly as possible. Thats where round brackets enter the scene. Take this for example -
int i = 2;
if ( !i == 5 ) {
printf ( " i is not equal to 5 \n" );
} else {
printg ( " i is equal to 5 \n " );
In absence of proper parentheses, this code would result in telling you that 'i is equal to 5'.
What we wish to tell C is - Look, let i be 2. If (i==5) isn't the case, tell the user about it.
The problem is that "!i" means NOT(i), and C evaluates conditions from left to right.
So NOT(i) in this case is NOT(2) i.e. 1 ( or 10 become 01 in machine terms). Obviously 1 isn't equal to 5 and program ends up telling us that i is 5.
While if we use parentheses, the logic is better understood by C and any other programmer too.
int i = 2;
if ( ! ( i == 5) ) {
printf ( " i is not equal to 5 \n" );
} else {
printg ( " i is equal to 5 \n " );


C takes logical shortcuts.

Look at this :
if ( a && b && c && d && e && f && g && h &&  i  ||  j ) {
.... do the job ...
One would think that this is a very long condition to evaluate. You would say it will take time to go through checking all of a...j variables. But, C doesn't like to toil uselessly. Just in case b is FALSE, C would immediately stop evaluating other variables d,e,f,g,h which are connected by logic AND. It would simply evaluate j in this case and apply OR.
So, in this case performance of program will definitely depend on what values have a,b,c,d,e,f,g,h have got. The earlier C finds a FALSE among them, the faster will the code run!
One can even call this short circuiting!


What determines ouput (cast operators)

Okay, we know 5/4 = 1.25. So, if we have to do it in C, one would think of storing it in a float or double variable. i.e.

int i, j; double k; i = 5; j = 4;
k = i/j;
printf ("%lf" , k);

Now one would think that output will be 1.25. One would think that 5/4 equals 1.25 and since we are storing this result in a float type variable, it should be nicely done!
Alas! this won't happen because whenever an operation is performed, C takes into account the data-type of the operands. So the above code will assign 1 to k.
The solution to this is the cast operators. So using them we would have a modified code to get 1.25 as follows -
int i, j; double k; i = 5; j = 4;
k = (double) i / j;
printf ("%lf" , k);
int i, j; double k; i = 5; j = 4;
k = i / (double) j;
printf ("%lf" , k);
or even
int i, j; double k; i = 5; j = 4;
k = (double) i / (double) j;
printf ("%lf" , k);
All of these will give 1.25 as output. But the following won't -
    int i, j; double k; i = 5; j = 4;
k = (double) ( i / j );
printf ("%lf" , k);
Simply because i/j is being performed even before casting to double.


Truth, in C

Now in C, boolean data-type doesn't exist. Instead we use integers for the purpose. Conventionally 0 is false, and anything other than 0 is true. So,

if (32)
printf ("This will always be printed\n");
if (0)
printf ("This will never get printed. \n");
In the above code-snippet, its obvious that output is "This will always be printed".
Lets have another one -

int j, j;
j = 5;
i = i > 45;
pintf ( "i = %i" , i );
No here, the logic "i>45" will get evaluated and result stored in i. So, since j isn't actually greater than 45, i will contain 0. Had j been of the value 46 or 100 , i will get assigned 1.

Inside stuff :
Okay this is about C. What about how computer decides true/false?
The answer is yet interesting, what a computer actually does is that it sees everything in binary number system. So, a zero will always look like
0 or 000000 or 0000000000000
and anything other than a zero is bound to have the digit '1' at at least one place in the binary equivalent. So, the machine just sees if all the bits are 0, if thats the situation, it means FALSE. If even a single one is encountered, it means TRUE.

So how was it ?


Postfix or Prefix!

Its really interesting to note that for incrementing a variable say j by one, we can simply write j++; instead of j=j+1;
But, hardly do we think of ++j;
Lets see an example :

#include <stdio.h>
int main(void) {
int i,j;
printf ("i = j++; makes i = %i and j = %i\n",i,j);
printf ("i = ++j; actually makes i = %i and
at same time j = %i\n",i,j);
system("pause"); //tested on win98,xp,2k
return 0;

The output would be like-
i = j++; makes i = 2 and j = 3
i = ++j; actually makes i = 3 and at same time j = 3

Now if you try that one out, you will notice that i=++j; actually modifies j first and then puts it in i. So we can conclude that -

In case of i=j++; , the process breaks into -
1. i=j;
2. j++;
In case of i=++j; the following happens -
1. j++;
2. i=j;


Saturday, June 02, 2007

VB Games, SudoSol and QuizMaster

SudoSol - The Sudoku Solver
All right, this is yet another program to solve your Sudokus . Interesting point is, that it can't solve all sudokus. But if you take 10 sudokus to test it, it will most probably solve 6-7 of them completely. Don't let yourself down, if it can't solve, it can always take you near the solution!
All coding is in VisualBasic, and is based on elimination of similarities along rows, columns and inside the 3x3 boxes.

Coming up next is the
QuizMaster 1.0
Now, this is pretty simple implementation of Visual Basic and the Oracle dbms. So the key areas this program deals with is User Interface for interaction to the database, and, application of a dbms in education. Nothing much to say about it. All it offers is -
To create quizzes, to modify quizzes, to set negative and positive scoring scheme, to add comments to a quiz-bank, to store performance records of user and...

So, thats all for my class 12th projects in Informatics Practices.
(psst - I know its stupid to call these bunch of crap apps - VB GAMES, pacman that i created 3.5 years ago is much more suitable for such title!)

Labels: , , ,