Monday, October 17, 2011

How to tie a tie in 10 seconds

I found this post really interesting and wanted to share with you all. Hope this would help you guys!

Wednesday, September 14, 2011

volatile keyword in C++

I came across the keyword volatile for the first time.

It is used to prevent the compiler from modifying a segment of code for optimization. Variables defined with volatile keyword can be used for:
  • accessing memory mapped devices
  • signal handlers etc.
Here is an example (from wikipedia).

static int foo;
 
void bar(void) {
    foo = 0;
 
    while (foo != 255)
         ;
}
 

This code will be optimized to:
 
void bar_optimized(void) {
    foo = 0;
 
    while (true)
         ;
}
by an optimizing compiler.

If, however, the variable foo can change outside the code, we do not want the compiler to modify it. So, we use the volatile keyword as follows:
 
static volatile int foo;
 
void bar (void) {
    foo = 0;
 
    while (foo != 255)
        ;
}

Tuesday, September 13, 2011

SVN Checkout

SVN stands for subversion.It is a version control software that allows users to download latest version of a particular branch without having to wait until it is properly packaged and delivered.

Here is how you can checkout from svn.
svn checkout <here you enter the web page address>
 
  

Thursday, September 1, 2011

How to change font size in LaTex equations

Credit should go to original contributor. I am just sharing here.

\documentclass{article} \usepackage{amsmath}
 
\begin{document}


 
\begin{eqnarray} 2x+3 \end{eqnarray}


 
\makeatletter

 
\def\@eqnnum{{\normalsize \normalcolor (\theequation)}}

 
\makeatother

 
{ \small \begin{eqnarray} 2x+3 \end{eqnarray} }

 
\end{document}
 

enter image description here

to make sure the size of the equation numbers are not changed we have included a redefinition of the eqnnum command.
\makeatletter  \def\@eqnnum{{\normalsize \normalcolor (\theequation)}}  
\makeatother

available sizes:

  • \tiny
  • \scriptsize
  • \footnotesize
  • \small
  • \normalsize (default)
  • \large
  • \Large (capital "L")
  • \LARGE (all caps)
  • \huge
  • \Huge (capital "H")

Wednesday, August 31, 2011

TeXniCenter 0 ERRORS, 0 WARNINGS, 0 BAD BOX, 0 PAGES.

This happens if the MikTex has missing packages. To resolve this, go to
for e.g. MikTex2.9 -> maintainance (admin) - > Settings (admin) -> General and choose

either Yes or No (but not "Ask me first") for the option "Install missing packages on-the-fly".

cheers!

Tuesday, August 30, 2011

To get files from a FTP server

This is simple.

  1. Open the given ftp location in internet explorer
  2. In the "view" tab, click on "open FTP site in windows explorer"
  3. Just copy the contents from there
Cheers!

Wednesday, August 24, 2011

To span figures in two columns in LaTex

If you need your figures to span two columns in LaTex this is what you have to do.
\begin{figure*}[t]
\end{figure*}
Just change figure into figure*. Simple as that!

Wednesday, August 17, 2011

How to Find Keywords from Files in Ubuntu

I personally have wasted much time finding keywords within files, when I wanted to debug programming codes in Ubuntu.
Here is how it is done easily.

The function we use is called grep. Most of the Ubuntu distributions come with grep installed.

If you want to find my_function in all the files in folder /home/abc
type:
grep -i -n -r 'my_function' /home/abc

definition:
grep - function to search patterns in files
-i - ignore case
-n - output line number
-r - search recursively

Use
grep --help or man grep for more details.


Thanks for reading this post. Hope it would help!

Tuesday, August 16, 2011

Typing Japanese on Windows 7

Now this is very easy.
  • Go to control panel->Clock, Language and Region - click on the "Change keyboards or other input methods"
  • Click on the "Keyboards Languages" tab. Then click the "Change keyboards" button.
  • Click the "Add" button to add Japanese input capability.
  • Scroll down to Japanese. In the Keyboard section section choose "Microsoft IME. Click "OK".
That's it!

Sunday, August 14, 2011

Windows 7 and Hidden Partitions

  • I am using a Toshiba Dynabook laptop and I finally decided to install Windows 7 on it. Toshiba laptop has two hidden partitions; one for recovery called HDDRECOVERY and the other one for booting, called TOSHIBA SYSTEM VOLUME. Now when Windows 7 was installed it had created two more primary partitions, finishing up all the four primary partitions you can create. (In Windows 7 a small 100MB partition is created for system stuff). This makes you run out of all the primary partitions and you may not be able to install any other operating system like Ubuntu.
  • Now, unless one of your primary partitions is an extended partitions you cannot create any more partitions in the disk. So, I had to remove the hidden HDDRECOVERY. You can copy contents of hidden partitions using an Ubuntu live cd. Using System->Administration->Disk Utility mount the hidden partition you want and you can copy it to wherever you want.
  • On an extended partition you can create logical partitions and you can use this extended partition to install Ubuntu.

Cheers

Saturday, July 23, 2011

OpenCV for Visual C++ 2010 Express Edition

This is how it is done.

  1. If you do not have Visual C++ 2010 Express Edition, get it from http://www.microsoft.com/visualstudio/en-us/products/2010-editions/express
  2. Get OpenCV from http://sourceforge.net/projects/opencvlibrary/files/opencv-win/2.2/ 
  3. Choose OpenCV-2.2.0-win32-vs2010.exe
  4. Install it following the easy instructions. (add the OpenCV path to the PATH variable when asked)
next let us see how Visual C++ 2010 Express Edition can be configured. This can be easily done using a project property sheet.
  1. First go to View in VC++ Express Edition and check whether the Property Manger is there. If not, go to Tools->Settings and choose Expert Settings.
  2. Next, choose Property Manager from View; this will open up Property Manager side-by-side with solution explorer and Class view.
  3. Right click on top of your project name and since this is first time, click "Add New Project Property Sheet" and give a suitable name for your property sheet.
  4. By double clicking on the file name open the newly created property file.
  5. In Common Properties->C++->General: Additional Include Directories enter
    1. <OpenCV2.2 directory>\include;
  6. In Linker->General: Additional LibraryDirectories enter
    1. <OpenCV2.2 directory>\lib
  7. In Input: Additional Dependencies enter
    1. opencv_core220d.lib;opencv_highgui220d.lib;opencv_video220d.lib;opencv_ml220d.lib;opencv_legacy220d.lib;opencv_imgproc220d.lib if you are in debug mode
    2. opencv_core220.lib;opencv_highgui220.lib;opencv_video220.lib;opencv_ml220.lib;opencv_legacy220.lib;opencv_imgproc220.lib if you are release mode
now test the installation using this example code. Change the image file name.

#include <stdio.h>
#include <highgui.h>
int main( int argc, char** argv )
{
 IplImage* img = cvLoadImage( "c:/temp/abcs.jpg",1 );
 cvNamedWindow("test", CV_WINDOW_AUTOSIZE );
 cvShowImage("test", img );
 cvWaitKey(0);
 cvReleaseImage( &img );
 cvDestroyWindow("test");
}

Thursday, June 2, 2011

C++ File Read/Write at the same time

I ran into a problem where after I read a file using getline command, nothing was written to the file. You can overcome this problem using yourFile.clear(); yourFile.seekg(0).

sample code

    string zline;
    int iLine = 1;
    fstream m_File;

    m_File.open(zFileName, ios::in | ios::out | ios::app);
    if (true == m_File.is_open())
    {
        while (getline(m_File, zline))
        {
            ++iLine;
        }

        m_File.clear();
        m_File.seekg(0);

        m_File << iLine << " " << "Test" << "\n";
        m_File << flush;
        m_File.close();
}

Sunday, April 24, 2011

How to install Qt for Visual C++ Express Edition

Qt is a cross-platform GUI toolkit, whose SDK available under LGPL licence so that we can use it for free. It uses MingGW (gcc) compiler, which is not good as Visual C++ compiler. So you would like to use it together with, let's say Visual C++ Express edition. However, installing it with Visual C++ Express edition is little bit tricky. We have to build it with Visual C++ and here is how it is done.

Step 1
Download and install the LGPL Qt SDK for Windows. You can ommit installing MingGW; it is assumed that you have already installed Visual C++ Express Edition.

Step 2
Open Visual C++ Express Edition's command prompt. (Tools->Visual Studion Command Prompt)

Step 3
Change the directory to Qt installation direction (usually it is something like E:\Qt\2010.05\qt)

Step 4
run configure
(use options with it so that it will be onfigured to use with the msvc2010 platform
for e.g. configure -no-sql-sqlite -no-qt3support -no-opengl -platform win32-msvc2010
   -no-libtiff -no-dbus -no-phonon -no-phonon-backend -no-webkit)

Step 5
Build Qt by typing nmake
Here is where you will encounter all sorts of trouble. It can stop abrubptly giving you an error message. Type nmake again and try to build it once more. It can get resolved automatically but if you are stuck with the same error like,

c:\Qt\2010.05\qt\src\3rdparty\webkit\WebCore\tmp\moc\debug_shared\moc_SocketStreamHandlePrivate.cpp(97) : error C2065: 'QSslError' : undeclared identifier2.c:\Qt\2010.05\qt\src\3rdparty\webkit\WebCore\tmp\moc\debug_shared\moc_SocketStreamHandlePrivate.cpp(97) : error C3861: 'socketSslErrors': identifier not found3.Generating Code...4.NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\cl.EXE"' : return code '0x2'5.Stop.6.NMAKE : fatal error U1077: '"C:\Program Files\Microsoft Visual Studio 9.0\VC\BIN\nmake.exe"' : return code '0x2'7.Stop.8.NMAKE : fatal error U1077: 'cd' : return code '0x2'9.Stop. or

then, you have to go and check for these files and delete them.
  1. delete files \src\script\tmp\moc\debug_shared\mocinclude.tmp and \src\script\tmp\moc\release_shared\mocinclude.tmp and restart nmake
  2. delete files \src\3rdparty\webkit\WebCore\tmp\moc\release_share d\mocinclude.tmp and \src\3rdparty\webkit\WebCore\tmp\moc\debug_shared\ mocinclude.tmp and restart nmake.
Remember that nmake will take time. Just be patient.

Step 6
Finally it is time to let the Visual C++ Express Edition know where the include, library and executable files of Qt are located at.

This can be easily done using a project property sheet.

  • First go to View in VC++ Express Edition and check whether the Property Manger is there. If not, go to Tools->Settings and choose Expert Settings.
  • Next, choose Property Manager from View; this will open up Property Manager side-by-side with solution explorer and Class view.
  • Right click on top of your project name and since this is first time, click "Add New Project Property Sheet" and give a suitable name for your property sheet.
  • By double clicking on the file name open the newly created property file.
  • Under common properties->C/C++->Additional Include Directories, insert
    • "..\..\..\include\QtCore";"..\..\..\include\QtGui";"..\..\..\include";"..\..\..\include\ActiveQt";
  • Under common properties->Linker->Additional Library Directories, insert
    • <your Qt directory>\2010.05\qt\lib;<your Qt directory>\2010.05\qt\lib;
  • Under common properties->Linker->Input->Additional Dependencies
    • <your Qt directory>\2010.05\qt\lib\qtmaind.lib;<your Qt directory>\2010.05\qt\lib\QtGuid4.lib;<your Qt directory>\2010.05\qt\lib\QtCored4.lib;
You can use this same property sheet when you create other Qt-based projects.

Wednesday, April 20, 2011

Figures in LaTex documents

I ran into some problems inserting figures in a LaTex document in TexnicCenter using the LaTex=>PDF configuration. When you create direct pdfs you will be using pdflatex binary, which does only deal with jpg, png image files. In the process you will loose image quality and sometimes encounter other problems; well, I had such a problem where I could not properly span my figure to column width in a two column document.

When you insert figures in your LaTex document it is better to create .ps files (LaTex=>PS) as the quality of your images will be preserved. In this configuration, you have to use image files in .eps format. Use GIMP software to convert your image files into .eps format. Also, it is better if you drag the file into GIMP so that you do not have to worry about the size of your image. And then save it in the .eps format.

So, once you create the .ps file use GSView software to convert it to .pdf files. In the process of installing GSView you will be required to install Ghostscript software as well.

A very simple code for inserting a figure in LaTex would look like this.

\section{Methodology}
The schematic diagram of the proposed system is given in Fig.~\ref{fig:robot}
\begin{figure}[htb]
 \begin{center}
  \includegraphics[width=\columnwidth]{images/robot.eps}
  \caption{Some figure}
  \label{fig:robot}
 \end{center}
\end{figure}


Do not forget to include
\usepackage{graphicx}
at the top 

Tuesday, April 19, 2011

View Output with Adobe Reader X in TeXnicCenter

I could not enable this facility in TeXnicCenter for new Adobe Reader X and it did not work out with default settings. After googling for this issue I found a solution from here.
And, I am sharing it with you guys.

  1. Enter TeXnicCenter output profiles screen by pressing ALT+F7.
  2. Select LaTeX => PDF
  3. Open the Viewer Tab
  4. Make sure that the new Adobe Reader executable path is pointing to the newly installed version, rather than an obsolete path. Common paths are:
    1. C:\Program Files (x86)\Adobe\Reader 10.0\Reader\AcroRd32.exe or C:\Program Files\Adobe\Reader 10.0\Reader\AcroRd32.exe
  5. Next, select DDE command in each section (3 times). Enter “acroviewR10” in each Server text box (3 times), and “control” in each Topic text box. In the first two Command text boxes (View project’s output and Forward Search sections) fill in:
    [DocOpen("%bm.pdf")][FileOpen("%bm.pdf")]
    And in the last Command text box (Close document before… section) fill in:
    [DocClose("%bm.pdf")]

Credit goes to original contributor.

Tuesday, April 12, 2011

Copying files in command prompt in windows

Copying files in windows is quite easy; just right click on the folder you want to copy, then select copy and then paste wherever you want it to be. However, you may have experienced that if copying stops due to some error, even the amount copyied upto that point can disappear. In that case you may want to use the command prompt for copying.
xcopy is a powerful version of the copy command with additional features; has the capability of moving files, directories, and even whole drives from one location to another.

To copy from folder1 to folder2, the syntax would be
xcopy "C:\folder1\*" "C:\folder2" /k /e /d
where
/k - Copies attributes. Normal xcopy will reset read-only attributes.
/e - Copies directories and sub directories, including empty ones.
/d[:mm-dd-yyyy] : Copies source files changed on or after the specified date only. If you do not include a mm-dd-yyyy value, xcopy copies all Source files that are newer than existing Destination files. This command-line option allows you to update files that have changed.

For additional parameter information you can have a look at here.