Sunday, March 24, 2013

C++ string tokenizer

The advanced tokenizer:

void Tokenize(const string& str,
                      vector& tokens,
                      const string& delimiters = " ")
{
    // Skip delimiters at beginning.
    string::size_type lastPos = str.find_first_not_of(delimiters, 0);
    // Find first "non-delimiter".
    string::size_type pos     = str.find_first_of(delimiters, lastPos);

    while (string::npos != pos || string::npos != lastPos)
    {
        // Found a token, add it to the vector.
        tokens.push_back(str.substr(lastPos, pos - lastPos));
        // Skip delimiters.  Note the "not_of"
        lastPos = str.find_first_not_of(delimiters, pos);
        // Find next "non-delimiter"
        pos = str.find_first_of(delimiters, lastPos);
    }
}

Source: http://oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html

C++ string to double and vice versa

The C++ 11 way is to use std::stod and std::to_string. Both work in Visual Studio 11.


The STL offers the desired functionality:
std::string  s  = "0.6"
std::wstring ws = "0.7"
double d  = std::stod(s);
double dw = std::stod(ws);


http://stackoverflow.com/questions/1012571/stdstring-to-float-or-double

Monday, March 4, 2013

Latex packages: 9 essential

http://www.howtotex.com/packages/9-essential-latex-packages-everyone-should-use/

Monday, July 23, 2012

Wednesday, February 8, 2012

Perl

Download perl from ActivePerl website and install it. It will automatically set the path and environment variable.

Perl is useful as it process one line from the file at a time. Each line is stored in $_ variable.

Saturday, February 4, 2012

Combinatorial Optimization

Combinatorial Optimization
http://en.wikipedia.org/wiki/Combinatorial_optimization

My research

Research Interests:
·         Combinatorial Machine Learning,
·         Decision tree, test & rules,
·         Many Valued Decisions,
·         Artificial Intelligence,
·         Artificial Neural Network (ANN)

Books that I read

1. Machine Learning
2. Data Mining
3. Combinatorial Machine Learning
4. Concepts of Programming Languages
5. Algorithms
6. Artificial Intelligence
7. Computer Architecture
8. Computer Networks
9. Operating Systems

Tuesday, May 5, 2009

Search Engine

How search engine works:

Animated learning: http://www.learnthenet.com/english/animate/search.html
How stuff works: http://computer.howstuffworks.com/search-engine.htm
Search engine watch: http://searchenginewatch.com/2168031

Search Engine Ranking

How Search Engines Rank Web Pages


How do crawler-based search engines go about determining relevancy, when confronted with hundreds of millions of web pages to sort through? They follow a set of rules, known as an algorithm. Exactly how a particular search engine's algorithm works is a closely-kept trade secret.

http://searchenginewatch.com/2167961

Computer Science papers

Papers in Computer Science is a blog for abstracts and brief summaries and discussions about published computer science articles, updated 3 times a week.


http://papersincomputerscience.org/category/artificial-intelligence/

Friday, January 30, 2009

How to memorize words

Use Mnemonic.

Mnemonics - The ultiamte word memorization tricks


Before sitting for the GRE, I sorted out some techniques to remeber a word, called 'MNEMONICS'. Everyone has their own mnemonics. You have to sort out yours.

These are my mnemonics:

1. Never learn a new word by rote learning, means Memorization by repetition. Rather try to visualize a word in your mind. as example, the word 'copse' means 'A dense growth of bushes', now when u think the word copse, close your eyes and visualize it like the bushes u c in the gardens. And also think that, the "copse" also SOUNDS like bushes. Got it?

2. Always interrelate your ideas and find links to remember. Suppose the word "SPLICE" means "to join or tie". Now the word "SLICE" means "Cut into pieces". See the relation between the words "slice" and "splice". They sound very similar but means opposite. Another similar example is " EXTINCT" an " EXTANT". Try to find linkage between words in your own way. Each person has their different and unique way of thinking. Find and use yours. You can relate with your mother tongue language words too.

3. The best way to memorize a word is by learning the word’s ETYMOLOGY (The study of the sources and development of words). In this way you can learn several words at a time.

Like ‘Philanthropist’ and ‘Philanderer’ have the common root ‘Phil-‘(means ‘Love for something’).
While, the meanings are ‘Philanthropist =Someone who makes charitable donations intended to increase human well-being'
'Philanderer= A man who likes many women and has short sexual relationships with them'
Again, 'Philanthropist' has another root 'Anthropo-' (means ‘human/mankind’)
Some more words from this root are : Anthropology, Anthropomorphic, Anthropoid.

You can learn more words by this means. Well, you can go to http://www.mnemonicdictionary.com or http://www.thefreedictionary.com for word origins or etymology.

4. Always learn at least two words at a a time. When you larn a new word, learn all its synonyms, at least one. You might not remember them but all at once, but eventually it will help.
For now, Philanthropist= altruist, Philanderer= womanizer
In this way if you memorize 3000 words, it becomes 6000. :D

5. Learn the words by listening to the audio.

6. Also try to larn words through pictures. Larning proper nouns by this system is pretty effective. The link:
http://www.ziddu.com/download/1866674/LarnwordsthroughPictures.zip.html

7. Use WORD WEB dictionary. Go to www.download.com and search it. This software rocks.

8. Finally, Practice is the ultimate goal of success in GRE. Unless you practice nothing's gonna help you. It doesn't really matter how strong is your vocabulary part. Because, practice shows us where we are committing mistakes and what are the notches that needs to be filled. I am repeating the dialog verbatim "There is no other way than practice and revise".

Hope you will ‘eat words, drink words, sleep words and dream words’ till you sit for the exam.

Best of luck.

Thursday, January 29, 2009

Difference between HTTP and HTTPs

Http is hyper text transfer protocol which is responsible for transmitting and receiving information across the Internet where as https is secure http, which is used exchanging confidential information with a server, which needs to be secured in order to prevent unauthorized access.

HTTP is Hyper Text Transport Protocol and is transmitted over the wire via PORT 80(TCP). You normally use HTTP when you are browsing the web, its not secure, and so someone can eavesdrop on the conversation between your computer and the web server. HTTP can support the client asking for a particular file to be sent only if it has been updated after a certain date and time. This would be used if the client has already retrieved a copy of a file by that name from that server, but wants to check to see if it has been updated since then. The server responds either with the updated file, with a message to say the file has not been changed, or with a message that the file no longer exists.

HTTPS (Hypertext Transfer Protocol over Secure Socket Layer or HTTP over SSL) is a Web protocol developed by Netscape and built into its browser that encrypts and decrypts user page requests as well as the pages that are returned by the Web server. HTTPS is really just the use of Netscapes Secure Socket Layer (SSL) as a sub layer under its regular HTTP application layering. (HTTPS uses port 443 instead of HTTP port 80 in its interactions with the lower layer, TCP/IP.) SSL uses a 40-bit key size for the RC4 stream encryption algorithm, new-age browsers use 128-bit key size which is more secure than the former, it is considered an adequate degree of encryption for commercial exchange. HTTPS is normally used in login pages, shopping/commercial sites.

Tuesday, December 2, 2008

xml String parsing in C#

I have faced problems for parsing xml string in C#. I have solved in the following ways:

Instead of give the actual string to the XmlTextReader
XmlTextReader  reader = new XmlTextReader(result);

You should pass with the help of StringReader Object.
XmlTextReader  reader = new XmlTextReader(new System.IO.StringReader(result));

Wednesday, November 5, 2008

All about scope

Request
Page
Session
Application

If you have a request scope, it will only run for the request that is made on that same moment.
If you have a page scope, the parameters and values will run for that page the whole time until the server is restarted.
If you have a session scope, all the values will be kept for until the clients session is destroyed.
And least the application scope, if you apply the application scope, the values will be kept for the entire application, until the server is restarted.

Tuesday, August 26, 2008

Chain of Responsibility Pattern

The classic Chain of Responsibility(CoR) pattern defined by Gang of Four(GoF) in Design Patterns:

"Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it."


Following Figure illustrates the class diagram.

Figure 1. CoR class diagram

A typical object structure might look like following Figure .

Figure 2. CoR object structure

From the above illustrations, we can summarize that:

  • Multiple handlers may be able to handle a request
  • Only one handler actually handles the request
  • The requester knows only a reference to one handler
  • The requester doesn't know how many handlers are able to handle its request
  • The requester doesn't know which handler handled its request
  • The requester doesn't have any control over the handlers
  • The handlers could be specified dynamically
  • Changing the handlers list will not affect the requester's code
Uses of CoR:
1. Microsoft Windows global hook framework
2. Java servlet filter framework


Details are explained by Michael Xinsheng Huang, JavaWorld.com, 08/16/04

Monday, August 18, 2008

Difference between Association, Aggregation and composition

Difference between Association, Aggregation and composition:

Association:

1. A relationship between 2 objects that is not whole-part i.e.
A contains a reference of B and uses B through the reference
2. Generally implemented as a public property of A,
where B may be set in to A by an external party (say Spring)

Dependency:

1. A week association, where A doesnt contain a reference of B but uses B
2. Generally implemented as method parameter in A

Composition:

1. A strong whole-part relationship, i.e. B (child) has no existence
outside A (parent)
2. A creates and contains B but B can not contain A
2. B must not be visible outside of A since if A dies, B must die

Aggregation:

1. A week whole-part relationship, i.e. B (child) may exist exist
outside A (parent)
2. A contains B but B can not contain A
3. B must be visible outside of A since B may still exist when A dies
4. Generally 1-many relationship

With Real Life Examples:

Accosiation:
1. Create a folder called "Links"
2. create a shortcut inside this folder and link it to www.yahoo.com
3. create another shortcut instide this folder and link it to www.google.com
4. Ask your friend to do the same on another machine using same links
(www.yahoo.com and www.google.com)
5. Delete the "Links" folder, and open your browser to check if
www.yahoo.com and www.google.com still exist or not ;)

Briefly, Association is a relationship where all the objects have different lifecycles.
There is no owner.



Composition:
1. Open a new Document name it as test.txt
2. Write this sentence in iside this document "This is a composition".
3. Save the document.
4. Now, delete this document.

This is what is called composition, you can't move the sentence "This is a
composition" from the document because its lifecycle is linked to the
parent (the document)

Aggregation:
1. Create a file called file.txt
2. make a simple application to open the file.txt (rw), but don't program
it close the connection.
3. Run an instance of this application (it should work ok and can open the file for rw)
4. Keep the first instance, and run another instance of this application
(In theory it should complain that it can't open the file in rw mode
because it is already used by other application).
5. Close the 2 instances (make sure you close the connection).

From the above application, we knew that the Application and the file has a
separate lifecycles, however this file can be opened only by one
application simuletanously (there is only one parent at the same time,
however, this parent can move the child to another parent or can make
it orphan).


View Details: http://www.artima.com/forums/flat.jsp?forum=17&thread=24715


Wednesday, April 30, 2008

Use globally defined constants

You can use globally defined constants by defining them inside a class and referencing themwithout instantiation.

public class CONSTANT {

public static final integer SUCCESS = 1;
public static final integer FAILURE = -1;
public static final integer NOTFOUND = 0;

}

Since the members of the class are defined as "static", there is no need to instantiate the class. To use a constant, simply use CONSTANT.[constant name]

if (myMethod()==CONSTANT.SUCCESS) {
...;
}
else {
...;
}

For details: Java Tips

Set the memory available to the JVM

By default, the JVM will use up to 16Mb of RAM. If your program allocates a lot of memory, you may need to increase this value to give more room to the garbage collector.

When starting the JVM, two parameters can be adjusted to suit your memory needs:

-mx n Sets the maximum size of the memory allocation pool where n is in bytes, appending "m" to n will specified the number in megabytes, for example to set the maximum at 20Mb:

   java -mx 20m myApp

. -ms n Sets the startup size of the memory allocation pool, where n is in bytes, appending "m" to n will specified the number in megabytes. The default is 1Mb.

With JDK1.2, that syntax have changed, no space between ms/mx and the value:

   java -mx20m myApp

For Details: Java Tips

Pass an integer by reference

Sometimes you may need to pass an integer to be able to change its value. "integer" are always passed by value in Java. An easy way to pass by reference is to use a single element array.

int[] a = new int[1];
a[0] = 1;
add2(a);
// a[0] now = 3
...

void add2(int[] a) {
a[0] = a[0] + 2;
}


For details: Java Tips