Saturday, January 31, 2009

This will be useful code......

/*
* How to search for images and restrict them by size.
* This demo will also show how to use Raw Searchers, aka a searcher that is
* not attached to a SearchControl. Thus, we will handle and draw the results
* manually.
*/

google.load('search', '1');

function searchComplete(searcher) {
// Check that we got results
if (searcher.results && searcher.results.length > 0) {
// Grab our content div, clear it.
var contentDiv = document.getElementById('content');
contentDiv.innerHTML = '';

// Loop through our results, printing them to the page.
var results = searcher.results;
for (var i = 0; i < results.length; i++) {
// For each result write it's title and image to the screen
var result = results[i];
var imgContainer = document.createElement('div');

var title = document.createElement('h1');
// We use titleNoFormatting so that no HTML tags are left in the title
title.innerHTML = result.titleNoFormatting;

var newImg = document.createElement('img');
// There is also a result.url property which has the escaped version
newImg.src = result.unescapedUrl;
newImg.href = result.unescapedUrl;

imgContainer.appendChild(title);
imgContainer.appendChild(newImg);

// Put our title + image in the content
contentDiv.appendChild(imgContainer);
}
}
}

function OnLoad() {
// Our ImageSearch instance.
var imageSearch = new google.search.ImageSearch();

// Restrict to extra large images only
imageSearch.setRestriction(google.search.ImageSearch.RESTRICT_IMAGESIZE,
google.search.ImageSearch.IMAGESIZE_MEDIUM);

// Here we set a callback so that anytime a search is executed, it will call
// the searchComplete function and pass it our ImageSearch searcher.
// When a search completes, our ImageSearch object is automatically
// populated with the results.
imageSearch.setSearchCompleteCallback(this, searchComplete, [imageSearch]);

// Find me a beautiful car.
imageSearch.execute("Subaru STI");
}
google.setOnLoadCallback(OnLoad, true);
http://upcoming.yahoo.com/services/api/ for finding events...

Flicker API for images http://www.flickr.com/services/api/

Yahoo maps API http://gallery.yahoo.com/maps

Use this: http://developer.yahoo.com/maps/ajax/
Wonderful use: http://www.dataffect.com/usgs/#



Order matters: As is the case generally with JavaScript and CSS, order matters; javascript and css files should be included in the order specified above. If you include files in the wrong order, errors may result.

api.php?action=query&meta=siteinfo&siprop=namespaces&format=xml
api.php?action=query&generator=search&gsrsearch=meaning&prop=info
api.php?action=query&generator=search&gsrsearch=meaning&prop=info&meta=siteinfo&siprop=namespaces&format=xml


get all the pages which uses given image title
api.php?action=query&generator=imageusage&giutitle=Image:Albert%20Einstein%20Head.jpg&prop=info

return all the images given in a page
api.php?action=query&generator=images&titles=Main%20Page&prop=info

this is themoviedb.org API's

good for movie name caste actors and youtube links
http://api.themoviedb.org/2.0/docs/details/movie.search.html
Also helpful in getting information
Need to call first search method and extract movie id
use that movie id for fetching information.

TheMovieDB will be very useful in searching for movie information and related information.

Friday, January 30, 2009

Data API's

http://upcoming.yahoo.com/services/api/ for finding events...

Flicker API for images http://www.flickr.com/services/api/

Yahoo maps API http://gallery.yahoo.com/maps

Use this: http://developer.yahoo.com/maps/ajax/
Wonderful use: http://www.dataffect.com/usgs/#



Order matters: As is the case generally with JavaScript and CSS, order matters; javascript and css files should be included in the order specified above. If you include files in the wrong order, errors may result.

Wednesday, January 28, 2009

Space trimming

import java.util.regex.*;

public class BlankRemover
{

/* remove leading whitespace */
public static String ltrim(String source) {
return source.replaceAll("^\\s+", "");
}

/* remove trailing whitespace */
public static String rtrim(String source) {
return source.replaceAll("\\s+$", "");
}

/* replace multiple whitespaces between words with single blank */
public static String itrim(String source) {
return source.replaceAll("\\b\\s{2,}\\b", " ");
}

/* remove all superfluous whitespaces in source string */
public static String trim(String source) {
return itrim(ltrim(rtrim(source)));
}

public static String lrtrim(String source){
return ltrim(rtrim(source));
}

public static void main(String[] args){
String oldStr =
"> <1-2-1-2-1-2-1-2-1-2-1-----2-1-2-1-2-1-2-1-2-1-2-1-2> <";
String newStr = oldStr.replaceAll("-", " ");
System.out.println(newStr);
System.out.println(ltrim(newStr));
System.out.println(rtrim(newStr));
System.out.println(itrim(newStr));
System.out.println(lrtrim(newStr));
}
}

This program is helpful in using regular expression to beautify your string.

Eclipse crash issue

I faced an unusual eclipse crash today.
Error message said:

An error has occurred. See the log file
/home/hendrik/workspace/.metadata/.log.

I browsed through some forums and found this solution:

http://tapestryjava.blogspot.com/2004/10/worst-eclipse-crash-ever.html,

http://dev.eclipse.org/newslists/news.eclipse.newcomer/msg12793.html

The solution was that we needed to remove two file
\.metadata\.plugins\org.eclipse.core.resources\.snap
and
\.metadata\.plugins\org.eclipse.core.resources\.root\.markers.snap

And it worked for me.
cheers
Saurabh

Monday, January 26, 2009

Sensitive Information in a network world

Topic: Sensitive Information in a network world
Speaker: game therory application to internet and privacy and security issue.

Introduction:
Speaker talked about her recent 5-year work assignment of "Privacy obligations and rights in technologies of information assessment".
Project revovled about dealing with senstive information. Reason for choosing sensitive information is because Information has to be handled correctly but one need to understand that every information is not private. For instance, copyrighted information is published but it can be used only under certain norms.
The Project PORTIA invovled prople from various domain. The major research theme addressed fllowing issue:
Massive data set algorithm: Sensitive Data mining and information retrieval is also a concern.
Client side defense
Sensitive data in distributed systems
Policy enforecement tool for Database system
Contextual integrity
Talk invovled detailed discussion on Client side defenses and Sensitive data in DS.

Techincal understanding:
Basic research problem revolved about question that "what information does search engine can collect?"
Usual search engine can access following information about netork and clients.
1. TCP/IP: It can find out OS and server side platform details
2. HTTP headers: Information on the client side like cookies etc.
3. HTML: Server side content
4. Query terms
Speaker talked about software requirement and design used for solving this issue.This software is PWS (Privacy application for web search).
This may not be acceptable to all the users hecnce many approaches were adopted to avoid this data mining by search engines. The problems mainly involved anonymity and avoiding search engine based data mining.

Appraoches and solution:
Some different appraoch:
TrackMeNot This plugin will generate fake traffic(Cover traffic) and confuses search engine by hiding the actual search query.
Tor + Privoxy: TCP/IP layer anonimizer about source of search query: TOR anonimizer while Privoxy: browser level plugin. It targets any kind of web based system but vulnerable to active components and it is difficult to use.

Speaker's team effort:
Make users indistinguishable and handle active component problem. Speculation is that this might reduce the efficiency of google seach engine.

Design overview of software:
It is a 3-tierd architecture. This software can be used as a firefox plugin:
HTTP proxy
HTTP filter(strip out unnecessary information) + HTML filter(remove active compoenent)
Tor Client

Tor network sends the anonymized packet in anonymous way to server and hence hides the client information.
There is broad scope of future work in this domain. Few points are listed here:
Reduce impact of Tor path selection on performance.
develop a formal model t measure privacy.
Semantic anonimozation
Also this might reduce the efficiency of future search results.

PORTIA antiphishing tools includes spoofguard, pwdHash, safeCache, safeHistory and spyBlock. This is present on internet.
Later half of presentation was based aroud distributed computing data mining.
Secure multiparty function evaluation.
Problem statement:
In a distributed environment, how to do a collective computation such that no one get to know about others data and final result is obtained.
Speaker's team adopted survey based approach and applied it to CRA taulbee survey.The intention was to convey salary distribution statistics per tier and rank to the CS community without revealing department specific information.

Sunday, January 25, 2009

Yahoo user interface

Best place to start YUI
http://www.insideria.com/2008/05/writing-your-first-yui-applica.html

Saturday, January 24, 2009

XML

In XML, new line is stored as two character carriage return and line feed.
XML attribute can not contain multiple values.
usually metadata should be stored as attribute however data should be stored as element only.
DTD stands for document type definition.

Modern Operating system assigment##0

1. How does a System call works?

System call is an interface to access privileged resources from user-level process. User-level process calls system call which executes in safe and secure privileged(kernel) mode and avoid any misuse of resources which might have global impact.
System call is set of assembly level instruction or set of function call from c library which access operating system resources and can be executed by kernel only. Whenever a user level process wish to access these resources, it calls the system call function. This system call function internally calls an interrupt 0X80 which transfer execution from user code to kernel code. Each system call is identified by a number which has to be declared in one file and is generally wrapped around _sys_call function.

2. What kind of information is stored in process control block?

A process control block contains process state in a structure. It contains process id, list of open file descriptor associated, memory info, process state, pointers to other data structure etc. It contains all the required information to start the process at later point of time and plays a crucial role in context switch.

3. Which scheduling algorithm is best in terms of avg waiting time? Why is it not used in real life situation?

I guess shortest process next is the best algorithm but this may lead to starvation of long job in real life situation hence it is not used.

4. What is semaphore and what operations can be performed on it?

Semaphore is a variable used for synchronization of various resources among many processes such that race condition can be avoided. Only read and write operation are possible on semaphore and it can be either binary or a counting type of variable. Semaphores are a special kind of locks.

5. Describe one approach for avoiding dead lock while using locks for synchronization between multiple processes?

One approach is to forcefully take back the locks after a given time.
Second approach is to not provide locks to more than certain number of resources.
Third approach is to use deadlock avoidance approaches while giving locks.

6. "LRU page replacement" algorithm?

This is least recently used page replacement algorithm.As the size of memory is fixed and number of pages that can be kept in the memory are limited hence there must be some rule to decide which page should be replaced to make way for incoming page. LRU is replacement of page which is not used for longest period of time.

7. What is thrashing and why it occurs?

Thrashing is a situation when excessive page replacement happens which leads to more time and resources wasted in paging rather than actual system progress.

8. Why most OS's maintain file buffer in main memory? What is the benefit?

Most OS maintain the file buffer in main memory because doing disk IO for each read or write operation will be too costly and resource intensive. This is reduce the system speed and hence increase latency.

9. What is an inode and what kind of information does it contain?

Inode is file system data structure which contains basic file metadata. it contains information on group id, device id, length, file mode and reference count etc. This information can be retrieved by stat command.

10. What is the difference between soft and hard link in a file system?

Hard link refers to same file Inode while soft link refers to different file Inode.

Part II
1. P1 10 unit
2. P2 1 unit
3. P3 2 unit
4. P4 1 unit
5. P5 5 unit

Assuming all process arrive at time O.
With FCFS
Process name turnaround time waiting time
P1 10 0
P2 11 10
P3 13 11
P4 14 13
P5 18 14

With RoundRobin
Process name turnaround time waiting time
P1 18 8
P2 2 1
P3 5 7
P4 4 3
P5 14 9

Part III
Sleeping barber problem:
See what are the resources.
Customer is resource for barber.
Barber is resource for customer.
free seats is resource for customer.

Barber:
While(true){
// occupy a customer
P(customer)
P(accessseats)
numberofaccessseat++;
V(barber)
V(accessseat)
}

Customer:
P(access seat)
if (numberofaccessseat > 0){


}
Try doing this at your own.

Part IV

Current disk head position: 49
moving towards track: 100
pending I/O request: 42 78 3 51 99
SSTF:
51 42 78 99 3
total track seeked: |49 - 51| + |51 - 42| + |42 - 78| + |78 - 99| + |99 - 3| = 164 units

SCAN:
51 78 99 3 42
Total track seeked: |49 - 51| + |51 - 78| + |78 - 99| + |99 -100| + |100| + |0 - 3| + |3 - 42| = 182 units

Using SSTF more frequently used data should be stored in the middle so that distance from any corner or position on the disk will be mediocre and pending track request will be served faster.

Friday, January 23, 2009

To Do list

Read XML DOM PHP AJAX XSLT DTD SCHEMA tutorial on w3school as soon as possible.
This will help a lot in understanding and solving basic concepts....

Now: One blog on management class
Tomorrow: 1 hours MOS assignment
2 hours YUI project

6 hours YUI toolkit examples

Sunday: Till afternoon YUI
Evening Proxy project (start formulating the problems and all)

Monday: ITM assignment and Proxy result gathering

Ajax

Javascript + XML
no new programming language but a new way of using existing standards.
better faster and more interactive web applications.

With Ajax, javascript can directly contact to server using XMLHttpRequest without reloading the page.

will complete it some other time...
for now just read the w3school material...

Wednesday, January 21, 2009

Information technology management

Attending this lecture revived my memories of Internship days at IBM. The brainstorming interactive discussion, energetic classroom full of people from different cult, background and each one special in his own way made me feel deja vu. It was a nice change from (sometimes) boring, deeply technical core computer science stuff where one get burdened and lost by some glitch which drive you crazy and somewhat bald (as in my case).

Before this class, I never thought how special i am? I was always afraid of such questions because it sounds like self-praising and i usually get stumpped whenever someone ask me such question. But i am happy that i found not one but many reasons of feeling special. I am yearning to get involved and experience the intersection or to be precise synergy of tehnology and business in coming weeks but one point which i am still thinking about is what might be the next innovation that will change the face of this world after present deployment cycle. Also why the engineering automobile age(1908 - 1971) took so long to get mature. One reason might be that it faced two world war in that period which spanned almost 10-15 years.

Looking at the presentation again, i found one interesting point. In sequence to last observation:
1771 - 1829 == 58 years (this period saw the well known great danish war during 1801-1814 when sweden, netherland, russia and denmark launched seized all the ships of british army and trade and mind you britain was the main force behind development of railways.) so effectively this comes to be 44 years.
1829 - 1873 == 44 years
1875 - 1920 == 45 years
1908 - 1974 = 66 years (but this period saw two biggest war, world war I and world war II so just cut 20 years) so effectively 46 years.
1971 + 45 years(approx) == 2016 {So according to above theory, this is going to be the year of next phase of innovation and development}

lol, this analysis looks funny to me. But now that i have written so much crap so lets see how others comment on it.

See you all tomorrow. good job Cough
Implement these
http://www.pages.org/javascript/index.html

Also do this 100 example:
http://www.w3schools.com/JS/js_examples_3.asp

JavaScript

real power of javascript on the client side is that scipts have access to hierarchy of objects that are based on content of web page.
for example client side java sciprt can access and manipulate each of the images that appear in a document and can communicate and interact with java applet embedded within an HTML document.

basic applications and features:
controlling document appearance and content:
like displaying date and time on web page
Setting the document's properties like bgcolor font etc.
Conditional HTML generation

Controlling browser
Opening windows with specific size.
Opening new tab.
Programmatically write the HTML tags that create any desired frame layout.
History objects allows to move back and forth within user's browsing history.
Displaying messages in status line of browser window.

Interacting with HTML forms
To calculate shipping charges and sales tax on order placed.
validating form data before sending it to server

User interaction and event handling
displaying messages when mouse hover over a hyperlink
pop up a confirmation dialog box when user submits button

Read and writing client state with cookies
Uses cookie to find if user has previously visited the site, registered etc.
Javascript can dynamically generate content using value of cookies.

More features:
Allows image rollover and animation effects
Time stamping on web pages.
Resizing window

Misuse of java script:
malicious web page can use javascript to send data to some third party software/server.

Java script expression can be evaluated using javascript URL pseudoprotocol in browser.
syntax: javascript:
example: javascript:d = new Date(); typeof d;

best way to debug is look at error console of browser or insert alert statement at appropriate places.
Document.write can also be used but it has limitation as it does not work within an event handler.


JavaScript written using 16 bit unicode character set.
each character represented as 2 bytes instead of most commonly used 1 byte standard.
case sensitive to much extent
semicolon can be omitted if each statement is on a separate line.
try to put each statement completely on separate line.

Converting number base or type
toSring(base)===> this will convert variable to String in base notation.
example: binary conversion:
(x).toString(2);

another way to define function:
var square = new Function("x", "return x*x;");
here arguments list and body of arguments is passed as strings to the function.

Objects in javascript have the ability to serve as associative arrays.
example:
image.width
image.height
image["width"]
image["height"]

creating arrays:
var a = new array(1.2, "javascript", true, { x:1, y:3 });
var a new array(10);

Date object:
var now = new Date(); // holds current day and time
now.getDay();

Javascript also provides error object which can be used for throwing and catching errors.
Javascript is untyped language.

if you assign an undeclared variable to some vale then java script will implicitly initialise that variable for you.
no block scope ... variable declared throughout function body.

All divide operation results in floating point numbers.
equality operator == and ===
in case of string comparison operator can be used but all capital letters will be less than lowercase letter.
example: Zoo will be less than aarjksf

in operator for property check
example:
var has_x_coord = "x" in point; //Evaluates to true

similarly instanceof operator...
example:
var d = new Date();
d instanceof Date; // evaluates to true; d was created with Date()

String concatenation and comparison is tricky.
typeof operator is useful in finding the type of object whether number, string or boolean.

Delete operator of java script is not like delete of C++. C++'s delete operator is used to deallocate memory but javascript not require such functioning because of garbage collection.

javascript:void(0) is useful when you dont want to reload your page.

(.) operator example:
document.lastModified
navigator.appName

switch case statement use:

function convert(x) {
switch (typeof x) {
case 'number':
return x.toString(16);
case 'string':
return '"' + x + '"';
case 'boolean':
return x.toString().toUpperCase();
default:
return x.toString()
}
}

try catch finally is more or less similar to what is there in C++ and java.
throw id used to throw exception.
example:
if (x < 0) throw new Error("X must not be negative");
Exceptions propagate through the lexical structure of javaScript method.
If no exception handler is ever found, the exception is treated as an error and is reported to the user.

try {

}
catch (e){
//
}
finally {

}

there is something called scope chain as well. with operator is used to modify this scope chain. This helps in reducing typing.

frames[1].document.forms[0].address.value
to use directly

with(frames[1].document.forms[0]) {
name.value = "";
address.value = "";
email.value = "";
}

or
var form = frames[1].document.forms[0];
form.name.value = "";
form.address.value = "";
form.email.value = "";

for/in combination is also frequently used to iterate over some array or objects.
exmaple:

for(var prop n my_object) {
document.write("name:" + prop + "; value:" + my_object[prop], "
");
}

Function statement is not the only way to define a function. A constructor can also be used to define a function.
Example:
var f = new Function("x", "y", "return x*y");

array can be sorted using array.sort function call.

function can be defined as data, or literals or using constructors.
example:
var operators = new object();
operators["add"] = function(x,y) { return x+y; };
operators["subtract"] = function(x,y) { return x-y; };

function operaot2(op_name, operand1, operand2){
if(operators[op _name] == null) return "unknown operator";
else return operators[op_name](operand1, operand2);
}

Arguments object is highly useful in passing unlimited number of argument to a function. it also provide a callee property. Using this one can find out about callee function as well.

callee property allows unnamed functions to be invoked and executed.
For example:

function(x){
if (x <= 1 ) return 1;
return x*arguments.callee(x-1);
}

expected number of argument can be obtained using length property of function name however actual count of argument can be obtained using Arguments.length argument.


apart from this one can define function own property.
Use: suppose a function wants unique value to be returned on every invocation then it is better to define property specific to function and store the previously returned value in that rather than defining global variable.

uniqueInteger.counter = 0;
function uniqueInteger(){
return uniqueInteger.counter++;
}

apply() and call() function are also somewhat useful.

Objects can be created using new keyword.
Example: creating and setting properties:

var book = new Object();
book.title = "hello motot";
book.chapetr1 = new Object();
book.chapetr1.title = "jeheheh";
book.chapter1.pages = 19;

Enumerating properties: useful while debugging

function DisplayPropertyNames(obj) {
var names = "";
for(var name in obj) names+= name + "\n";
alert(names);
}

function also define prototype properties to save resources in javascript.

String.prototype.endsWith = function(c) {
return (c == this.charAt(this.length-1))
}

var message = "Hello World";
message.endsWith('h');
message.endsWith('d');

prototype provides a sense of inheritence in javscript.

Array:
slice
splice
concat
sort
length
push/pop
shift/unshift
join
reverse

Tuesday, January 20, 2009

Style sheet

A CSS style sheet consists of two parts
1 selector which can be a HTML tag such as p1 or h1,
and declaration which defines the property the value of the selector.

h1 {color: blue}
p {font-family: Arial,; color: black}

way of using CSS
1. External style sheet
2. Embedded style sheet
3. Inline style sheet

For example in embedded style sheet, style sheet code is embedded in html code using #style# tag.
#style type="text/css"#
#!--
h1 {color: blue}
p {font-family: Arial,; color: black}
--#
#/style#

External style sheet:
Keeps the style rules in a separate file, apart from the HTML web document. advantage of using an external style sheet is that you can apply same style rules to more than one document in your web site.
this helps in creating web pages with consistent appearance and modification of style sheet will be consistently reflected on all the related web pages.
style sheet => an ASCII text document with a special extension (.css).
use of #link# tag to connect to web page(html file).

#head#
#title#xxxxx#/title#
#link rel="stylesheet" href="mystyle.css"#
#/head#

Friday, January 16, 2009

C++ programming practice

http://www.codersource.net/codersource_cppprogramming.html

C++ tutorials ... good point to start programming...

Also C++ programming practice exercises...
http://people.sc.fsu.edu/~burkardt/cpp_src/cpp_src.html

Wednesday, January 14, 2009

In Java
field and member function

In C++
Member and member function

in Java function has to be included inside a class but in C++ free functions are possible in a program.
One such free function in c++ is main.
In Program you need to use namespace as well as include iostream.
To print output "cout" is used.
cout [[ x [[ y [[ z [[ endl;
This function is left-associative so value is evaluated from left to right.

x=y=z=0;
assignment operator is right associative so first z is set to 0 followed by x and y.

To call a free function from any other function or class in the program, no class declaration is required. Just calling by name of the function will suffice but a prototypical declaration of function will be required (as similar to c). Either the function implementation should be placed before the function call or a forward declaration should be there.

if program involves more than one file then g++ file1.c file2.c can be used to generate a final single executable.
One more option is to create a separate object files using -c option then link them at later. By this, if later any file changes then we don't need to recompile all the files.

g++ -c hello.c ====> hello.o
g++ -c hello1.c ===> hello1.o

g++ hello.o hello1.o

C++ types is combination of both C and Java types:
1. primitive types
2. arrays
3. enum
4. structure
5. union
6. pointer
7. classes
new type can be defined using typedef.

C++ supports c type interpretation of integer values where they can be considered as boolean values for conditional statement. This might lead to assignment related error like
if (x = 0) // we wanted to compare x to 0 but by mistake we made it like x= 0 which is syntactically correct but hard to debug.
To resolve this one should write constant first instead of variable.
if (x == 0) should be practiced to be written like this if (0 == x).


C++ arrays lacks many important feature which are useful in Java.
For example:
no length operation.
no dynamic resizing of array.
No run time check on out-of-bound index.
Not possible to assign one array to another. No array copy possible.
However one can use vector class in STL or define there own such class which can provide all these functionality.

Array declaration in C++
int arr[10]; // array of 10 int variable;

In java brackets can precede the variable name but in C++ it is not so.
int[10] arr; // java correct but in C++ incorrect.
In java array declaration includes size so memory is allocated at same moment.

Think of a real life programming situation where union keyword is efficient to use?

In C++ null is upper-case but in java it is lower case value;
In C++ if structure declaration is like:
struct x {
int x1;
int x2;
};
x x3, x4; ======> valid in C++ but in C this should be like struct x x3, x4;

There is no garbage collection mechanism provided in C++ so we need to deallocate heap memory by your own. use Delete keyword for this purpose;

A subtle case to consider:

int *p, *q;
p = new int;
q = p;
delete q;
*p = 5; here p is a dangling pointer.

also 2nd case can be:
int *p = new int;
*p = null
This will leave memory leak in the program.
To debug pointer use purify.

To allocate space to pointer using dynamic allocation, use like this:
int *p = new int[10]; // array of 10 pointers.
delete[] p;

code snippet to read input file and output file:

#include

int main(){
int x;
ifstream infile;
infile.open("input.dat");
if (infile.fail()){
cerr << "error in opening file" << endl;
exit(1);
}
while(infile >> x)
some operations

// to read character by character
while(infile.get(c))

}

Important point to note and remember:
Input and outputstream are always passed by reference.

In Java parameter are passed by values only but in C++ they can be passed by
1. value
2. reference
3. Const- reference
for example:

void func(int a, int &b, const int &c);
here a is pass by value
b is pass by reference
c is cons-reference

A wonderful concept is this:
IN the following example, even though pointer is an address to a memory location. When such pointer is passed by value, value stored at the address stored by pointer can change but pointer it self does not change.

void f(int *q){
*q = 5;
q = null;
}

main() {
int *p;
int x = 2;

*p = &x
f(p);
// value of x = 5 but p != null
}

Parameter should be passed by reference if any function has to return multiple values.
Const-reference is used when you don't want function to modify parameter value but you want to avoid making copy of parameter becuase parameter is large or resource overhead might be high.

Const-reference may lead to compile-time error so all the member functions should be const as well. Arrays are always passed by reference. To pass an array by value one should user Vector.
Always put a practice of keeping general code in c files and declaration in header files. Include
header files in this way:
#include "prog1.h"

class implementation should be divided in 2 files.
header file (.h) should include the definition and declaration. Generally variables and methods are declared public and private according to their usage.
.c file should include all the implementation of API's and member function specified in corresponding header file.
Unlike java class definition should end in semicolon.
Constructor should have same name as class.

class IntList {
public:
IntList();
void AddToEnd(int k);
void print(ostream &out) const;

private:
int x1;
int x2;
int x3;
static const int SIZE = 10; // initial size of the array
int *Items; // Items will point to the dynamically allocated array
int numItems; // number of items currently in the list
int arraySize; // the current size of the array

};

here print is declared as const bacause in case if the member function are not changing any variable then function should be declared as const.
if a situation is like this
void f(const IntList &L) {
L.Print(cout);
}
here if Print is not declared to be const then compiler will throw some compile time error.
C file will look like this:

#include "prog.h"

IntList::IntList():Items(new int[SIZE]), numItems(0), arraySize(SIZE) {
}

void IntList::AddToEnd(int k) {
...
}

void IntList::Print(ostream &output) const {
...
}

Inthe above code, one must not forget to include the header file.
standard library header files should be included in angle brackets while quotes should be used to include your own file.
The way constructor code is written:
1. Member initialization list
2. Initialization inside constructor body.

Some confusion on use of Member initialization list.

String in C++
include [string] at the top of program
strings can be declared with or without initial value
String s1 or String s1("hello") or String s1 = "hello"

s1.size()
s1 == s2 [comparison]
+ for concatenating.....
size() for calculating size;

string can be indexed as well.

Tuesday, January 13, 2009

http://docstore.mik.ua/orelly/java-ent/index.htm

good book for distributed computing in Java... do it some time..

Monday, January 12, 2009

http://pages.cs.wisc.edu/~hasti/cs368/CppTutorial/

Link to solve your problems.... this will help in learning basic C++ stuff.
const char *a;======> pointer to a const char type. It means value at address stored in pointer can not be changed.
char* const a;
char const *a;

In this const is applied to closest next symbol.
For example in "const char *a", const applies to char * while in char * const a , const applies to a.

array of pointer vs pointer to aray

int *p[10] ==> array of 10 int pointer where each one can be accessed p[1], p[2] etc...
int (*p)[10] ==> pointer to array of 10 integer values.

#Define vs Typedef

#defines are used for textual replacement while typedef can be used for generating new kind of declaration types.

for example:

typedef int ar[10];

ar hello;
/*
hello is an array of 10 int element.
*/

sizeof vs strlen

char str[]="abcd";
char *s="abcd";

strlen(s) = 4;
sizeof(s) = 2;
sizeof(str) = 5; =======> this include "\0" by default at end.
strlen("abcde\0") = 5 strlen() counts till it encounter a null value.

Using fgets to read a file in C

while(fgets(buffer, length, file pointer)!=null)
Do Something

Noticeable thing here is that one should use null for identifying the end of file instead of EOF as fgets returns null.

Saturday, January 10, 2009

something good.... read it sometime
http://www.javascripttoolbox.com/bestpractices/

Thursday, January 8, 2009

Java script:

Java script is client-side scripting language that allows you to write scripts, or small non-compiled programs, that are run by browser.

What can be achieved using java script?
1. Move objects around the web page.
2. Show or hide elements.
3. Create lists that expand or contract when you select an item.
4. Dynamically alter the color and size of web content.
5. Provide the drag-drop functionality similar to that used by modern graphican operating system.

Dynamic HTML is combination o three key technologies:
1. HTML
2. Style sheets
3. Scripting

Scripting can be divided into two parts:
Client side scripting: VBScript, JavaScript, AJAX
Server side scripting: JSP, PHP, ASP, Cgi-bin

To make the whole model distributed, some other standards are used. Some of them are complementary and others are alternatives.
1. Java RMI
2. CORBA
3. SOAP
4. XML-RMC
5. WSDL/WSDD
6. UDDI

To learn about all this basic knowledge of web services, Java and XML are prerequisites.

Now we'll discuss JavaScript in somewhat more details.
It can be integrated with HTML code in following ways.
1. Include inline scripts in response to intrinsic events.
2. Put scripts in the document head or body.
3. Link to external scripts.

To let browser know about scripting language, we need to explicitly mention this in meta tag.


This ensures that the browser knows that we are using JavaScript unless told otherwise.

some random points:
For navigator DOM model
All object under DOM is stored in an array..
For example all image objects are stored in the document.images property.

In case of explorer DOM model
All objects are contained in document.all object.
Also some syntax are changed with respect to Netscape but concept is same.

Handling Events:
coding for event handling is difficult for navigator but straightforward in case of Explorer as explorer does a bubble up approach such that event first is detected by element that generated that like div or image element and moves up the document object chain until handled or cancelled.


Wednesday, January 7, 2009

Knowledge is meant for solving problem of life
not to stack up in libraries....

Tuesday, January 6, 2009

apache virtual hosting...

http://www.debuntu.org/2006/02/22/7-virtual-hosting-using-apache-2

Just refer this link whenever face problem with static site hosting...

Also look into this link.....
http://articles.slicehost.com/2008/4/25/ubuntu-hardy-installing-apache-and-php5

I was facing problem of error in processing of apache and PHP ...
encountered this link which solved my problem....
http://ubuntuforums.org/archive/index.php/t-478045.html

Saturday, January 3, 2009

Operatins system repository:: learn this

http://www.personal.kent.edu/~rmuhamma/OpSystems/os.html

When computer is turned on

The first programs that runs is usually a set of instructions written in Read only Memory (ROM). This code examines the system hardware to make sure if everything is functioning properly.
POST checks for BIOS, CPU and Memory and store results at special memory location.
Once POST is done, code written in ROM starts activating hard drive.

AS soon as Hard drive activate, it reads the first piece of OS places in master bootStrap loader (sector 0 track 0 or 1 something like that..)...

Bootstrap loader has only single function of loading the operating system into memory and allow it to begin operation.
In the most basic form, bootstrap loader sets up driver interfaces with hardware and sets up division of memory that holds operating system and applications.

Then operating system manages following six task
Process management
Memory management
User interface
Storage management
Device management
Application Interface


Read these articles whenever you get time...
http://computer.howstuffworks.com/operating-system12.htm
Threads have its own:
Program counter
register set
stack space

Shares:
Code section
Data section
OS resources like open signals and files

But cost of all this is no protection between threads...

Thursday, January 1, 2009

http://nces.ed.gov/nceskids/createAgraph/default.aspx?ID=820cf1c6c33242e791707d7e9f73a278

graphs .. kewl man