Thursday, January 12, 2017

MAC gcc g++ error while creating libraries clang: error: unknown argument: '-soname

The error is generated by the following command:

gcc -shared -WI -soname,libaverage.so.1 -o libaverage.so.1.0.1 average.o

It is solved by replacing -soname with install_name, i.e.,
gcc -shared -WI -install_name,libaverage.so.1 -o libaverage.so.1.0.1 average.o

Saturday, November 12, 2016

"Could not activate cellular data network” Fix for iPhone with IIT Ropar WiFi enabled!

If you are using your iPhone to access IIT-Campus wifi, and you get an error whenever you access 3G or 4G data network, the problem is the IIT Ropar network profile, which you need to install on your iPhone to access Internet.

Fix

  1. Go to "Settings" and the "General"
  2. Select "VPN" and look for "Profiles"
    • If you find IIT-Ropar profile, delete it (and all other profiles for that matter)
  • If 2 din't work, look for "Profiles" option just below "VPN"
    • If you find IIT-Ropar profile, delete it
  • Restart your phone and data network should work.
  • You can now re-install IIT Ropar profile
The problems occurs because of the stupid, unnecessary, useless, annoying apple updates which keep poking you until you install them. 

Sunday, August 7, 2016

Makefile : *** missing separator

This error comes when you do not add a "tab" before the command, just below the "target:dependencies" line, i.e.

main.o: main.cpp
[\tab] g++ -c main.cpp

A missing tab would cause this error. 

Sunday, July 31, 2016

C++: what is the difference between passing a reference and passing a pointer to a function?

Both are same in the kind of functionality they provide, they allow you to modify a variable of calling function.

Pointers store variable location and need special operators to access the content. References, on the other hand, also point to the same location but with a symbolic variable ('alias' of the original symbolic variable).

When we call a function with the original variable, a new copy of the variable is created and passed to the function. The references are introduced exactly to bypass the copy stage and pass the symbolic variable directly to the function.


The reason for the existence of references is that they are slightly more user friendly than the pointers. We can have normal expressions (without '*') and yet have pointer functionality.

References are even used when we do not want pointer functionality, i.e., we do not want to to change the variable in the called function. This is done by declaring the reference variable 'const'. The advantage is to avoid copy of the large objects.  

Thursday, July 28, 2016

While delivering presentation: how do I look at Notes?

Answer: Look at your notes in a deliberate manner and let the students know that you are consulting them.

After you finish a slide, look at your notes in a deliberate manner, don't glance surreptitiously at the notes as if you're trying to make it seem that you're not looking at or consulting notes.

It may seem long to you, but student's do not mind it. In fact, they get a breather to grasp the things explained at the previous slide.

Friday, July 15, 2016

Algorithm Analysis: How to calculate coefficients of asymptotic notation?


An algorithm with running time $f(n)$ is said to be $\theta(g(n))$ if the following holds:

$c_1g(n) \leq f(n) \leq c_2g(n)$ for all $n>n_0$ and some value of $c_1$ and $c_2$.

For example, $f(n)=\frac{n^2}{2}-3n$ is $\theta(n^n)$.

To prove this, we need to find at least one set of values for $n_0, c_1$ and $c_2$ that satisfies above inequality. Below is a simple procedure to do that:
  1. To calculate $c_1$, obtain a value of n for which $f(n)$ is positive and solve left side inequality with that value of $n$.
    • $n_0=7$ and $c_1\leq1/14$
  2.  To calculate $c_2$, just put $n=1$ and solve the right side inequality.
    • $n_0=1$ and $c_2=1/2$
The basic idea is to make sure that $c_1$ and $c_2$ are positive.




How to add LaTex (math symbols) on blogger.com?

To write equations on blogger.com using LaTex, you need to add a java script to the template. Follow the steps below to add the script.
  1. Click on the Blog (not Post) you want to add equations to.
  2. Find "Template" on right side panel and click it.
  3. Click on "Edit HTML".
  4. Search for <head> and paste the following text just below <head>:
  5. Save it and add latex math code in-between two dollar signs ($\$$latex$\$$) as follows:
    • Einstein's most famous equation is $\$E=mc^2\$$
  6. It will appear as: 
    • Einstein's most famous equation is $E=mc^2$

Tuesday, August 18, 2015

How to configure XeLatex for US Letter (8.5x11 inches) pdf size?

Most conferences and journals only accept US Letter size formatted PDF. However, most latex compilers produce A4 size PDF by default. You need to explicitly tell the compiler to generate US Letter size.

XeLatex is one of those compilers that allow you to use both PDF and EPS figures. To configure XeLatex for US Letter size, follow this:

  • In whatever editor you are using, find the place where you provide arguments for XeLatex compiler. For texmaker, it is at "Preferences" or "Configure texmaker", depending on your version.
  • Add -papersize=letter to the arguments. The modified arguments should look something like this:
    • xelatex -synctex=1 -papersize=letter   -interaction=nonstopmode %.tex
  • Save and compile your code.

Tuesday, May 26, 2015

Latex Tables: How to Center Text Both Horizontally and Vertically

The normal approach is to use ">{\centering\arraybackslash}m{3cm}" to specify cell format at the top:
\begin{table}
\centering\begin{tabular}{|>{\centering\arraybackslash}m{3cm}|>{\centering\arraybackslash}m{5cm}|} \hline\textbf{Topic} & \textbf{Paragraph} \\\hline \hlineTopic 1 & This is a paragraph. This is a paragraph. This is a paragraph.\\\hline\end{tabular} \end{table}
The text is both vertically and horizontally centered, but, you probably want the Paragraph column to be left aligned. If you use "p" to specify the cell format for the second column, the text will no longer be vertically centered:

\begin{table} \centering\begin{tabular}{|>{\centering\arraybackslash}m{3cm}|p{5cm}|} \hline\textbf{Topic} & \textbf{Paragraph} \\\hline \hlineTopic 1 & This is a paragraph. This is a paragraph.\\\hline\end{tabular} \end{table}
To have a paragraph style text and vertical alignment both at the same time, use  ">{\centering\arraybackslash}m{3cm}" to specify cell format at the top and use \multicolumn{1}{m}{Text} in the table entry:
\begin{table} \centering\begin{tabular}{|>{\centering\arraybackslash}m{3cm}|m{5cm}|} \hline\textbf{Topic} & \textbf{Paragraph} \\\hline \hlineTopic 1 & This is a paragraph. This is a paragraph.\\\hline\end{tabular} \end{table}
Enjoy!
 






Sunday, April 12, 2015

Ubuntu Matlab: Error using VideoFileReader/setup Could not open the specified file.

In order to read video file using vision.VideoFileReader object, you need to initialize it:

video_source = vision.VideoFileReader('test.avi')

Now, to access a (next) frame of the video, you need to run the following command:

frame  = step(videoSource);

If you are doing it for the first time after fresh Matlab installation, you will probably run into the following error:

Error using VideoFileReader/setup 
Could not open the specified file.

This happens because Matlab is unable to find the correct codec to decode the video file. To solve this problem, follow these steps:


  • Install ubuntu-restricted-extras
    • sudo apt-get install ubuntu-restricted-extras
  • Install Gstreamer
    • sudo add-apt-repository ppa:gstreamer-developers/ppa
    • sudo apt-get update
    • sudo apt-get install gstreamer0.10-tools gstreamer-tools gstreamer0.10-plugins-base gstreamer0.10-plugins-good gstreamer0.10-plugins-bad
  • Install gstreamer0.10-ffmpeg 
    • sudo add-apt-repository ppa:mc3man/trusty-media
    • sudo apt-get update 
    • sudo apt-get install gstreamer0.10-ffmpeg
Restart the Matlab and it should work just fine!

Enjoy!



Sunday, March 29, 2015

The curious writing style of Benjamin to manage the overall THEME of the paragraphs and paper!

It is very simple.

Instead of writing full text in the beginning itself, write 2-3 lines summarizing the message you want to convey by each paragraph.  While writing the full text, just expand these lines. Make sure that the content you add to each paragraph adheres to the final message of the paragraph.

To manage the theme of the whole paper, just write the messages of each paragraph and read them all together. You will get a clear idea of whether or not the paragraphs follow a single theme and story. 

Monday, August 19, 2013

How to remove white space from eps and pdf figures!

When we store figures as pdf, they are stored with high quality in a vector format.  But generally the whole page is stored, with lot of white space around the actual figure. There are two ways to remove this space.

1. Convert to eps and remove space from eps

Do NOT use GIMP autocrop feature for removing the space. GIMP converts the images into bitmaps (non-vectored) which is bad quality. 

Follow the steps below to create high quality eps figures and remove space:
  • pdftops file_with_space.pdf file_with_space.eps
  • cat file_with_space.eps | ps2eps > file_without_space.eps

2. Remove space directly from pdf

To do that, use the pearl script given at http://www.ctan.org/tex-archive/support/pdfcrop/. For instructions, read the README file.

Wednesday, July 31, 2013

latexdiff: Excellent tool to view modifications!

It is hard to specifically see the changes in two versions of a paper. It is even harder to spot those changes in the .tex files. To visualize the changes (or differences) between two latex version of a paper, we can use an excellent tool, latexdiff, freely available for linux. It can be installed with a simple command:
  • sudo apt-get install latexdiff 
The output file will have colors and annotations to mark the differences. The name of the output file is derived from the input filenames.

Difference of two local .tex files (latexdiff)

  • latexdiff --flatten --pdf old-file.tex new-file.tex > diffs.tex
(the –flatten argument makes latexdiff recursively operate on any included .tex files.)

Difference of SVN versions (latexdiff-vc)

  • Compare current working copy with earlier version
    • latexdiff-vc --pdf --flatten -r version file.tex > diffs.tex
  • Compare two versions
    • latexdiff-vc --pdf --flatten -r version1 -r version2 file.tex > diffs.tex

A guide to begin work at University of Ottawa

Important Formalities

  1. On the first day you arrive Ottawa, go to City Hall (City of Ottawa) and apply for SIN (Social Insurance Number) and OHIP (Ontario Health Insurance Plan).
    • For SIN, you only need your passport and work permit. Carry your job offer just in case.
    • For OHIP, you need to provide a proof of address. You can carry your lease agreement. 
  2. To be on campus, you need to have medical insurance. Your free insurance (OHIP) only starts after three month. Therefore, you need to apply for private insurance for these three months. You can do that at the HR office. It will cost you around C$171 for three months. Chose the option to pay from your salary.
  3. Come to the department and meet Prof. You need to sign a contract with Prof and submit a to the department office. After approval from the Director, you will get a copy of the contract.
  4. You need to take that copy to the FGPS for registration as postdoctoral researcher.

Other Logistics

Access Card

Go to the department and obtain forms to fill. You need your supervisor to sign those form. You also need to finish WHMIS test before you can get access card. 

Email ID

You will get it automatically after registration.

Staff Card

You will get staff card from HR office.

Thursday, June 27, 2013

Most Complete Guide For Installing, Compiling, and Running OpenCV on Ubuntu!

I went through many guides to install OpenCV on my Ubuntu machine, but most of them are incomplete. A complete installation of OpenCV, with working video encoding/decoding functionalities, requires support of ffmpeg and x264, which in turn depend on many other libraries. 

In this guide, we will first install x264 and ffmpeg, and eventually OpenCV. Finally we will see how to configure OpenCV and compile programs. Most of the information is found at the following three blogs: [1], [2], and [3].


1. Remove old ffmpeg and x264

  • sudo apt-get remove ffmpeg x264 libx264-dev libav-tools libvpx-dev

2. Install all dependencies for ffmpeg and x264

  • sudo apt-get install build-essential checkinstall git cmake libfaac-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev libvorbis-dev libx11-dev libxfixes-dev libxvidcore-dev texi2html yasm zlib1g-dev pkg-config
  • Download and install yasm 1.2.0 from here
    • ./configure --prefix=/usr
    • make
    • sudo make install
Image I/O
sudo apt-get install libtiff4-dev libjpeg-dev libjasper-dev
Video I/O
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev
Python
sudo apt-get install python-dev python-numpy
Download and install libjpeg
sudo apt-get install libjpeg8 libjpeg8-dev
Other third-party libraries
sudo apt-get install libtbb-dev
GUI
sudo apt-get install libqt4-dev libgtk2.0-dev

3. Install x.264 and ffmpeg

In install x264 and ffmpeg, I mainly follow the guide given at [3]. Below are the main steps.

X264

Download and install latest x264 from videolan.org.
  • git clone --depth 1 git://git.videolan.org/x264
  • cd x264
  • ./configure --enable-static --enable-shared
  • make
  • sudo checkinstall --pkgname=x264 --pkgversion="3:$(./version.sh | awk -F'[" ]' '/POINT/{print $4"+git"$5}')" --backup=no --deldoc=yes --fstrans=no --default

libvpx

  • git clone --depth 1 http://git.chromium.org/webm/libvpx.git
  • cd libvpx
  • ./configure --enable-shared
  • make
  • sudo checkinstall --pkgname=libvpx --pkgversion="1:$(date +%Y%m%d%H%M)-git" --backup=no \--deldoc=yes --fstrans=no --default
If you get some error like "relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC",  compile libvpx with  "fPIC" option. You can do it with the following modified configure command": 
CFLAGS=-fPIC ./configure --enable-shared


Install librtmp

apt-get install librtmp-dev

FFMPEG

Downlaod latest ffmpeg 1.2.1 from here. Go to the download folder and run the following commands:
  • tar -xvf ffmpeg-1.2.1.tar.bz2
  • cd ffmpeg-1.2.1/
  • ./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb   --enable-libopencore-amrwb --enable-librtmp --enable-libtheora --enable-libvorbis   --enable-libvpx --enable-libx264 --enable-nonfree --enable-version3 --enable-x11grab --enable-shared --enable-pic
  • make
  • sudo make install

4. Install OpenCV

Get a copy of the latest source code here for OpenCV 2.4.5. Open a terminal and go to the directory where you have downloaded the tar file, and run the following commands:
  • tar -xvf opencv-2.4.5.tar.gz
  • cd opencv-2.4.5/
  • mkdir build
  • cd build/
  • cmake -D WITH_QT=ON -D WITH_XINE=ON -D WITH_OPENGL=ON -D WITH_TBB=ON -D BUILD_EXAMPLES=ON CMAKE_BUILD_TYPE=RELEASE -D BUILD_NEW_PYTHON_SUPPORT=ON -D CMAKE_INSTALL_PREFIX=/usr/local ..
  • make
  • sudo make install

5. Configure OpenCV

We need to tell linux where the shared libraries for OpenCV are located by entering the following shell command:
  • export LD_LIBRARY_PATH=/usr/local/lib

Add the command to your .bashrc file so that you don’t have to enter every time your start a new terminal.
Alternatively, you can configure the system wide library search path. Using your favorite editor, add a single line containing the text /usr/local/lib to the end of a file named/etc/ld.so.conf.d/opencv.conf. In the standard Ubuntu install, the opencv.conf file does not exist; you need to create it. Using vi, for example, enter the following commands:
  • sudo vi /etc/ld.so.conf.d/opencv.conf
  • G
  • o
  • /usr/local/lib
  • :wq!

After editing the opencv.conf file, enter the following command:
  • sudo ldconfig /etc/ld.so.conf

Using your favorite editor, add the following two lines to the end of /etc/bash.bashrc:
  • PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
  • export PKG_CONFIG_PATH

After completing the previous steps, your system should be ready to compile code that uses the OpenCV libraries. The following example shows one way to compile code for OpenCV:
  • g++ `pkg-config opencv --cflags` my_code.cpp  -o my_code `pkg-config opencv --libs` 

If you are using a Makefile, append CFLAGS and LDFLAGS as follows:
#Compiler flags
CFLAGS=-c `pkg-config opencv --cflags`
#Linker flags
LDFLAGS= `pkg-config opencv --libs`

Note: Sometimes Makefile does not include libraries if you put LDFLAGS in the middle of link command, i.e.
  • g++ $(OBJECTS) $(LDFLAGS) -o output
It is better to put $(LDFLAGS) at the end of the command after specifying output file, i.e. 
  • g++ $(OBJECTS) -o output $(LDFLAGS)

       

[1] http://karytech.blogspot.ca/2012/05/opencv-24-on-ubuntu-1204.html
[2] http://www.ozbotz.org/opencv-installation/\
[3] https://gist.github.com/faleev/3435377

How to connect to uOttawa network through vpnc on Ubuntu Linux!

Basic Setup

If you find is difficult to install standard university provided vpn software, you can use the vpn client that comes with Ubuntu, vpnc.  All you need is the information to create a configuration file. University provides a configuration file in a different format. We need to conver it in right format, copy at right place, and just run it.

Following are the steps to connect your Ubuntu linux machine to university vpn:
  1. Download the empl.pcf file from the following link: 
  2. Open the terminal and go to the folder where you downloaded empl.pcf and run the following command:
    • pcf2vpnc empl.pcf  empl.conf
  3. Copy the empl.conf file to /etc/vpnc/
    • sudo cp empl.conf>/etc/vpnc/
  4. Run vpnc with empl as argument
    • sudo vpnc empl
  5. Enter username (for employees its "E" followed by your employee number without the leading '100',e.g. E123456) and password (infoweb password).
  6. You can also hard code username and password in empl.conf file by uncommenting 
    • Xauth username
    • Xauth password
  7. To disconnect, run following command
    • sudo vpnc-disconnect

If some of the commands do not work on your computer, you may have to install new software. Find more information here

Advanced

Same procedure should work to connect to any private network. You just need the following information from the private network owner: 

IPSec gateway
IPSec ID
IPSec secret
IKE Authmode
Xauth username
Xauth password

Obtain this information and store in myvpn.conf; and follow the instructions above to run the vpn client.

Saturday, June 22, 2013

Converting pdf figure into vectored eps figure!

I used linux "convert" command to convert pdf figures into eps files, but the output figure quality was very bad. Probably its not a vectored eps figure. Therefore, I searched more and found that eps figures created by pdftops are vectored.

To convert file.pdf into file.eps, run the following command in the terminal:

pdftops file.pdf file.eps 

Wednesday, June 12, 2013

How to create vectored eps file from LibreOffice Draw!

While writing papers in Latex, we need to have vectored eps files for good quality figures. LibreOffice Draw does not have any option to save as eps in the "save as" list. However, you can export a figure (or selection to avoid white space around the figure) as eps file.

Following are the steps:
  • Create a new figure or  open existing figure in LibreOffice Draw. You can even open Microsoft Office figures in LibreOffice Draw. 
  • Select the figure you want to save. Most of the times we want to save the whole figure, so we select all (ctrl+A). If you do not select the figure, LibreOffice Draw will store it as a page with unnecessary white space around the figure.
  • Click File->Export; a window will pop-up
  • At the bottom, from "File type", select eps format.
  • Check the "Selection" box.
  • Save at your desired location by clicking on save
*Note: For some figures the LibreOffice may have problem predicting size during exporting. It happened to me with tables without boundary. Try adding boundaries to avoid that. You can select line color white if you do not want the border to be visible.

Wednesday, January 2, 2013

Quick guide for basic usage of git (on bitbucket)

The procedure for routine work on git.

Step 1: Clone the repository on your local machine by running the command given on the bitbucket site.

  • git clone https://mksaini@bitbucket.org/mksaini/test.git


Step 2: At any time, before you start editing the code, update your local repo with latest commits with the following command:

  • git pull origin master


Step 3: Make your changes in the files and commit the changes

  • git commit -m "Committing changes" -a
Step 3.1: In case you have added a new file or folder to the repo, or you want to commit only particular file or folder, you need to specifically add that before running the above mentioned commit command (in that case, the commit command should be run without option "a"):
  • git add file/folder  


Step 4: Push the changes to the remote repo, i.e., reflect the commit in the remote repo:

  • git push -u origin master
The procedure for putting code in a new repo:

Step 1: Create a new repo on bitbucket (it is better to use the same name for the repo your local project folder)

Step 2: Go to you project folder and delete any previously present git files in there
  • rm -rf .git/
Step 3: Initialise git
  • git init
Step 4: Configure it for the remote repository. You can find the command to do that on bitbucket itself. To get that, select you repo, and then select "I am starting from scratch":
  • git remote add origin https://username@bitbucket.org/your_repo.git
Step 5: Add all
  • git add *
Step 6: Commit
  • git commit -m "My first commit"
Step 7: Push the changes to the remote repo (i.e. save on bitbucket)
  • git push -u origin master

Monday, July 23, 2012

Adding existing C++ Makefile project to Ecplise for editing the files!


On linux based systems we generally compile C++ projects with Makefile. The default editors for the source code are gedit or vi/vim. However, these are not so user friendly for editing complex codes.

Therefore, many a times we want to use Eclipse for editing source files and comiple it using a Makefile. It can be done by adding the project to Eclipse in the following steps:

  1. Open Eclipse with its default workspace.
  2. Go to File->New->Makefile Project with Existing Code
  3. Browse to the main folder in which you have your project files
  4. Give appropriate project name. I generally like the name to be the same as the root folder.