Sunday, February 17, 2008

Compare two word documents using MS Word

Compare two word documents using MS Word
1. Open a document.
2. On the Tools menu, click Compare and Merge Documents.
3. Select the document that you want to compare to the copy that is currently open.
4. Click the arrow next to Merge, and then do one of the following:
* To display the results of the comparison in the selected document, click Merge.
* To display the results in the document that is currently open, click Merge into current document. * To display the results in a new document, click Merge into new document.

The differences will be displayed as comments in the new document.





For example here the Last updated date has been changed from 13-04-07 to
11-05-07.

Speed up the start of Acrobat Reader

Opening PDF files are taking time, then

Method 1:
Every time you run Adobe Acrobat, up to 20 plugins are loaded
unnecessarily - most users do not need even a fraction of them!
To disable unneeded plugins and make them optional instead, follow these
instructions:
1. Browse to the plugins folder: C:\Program Files\Adobe\Acrobat
7.0\Reader\plug_ins
2. Create a new folder named Optional
3. Move all files from the plug_ins folder to Optional, except
EWH32.api, print*.api, and Search*.api

Method 2:
Download the software Adobe Reader SpeedUp software from
http://www.tnk-bootblock.co.uk/software/, which does the same thing
specified in Method 1, but in a nice GUI friendly option.

Method 3:
Install a light weight PDF reader (other than Acrobat). The best free
PDF reader is Foxit Reader. No need to install, just copy the executable
and run from your system. This is very light and extremely fast.

Foxit reader is available at
http://us01.foxitsoftware.com/foxitreader/foxitreader.zip (just 1.8 MB
size).


Threading libraries in C++

Here is the list of Threading libraries in C++

Pthread (POSIX threads)
http://en.wikipedia.org/wiki/POSIX_Threads
pthread won't work fine on windows, because windows won't support POSIX standards - but there are some implementations of pthreads api on windows also!
Note: pthread is a c library not a c++ library, hence you can use it in c applications also.

Boost::thread - supports many compilers and architectures include Linux
and Windows.

Check these links: http://www.ddj.com/cpp/184401518,
http://www.boost.org/doc/html/thread.html

The problem with Boost libraries is that it requires good knowledge on STL, and learning is not very easy.

Glib::thread - Glib supports multi-threading, it can run on Windows and Linux but I don't think it supports VC++ compiler.

Check these:
http://www.gtkmm.org/docs/glibmm-2.4/docs/reference/html/classGlib_1_1Th
read.html, http://inti.sourceforge.net/tutorial/libinti/threads.html

Qt: Qt library (not the Quick Time player from Apple) also have threading support (both 3.x and 4.x versions). Qt 4.x is released under GPL for Windows also.

http://doc.trolltech.com/3.3/threads.html

Note: Nokia recently acquired TrollTech (the company behind Qt)

Intel threading library:
One more library from Intel (open source library, GPL2 with the runtime
exception). But only works on x86 or x86_64 (Intel or AMD; 32 or 64 bit)
architectures.
http://www.intel.com/software/products/tbb/
http://threadingbuildingblocks.org

wxWidgets also have a threading library.

And it is easy to write own threading library too!

Win32 is also having a thread api - but who is using win32 or MFC these days?

However I bet on either PThreads or Boost::Threads.

Anyhow in next version <http://en.wikipedia.org/wiki/C%2B%2B0x> of C++, standard library will support threading - API very similar to boost::thread library!

Firefox tips

To check Installed plugins

type: about:plugins in browser,

This will show up list of plugins that are installed like Flash player
plugin, Java plugin, Shockwave plugin.










Customize the display and location of the close tab button in the tab bar

You can customize the display and location of the close tab button in
the tab bar by using about:config to edit the preference
browser.tabs.closeButtons.

Values:
0 Display a close button on the active tab only
1 (Default) Display close buttons on all tabs
2 Don't display any close buttons
3 Display a single close button at the end of the tab bar (Firefox 1.xbehavior)

Speed up Firefox

1.Type "about:config" into the address bar and hit return. Scroll down and
look for the following entries:

network.http.pipelining network.http.proxy.pipelining
network.http.pipelining.maxrequests

Normally the browser will make one request to a web page at a time. When you
enable pipelining it will make several at once, which really speeds up page
loading.

2. Alter the entries as follows:

Set "network.http.pipelining" to "true"

Set "network.http.proxy.pipelining" to "true"

Set "network.http.pipelining.maxrequests" to some number like 30. This means
it will make 30 requests at once.

3. Lastly right-click anywhere and select New-> Integer. Name it "
nglayout.initialpaint.delay" and set its value to "0". This value is the
amount of time the browser waits before it acts on information it receives.

If you're using a broadband connection you'll load pages MUCH faster now!

Working with Macros in C

More about C Macros

I do agree that everybody who worked in C, knows about pre-processor and macros.

But I thought of sharing some tips about preprocessor and the gcc options to control the preprocessor output.

Here is a simple usage of macros

#define sum(a, b) a+b

int main () {
int k = sum(10,20)*10;
return k;
}

Yes, the output is 210 (not 300, the famous interview question for freshers).

Let us check the output of preprocessor and see that the result is 210...

gcc takes an argument -E that output the preprocessor output.

Compile the above program using gcc -E test.c -o test.txt
Open the test.txt file and the output is

int main () {
int k = 10 +20*10;
return k;
}

Now you see how the #define is replaced with the value... quite useful for complex preprocessor commands.

Thought of add couple of other useful preprocessor commands.

For fun let us write a application that merges two XML files (by adding a root tag)... a cool application (not really, you can do it easily using a simple shell script ;-( ).

Combine two or more xml files using gcc?
Very simple.

sample_app.x

#include FILE1
#include FILE2

compile it using:
gcc -x c -P -DFILE1=\"text1.xml\" -DFILE2=\"text2.xml\" -DROOT_TAG=root1 -E sample_app.x -o result.xml
make sure that the text1.xml and text2.xml files are available. The output will be in result.xml (defined in -o option).
we use the following compile options:
-x c here our input file is sample_app.x, and gcc doesn't know whether it is C or C++ or Java, so mention that the language is c using -x option
-P (don't generate # line directives)
-D define the macro
-E only preprocess, don't compile and link
-o output file

Even though the above example is very simple, there are couple of very wonderful technologies that are build using this like
1) SQC uses this kind of logic (you too can write your own SQC compiler with some trouble).
2) Variable-length parameter list (called varags) also uses preprocessor (if you are not sure about this, just check that printf (a c function), can take any number of arguments)... you can also create variable length argument functions.
3) Template engines. just check the google CTemplate or Java Velocity (even though they are not written using this).

Some more tools while using preprocessor.
Predefined Macros
__LINE__ current line number
__FILE__
__DATE__ current date
__TIME__
__cplusplus defined if using a c++ compiler

Other useful macros defined by gcc
__SIZEOF_INT__
__SIZEOF_LONG__
__SIZEOF_LONG_LONG__
__SIZEOF_SHORT__
__SIZEOF_POINTER__
__TIMESTAMP__
__INCLUDE_LEVEL__

Stringizing using #
Common usage of this is escaping double quotes.
For example use what to copy a string
Error: "File Not found" - please check " test.xml"
We write:
printf("Error: %s\n", "\"File Not found\" - please check \"test.xml\"");
see the code looks ugly because of escaping double quotes, use Preprocessor to automatically include escape characters.

# define Q (x) #x
printf("Error: %s\n", Q("File Not found" - please check "test.xml")); // see we are not escaping any double quotes
Check the result using the same gcc -E option.

Token pasting using ##
A good example in gcc document related to this.
Say out want to generate a commands list like:
struct command commands[] =
{
{ "quit", quit_command },
{ "help", help_command },
{ "run", run_command }
...
};

where struct command
{
char *name;
void (*function) (void); // hope you are aware of function pointer...

// I can't give you more details because I too don't much about it :-(
};

you can define as:
#define COMMAND(NAME) { #NAME, NAME ## _command }

struct command commands[] =
{
COMMAND (quit),
COMMAND (help),
COMMAND (run);
...
};

Just run the above example using gcc -P -E test2.c -o test2.text and see the output!

Copyright (c) 2008 - Suresh