Friday, May 16, 2008

Improve your code by using boost::transform_iterator with STL map and multimap

Often while using STL, you want to select the key or value while iterating through the map, but the STL interface yield a pair upon derefencing the iterator. This makes the interface of your class while your implementation uses map, different from interface using vector. This is undesirable.

No worry, you can return a boost::transform_iterator. boost::transform_iterator is a useful tool to transform the value of the iterator while dereferencing it. The most common use of boost::transform_iterator is in the situation described above, although it is more general. For using boost::transform_iterator as above, you will need functions select_first and select_second as implemented here.

Always cheers while coding in C++!

Tuesday, April 29, 2008

Fixing Some Vista Woes

We have got the latest operating system Vista in our lab and latest configuration Quad Core Intel Processors. We have got large monitors and we have got game consoles. We have got them all. But Vista has been troubling me for quite some time. It randomly hangs (I found online it might be around 30 seconds) for some time. How do I find what is the issue and fix it?

I login as an Administrator, go to Control Panel > Administrative Tools > Event Viewer. Event Viewer > Application shows several errors - most related to vmware. Event Viewer > System also shows some errors. I will need to track these errors from now on.

To my surprise Event Viewer > System shows several error events (to view just error events, Menu > Action > Filter Current Log) which could be significant:
  1. The file system structure on the disk is corrupt and unusable. Please run the chkdsk utility on the volume OS. Such events were raised at 2 AM (probably after some system process executed) on 30 April 2008.
  2. The device, \Device\Ide\iaStor0, did not respond within the timeout period.

So I took the following steps:

  1. I ran chkdsk on my disks. As I expected there are no errors detected.
  2. For the iaStor0 issue, saw http://www.intel.com/support/chipsets/imsm/sb/cs-025783.htm. I am wary of installing new things unless needed. So I will wait for Vista to hang again before I try to fix the issue.

Wednesday, April 23, 2008

How I Formed an Excel Sheet of Students in the Course I am Tutoring

Every semester once I would have to form a list of all students in a course. Since the frequency of this task is not high I dont prefer to make a program to automate this task. This time I did the following:
1. Go to IVLE to get the list of students in one page. Save this page.
2. Clear out the irrelevant lines.
3. With vim, query replace the ";" with "\r" newline, or whatever else to get "name, Metric No" list. The useful commands are:
%s/ /\r/gc
%s/.*userID=\(.*\)' , 800 , 600)">\(.*\).*/\1,\2\r/gc
:%s/.*t.*/\r/gc
:%s/^\n//gc
4. Import this data into excel.

Thursday, April 3, 2008

Ubuntu: Get Wireless Working After Hibernate

After I installed ubuntu I faced a peculiar problem that the wireless wont connect after ubuntu wakes up from hibernation.

sudo /etc/init.d/networking restart didnt work for me.

Later I found that:

sudo /etc/init.d/dbus restart worked. But I am afraid it might be risky to do it everytime since it restarts a very low level process (though I am not an expert on this, and have no right to say it might be risky or not).

So as stated in this forum I edited the services that are shut down on hibernation. Have to see how it works out!

Wednesday, March 19, 2008

Eclipse does not use User's Environment Variables on Linux

Eclipse + CDT does not pick the environment variables I defined in ~/.bashrc, for example LD_LIBRARY_PATH.

Getaround tried - I changed the eclipse driver file in the same way as firefox uses firefox-bin.

amit@ubuntu:~$ cd /usr/bin
amit@ubuntu:/usr/bin$ sudo mv eclipse eclipse-bin
Password:
amit@ubuntu:/usr/bin$ sudo vim eclipse
amit@ubuntu:/usr/bin$ sudo chmod 755 eclipse

BUT IT DID NOT WORK.

Finally I had to enter environment variables manually into the eclipse CDT dialog.

Saturday, February 9, 2008

C++: Forward Declarations and Typedef

Consider the situation where I have two header files A.h and B.h

A.h:
class FwdDeclared;

----

B.h:
class Defined {
...
};

typedef Defined FwdDeclared;

----
This is not allowed in C++ [see GOTW: 034]. The GCC compiler complains: "error: Conflicting declaration". I need to look for the rationale for this language behavior. The workaround is to use "typedef Defined FwdDeclared" in A.h too - which means you're not forward declaring the typedefed class at all. I am looking for a better way to do this.

Tuesday, February 5, 2008

Installing MPICH2

I downloaded MPICH2 from http://www.mcs.anl.gov/research/projects/mpich2/ and installed it as Administrator on my lab's Windows Vista machine. After compiling my source the command
mpiexec.exe -n 1 MPICircuitSAT.exe
would not run complaining "Unable to connect to port 8676 ... No connection could be made because the target machine actively refused it." Update: Later I figured this is the error when smpd.exe is not running. Start smpd.exe using
smpd.exe -start

I then did
smpd.exe -install
in \bin, but only to receive a different error message on execution again:
"Aborting: Unable to connect ..."

Thursday, January 31, 2008

WxWidget Linking Woes

I am trying out using WxWidgets for UI for our Crackpot project (started with the basic example at WxWidget documentation at http://www.wxwidgets.org/docs/tutorials/hello.htm)

Link errors while using WxWidgets were resolved using stuff at: http://www.soe.ucsc.edu/~agames/wxogl.htm

Some other link errors are still left :(

Updated on Feb 8, 2008:

The link errors I was getting were related to unresolved symbols:
  • wxFrameNameStr
  • wxApp::Initialize

I was able to fix these today after much hue and cry, after I built the sample projects in the wxWidgets/samples directory. I copied the VC++ settings from these samples to my project. Indeed my settings were quite a lot different from that used in samples - preprocessor definitions, system type: (I was using console in place of windows), linked library names.

Anyway, all is well that ends well. Lesson learnt: Look for samples of compilation using a downloaded open source library first, before getting stuck with a compilation problem.