Recent Tweets

    Elsewhere

     

    July 2010
    S M T W T F S
    « Apr    
     123
    45678910
    11121314151617
    18192021222324
    25262728293031

    Archives

    Introduction to Test-Driven Development in C++ using Boost Test Library

    I have been following Test-Driven Development for a few years now. Even though TDD is widespread, often I come across a few friends who aren’t very familiar with TDD approach. It took a while for me to really appreciate TDD since I was introduced to it. When I demonstrated TDD in action, I got a few of my friends interested.

    We have our own test framework that we use in our project which was primarily developed by David Carlton. It works very well for our needs. However, for my personal projects, I wanted to try something that is more widely used in the industry. I started using CppUnit for a while until I found Boost Test Library coming a long way. Now, I use Boost Test Library for all my personal projects. It is very easy to setup tests and I really like it.

    I also wanted to write a quick introduction to Boost Test Library. So, I thought that I will put down a screencast that will solve two purposes of demonstrating Boost Test Library and serve as an introduction to TDD. This is not an extensive demo or an introduction. I have chosen a really simple problem that is often asked in preliminary rounds of technical interviews. But, it is a good place to start. I don’t guarantee that the solution is efficient. But, it is correct to my knowledge. Please feel free to suggest issues or improvements.

    Please note that a HD version of this video is available when viewed on Vimeo’s site.

    Continue reading Introduction to Test-Driven Development in C++ using Boost Test Library

    • Digg
    • del.icio.us
    • Twitter
    • Facebook
    • Google Bookmarks
    • LinkedIn
    • Live
    • Yahoo! Bookmarks
    • Posterous
    • Sphinn
    • Mixx

    Simple GNU Emacs keyboard macro demostration

    My obsession for GNU Emacs has grown over years to an extent where I managed to get a significant amount of users to adopt Emacs. In the past 10 years, I have learned a lot of nice tricks that I can do on Emacs to improve my productivity. So, I have decided to create a series of screencasts demonstrating some of those.

    I will start with a very simple one, macros. Quoting from Emacs documentation, “A keyboard macro is a command defined by an Emacs user to stand for another sequence of keys. For example, if you discover that you are about to type C-n M-d C-d forty times, you can speed your work by defining a keyboard macro to do C-n M-d C-d, and then executing it 39 more times.”

    In this demo, I have taken a real world example where you have to add C++ class member variables and accessors. There are other efficient ways to do such tasks in GNU Emacs. I personally use yasnippets to do these things. However, this approach is shown just to demonstrate keyboard macros. To supplement this video, please take a look at the keyboard macro documentation that is available within Emacs.

    • Digg
    • del.icio.us
    • Twitter
    • Facebook
    • Google Bookmarks
    • LinkedIn
    • Live
    • Yahoo! Bookmarks
    • Posterous
    • Sphinn
    • Mixx

    Mozilla Thunderbird 3 and Google Contacts addon issue

    Yesterday, I upgraded my Ubuntu 9.10 to Ubuntu 10.04 beta 1 (Lucid Lynx). Lucid comes with Thunderbird 3. After upgrading, using Thunderbird 3 once and rebooting, Thunderbird started up with empty profile and showed the account creation window. When I looked into the home directory, I noticed that my .thunderbird is moved to .thunderbird.upstream and the new .thunderbird is created with an empty profile. Moving the .thunderbird.upstream back to .thunderbird will work fine the first time and on the next startup, Thunderbird will repeat the same and start with an empty profile.

    After banging my head against this issue for a while and some help from #ubuntu-mozillateam, I figured out that Google Contacts addon is causing this problem. When Thunderbird starts up, Google Contacts addon creates a .mozilla-thunderbird directory which is the directory for Thunderbird 2. Thunderbird 3 doesn’t like this directory and it does all this renaming stuff. Uninstalling the Google Contacts addon fixed this issue for me.

    The lesson that I learned from this experience is to start Thunderbird in safe mode, thunderbird --safe-mode that will help you to isolate issues that are caused by faulty extensions.

    • Digg
    • del.icio.us
    • Twitter
    • Facebook
    • Google Bookmarks
    • LinkedIn
    • Live
    • Yahoo! Bookmarks
    • Posterous
    • Sphinn
    • Mixx

    Getting untruncated command line options passed to a Solaris process

    If you have ever wanted to get the command line options that were passed to a running Solaris process, you might have noticed that the output of command line arguments from ps is truncated to 80 characters. Looking into /usr/include/sys/procfs.h will reveal the reason why! This is because of the restriction in struct psinfo. Here are the relevant fields from the definition of struct psinfo.

    #define	PRFNSZ		16	/* Maximum size of execed filename */
    #define	PRARGSZ		80	/* number of chars of arguments */
     
    typedef struct psinfo {
             /* Fields omitted */
             char pr_fname[PRFNSZ];    /* name of exec'ed file */
             char pr_psargs[PRARGSZ];  /* initial characters of arg list */
             /* Fields omitted */
    } psinfo_t;

    So, due to the 80 characters restriction in psinfo::pr_psargs, the kernel will not be keeping track of arguments beyond the limit. Now, the only way to get the information is from the process’ memory of argv. In order to do this, you should have access to read the processes’ memory. This is the trick employed by both pargs and BSD version of ps with -ww switch.

    To get the full length command line arguments passed to a process, you can do one of the following.

    $ /usr/ucb/ps eww <pid>
    $ pargs -l <pid>

    One catch here is that, if the process has modified the argv since it was started, the output reported by both ps and pargs will show the modified data and not the initial arguments that were passed in. However, modifying argv within a program is not a standard practice and hence the chance of encountering such a scenario is remote.

    • Digg
    • del.icio.us
    • Twitter
    • Facebook
    • Google Bookmarks
    • LinkedIn
    • Live
    • Yahoo! Bookmarks
    • Posterous
    • Sphinn
    • Mixx

    Dumping core file from set-UID, set-GID 'ed processes in Solaris

    I had a previous post on how to turn on core files for set-UID, set-GID processes under Linux. Recently we ran into the same problem on Solaris. To turn on core files for set-id processes, use coreadm.

    $ pfexec coreadm -e global-setid

    Please keep in mind that these core files can have information that non-privileged user isn’t supposed to know. Quoting from Solaris man page:

         A process that is or ever has been setuid  or  setgid  since
         its  last  exec(2)  presents  security issues that relate to
         dumping  core.  Similarly,  a  process  that  initially  had
         superuser  privileges  and  lost  those  privileges  through
         setuid(2) also presents security issues that are related  to
         dumping core. A process of either type can contain sensitive
         information in  its  address  space  to  which  the  current
         nonprivileged  owner  of the process should not have access.
         If setid core files are enabled, they are created  mode  600
         and owned by the superuser.
    • Digg
    • del.icio.us
    • Twitter
    • Facebook
    • Google Bookmarks
    • LinkedIn
    • Live
    • Yahoo! Bookmarks
    • Posterous
    • Sphinn
    • Mixx

    Random links for week 7

    • Last week, I filed my 2009 Federal and State taxes through TurboTax. I found a promotion from Fidelity that offered 25% discount on all TurboTax products. If you are a TurboTax user, you can take advantage of it. You need not be a Fidelity customer to use this promotion. This is not a recommendation or endorsement for TurboTax. Take the discount if you are an existing user or you decided to try TurboTax.
    • Last weekend, I went to Mt.Rose for skiing with Luke Hornof. This was second ski trip. The first one was Sierra at Tahoe. Mt.Rose was a smaller resort compared to Sierra. However, I liked it much better for the experience that I had. The lift lines were smaller and the people were much friendlier. The ski rental shop people were very helpful and paid good attention in getting the right equipment and settings. The ski instructor Scott was one of the most knowledgeable ski instructor and was an excellent skier! Overall, it was a very positive experience and I will go there again. I am also planning to take a bunch of private lessons from Scott.
    • During the ski trip, we stayed at Carson City. It was a small city, not so busy! The people were cool and very nice. Luke and I were hoping around bars, pool clubs and hookah lounges on a quest with a hypothetical question and it was fun. I liked this place. But, I am not sure if I will visit this one again.
    • Digg
    • del.icio.us
    • Twitter
    • Facebook
    • Google Bookmarks
    • LinkedIn
    • Live
    • Yahoo! Bookmarks
    • Posterous
    • Sphinn
    • Mixx

    Chainloading OpenSolaris from GRUB 2

    I have a triple boot system with OpenSolaris, Ubuntu 9.10 and Microsoft Windows XP. I upgraded my Ubuntu 9.10 GRUB to GRUB 2 today. GRUB2 automatically added an entry for Microsoft Windows XP. However, it didn’t detect the OpenSolaris that was installed. I had to manually configure OpenSolaris chainloading in GRUB 2. If you are in a similar situation, this will be helpful for you to configure your GRUB 2.

    Find your OpenSolaris partition.

    $ sudo fdisk -l
     
    Disk /dev/sda: 320.1 GB, 320072933376 bytes
    255 heads, 63 sectors/track, 38913 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Disk identifier: 0x00099420
     
       Device Boot      Start         End      Blocks   Id  System
    /dev/sda1               1       12158    97659103+   7  HPFS/NTFS
    /dev/sda2   *       12159       24314    97643070   bf  Solaris
    /dev/sda3           24317       38913   117250402+   f  W95 Ext'd (LBA)
    /dev/sda5           24317       38297   112302351   83  Linux
    /dev/sda6           38298       38913     4947988+  82  Linux swap / Solaris

    In my case, it is /dev/sda2. Once you have found it, edit /etc/grub.d/40_custom and add the following entry for OpenSolaris. A key difference between GRUB and GRUB 2 is the device numbering. In GRUB, sda2 is (hd0,1). However, in GRUB 2, sda2 is (hd0,2). Keep this in mind when you are configuring your GRUB 2.

    # Chainload OpenSolaris GRUB.
    menuentry "Chainload OpenSolaris GRUB" {
        set root=(hd0,2)
        chainloader +1
    }

    Now your /etc/grub.d/40_custom should look like the following.

    #!/bin/sh
    exec tail -n +3 $0
    # This file provides an easy way to add custom menu entries.  Simply type the
    # menu entries you want to add after this comment.  Be careful not to change
    # the 'exec tail' line above.
     
    # Chainload OpenSolaris GRUB.
    menuentry "Chainload OpenSolaris GRUB" {
        set root=(hd0,2)
        chainloader +1
    }

    Then run update-grub to regenerate /boot/grub/grub.cfg.

    $ sudo update-grub
    Generating grub.cfg ...
    Found linux image: /boot/vmlinuz-2.6.31-19-generic
    Found initrd image: /boot/initrd.img-2.6.31-19-generic
    Found memtest86+ image: /boot/memtest86+.bin
    Found Microsoft Windows XP Professional on /dev/sda1
    done

    You will not find anything about OpenSolaris in the output message. However, you can examine /boot/grub/grub.cfg to find if an entry is added for OpenSolaris.

    $ tail -10 /boot/grub/grub.cfg 
    # This file provides an easy way to add custom menu entries.  Simply type the
    # menu entries you want to add after this comment.  Be careful not to change
    # the 'exec tail' line above.
     
    # Chainload OpenSolaris GRUB.
    menuentry "Chainload OpenSolaris GRUB" {
        set root=(hd0,2)
        chainloader +1
    }
    ### END /etc/grub.d/40_custom ###
    • Digg
    • del.icio.us
    • Twitter
    • Facebook
    • Google Bookmarks
    • LinkedIn
    • Live
    • Yahoo! Bookmarks
    • Posterous
    • Sphinn
    • Mixx

    Enabling virtual consoles in OpenSolaris

    OpenSolaris was lacking virtual console for a while. This support was made available since build snv_124. However, due to various bugs, it is turned off by default. To enable virtual consoles, do the following.

    $ pfexec svcadm enable vtdaemon
    $ pfexec svcadm enable console-login:vt2
    $ pfexec svcadm enable console-login:vt3
    $ pfexec svcadm enable console-login:vt4
    $ pfexec svcadm enable console-login:vt5
    $ pfexec svcadm enable console-login:vt6

    To enable hot keys for switching virtual consoles, do the following.

    $ pfexec svccfg -s vtdaemon setprop options/hotkeys=true
    $ pfexec svcadm refresh vtdaemon
    $ pfexec svcadm restart vtdaemon

    Console security is enabled by default. What it means is that if you leave a virtual console and move to another one, the previous virtual console will be locked and you will have to provide the password to unlock it. If you don’t like that, turn the security off.

    $ pfexec svccfg -s vtdaemon setprop options/secure=false
    $ pfexec svcadm refresh vtdaemon
    $ pfexec svcadm restart vtdaemon

    If you have already logged into an X session while doing this, logout and wait for Xorg to restart. After that, you should be able to switch between the virtual consoles by pressing the hotkey Alt + Ctrl + F#, where # => 1 to 7. Console 1 is the primary console, 2-6 are virtual consoles and 7 is the Xorg.

    • Digg
    • del.icio.us
    • Twitter
    • Facebook
    • Google Bookmarks
    • LinkedIn
    • Live
    • Yahoo! Bookmarks
    • Posterous
    • Sphinn
    • Mixx

    Tack sharp eyes

    One of the key things that I try to do when I take portraits is to focus on the eye of the subject. This is a well documented technique and works very well. Also, each lens has a sweet spot aperture for which the picture is really crisp. I find that it is at f/2.8 for my Canon 50 mm f/1.4 and f/4 for my Canon 70-200 mm f/2.8L. When I play with these sweet spots, I seem to get impressive tack sharp eyes. This is a crop from one of the self portraits that I shot with my Canon 50 mm at f/2.8. Next time, don’t shoot full wide for crisp results. Go ahead and try stopping down your aperture and find your sweet spot.

    Praveen Kumar

    Self Portrait

    Tack sharp eye

    Tack sharp eye

    • Digg
    • del.icio.us
    • Twitter
    • Facebook
    • Google Bookmarks
    • LinkedIn
    • Live
    • Yahoo! Bookmarks
    • Posterous
    • Sphinn
    • Mixx

    Beginning Alpine Skiing

    From Lake Tahoe

    This winter, I decided to give Alpine Skiing a try. As I live in the San Francisco Bay Area, Lake Tahoe is the natural choice for me to go for skiing. Me and three of my friends went to Tahoe the Christmas weekend. We stayed in The Ridge Sierra at Stateline, NV.

    I had never skied before. So, I decided to take beginner lessons. We were considering two resorts, Heavenly Ski Resort and Sierra at Tahoe. Heavenly was located very close to where we were staying and Sierra at Tahoe was a 30 minutes drive. As some of us felt that Heavenly is expensive and we got good recommendation about Sierra at Tahoe from a ski rental shop, we decided to go for Sierra at Tahoe. They had a 2.5 hour beginner lesson, ski rental and a full day restricted lift ticket for $89.

    We reached the resort at 10 am on the day after Christmas and the resort was crowded. It was a sunny day. We first had to check-in at their computers, pay for the package and proceed to the ski rentals. I got a 153 cm ski. It was awkward for me to walk with the ski boots in the beginning. The lesson started at 11:00 am. We had an instructor named Scott. We were taught about how to put on the skis, how to remove it, how to get back from a fall, wedging (French fries and Pizzas), stopping using wedge, climbing up hill without lift, getting on and off the lifts, making turns, stopping using C turn, slowing down using S turn, etc. I fell down a few times. Soon, I grasped some of the basics and managed to avoid falling by stopping using a turn or slowing down using a wedge.

    After the first day lessons, we took the lift to the bunny slopes about 10 times and applied some of the things that we learned on that day. I was able to appreciate some of the things that I didn’t quite get during the lessons. There were a few times, I fell when I get off from the chair lift. One thing that I noticed was that the times that I fell was only when there were four people riding the lift. When there were lesser people on the lift, I didn’t have an issue in getting off the lift. At the end of the day, we were so happy that we did reasonably well for the first timer. We wanted to come on the next day as well. But, my friends were warning me that we will feel so tired that we won’t be able to make it. So, we decided to defer the decision until the next day morning.

    The next day, I didn’t feel a thing. Two out of four of us opted out. Myself and Riaz Khan decided to head out for the second day lessons. It was bright and sunny when we left Stateline. However, once we crossed South Lake Tahoe, it was snowing heavily. We were wondering if we should turn around and call it off. But, we were too super enthusiastic to turn around. Finally, we got the message that it was an awesome day to ski from the ticketing lady. Also Sierra at Tahoe was running a promotion and upgraded our previous day ticket to a 3-pak at just $61 more. This time, we opted for the afternoon class and took the lift to the bunny slopes quite a few times in the morning. I got a chance to talk with various strangers while I was on the lift. One of such strangers was a Australian named Mark. He said that he will travel to the North America this season and will go back to Australia when it is winter there as he loves skiing. He identified me as an Indian and asked me why most of the Indians are either Software Engineer or a Doctor!

    I liked the teaching style of Scott and opted for his class on the second day as well. But, he insisted that I get a different instructor to get another perspective on the skiing basics as everyone has a different teaching style and approach. However, we anyway went ahead with Scott. The second class was all about making turns to slow down. We were taken to a higher slope, a 5 mile trail marked as green circle. We were coming down this slope using S turns to slow us down. We were still skiing wedged at this point. We did quite well for a beginner on his second day. I fell only once the entire stretch and I slowly gained the confidence to negotiate steeper slopes using turns. We then completed another very satisfying day at Tahoe.

    We (Riaz Khan) are planning to go for another trip soon to get our next level lessons. Scott told that we were ready for parallel skiing and turns in our next lessons. I am very eagerly looking for our next trip to Tahoe.

    I didn’t take any of my cameras to the ski resort as I don’t want to get side tracked into photography. So, there are no pictures of me at the ski resort.

    I want to share some thoughts for the beginners about the gears. Buy a snow pant. It is a very good investment. I am happy that I bought Coumbia Titaninum snow pants. They make to feel very comfortable and warm. Invest in a branded water/wind-proof gloves. I bought North Face Montana and it was really awesome. Some of my friends got cheaper gloves. But they were complaining that their fingers were freezing after they fell a few times in the snow as water went inside it. Look for pockets in the gloves to use hand warmers if needed. Next, get good goggles. You might need it on a very sunny day and even more on a snowy day. You might want to get one with good UV-A/B protection. So spend those extra dollars to get a branded goggles, because the last thing that you want to compromise is on your eye sight. Get a beanie.

    Keep some energy bars and water with you. Going to the restaurant on a crowded day will waste your time that could otherwise be spent in skiing. If you have energy bars, you can finish your meal while you are on the chair lift.

    Finally, keep snow chains in your car as the weather might change drastically and there are some parts of the highway where they might make snow chains mandatory. Even though we had a FWD sedan (Nissan Altima), we didn’t use snow chains during this trip. But, we carried the chains in the car.

    • Digg
    • del.icio.us
    • Twitter
    • Facebook
    • Google Bookmarks
    • LinkedIn
    • Live
    • Yahoo! Bookmarks
    • Posterous
    • Sphinn
    • Mixx