Tag Archives: tips

Simple GNU Emacs keyboard macro demonstration

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.

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.

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.

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 ###

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.

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

Fix mouse cursor jumping to top left corner of screen on OpenSolaris

Update 2009-11-07: This issue is fixed in OpenSolaris build snv_126.

OpenSolaris dev repository update snv_116 introduced an XOrg bug that caused the mouse cursor to jump to the top left corner of the screen very frequently. Apparently, there is some floating point math issue is involved using MMX/SSE2 instructions. I was living with the workaround posted on bugzilla. I was hoping that the bug would soon be fixed in the subsequent updates. Yesterday, I updated to build snv_122 and found that the issue still exists. Hence, I am posting about the workaround to fix this issue.

$ pfexec bash
# cp -p /usr/X11/bin/i386/Xorg /usr/X11/bin/i386/Xorg.orig 
# echo 'xf86SigioReadInput+9?w 770f 9090 9090' | mdb -w /usr/X11/bin/i386/Xorg

This bug is currently tracked in bugster.

Random links for week 36

  • My (ex-)manager David Carlton has decided to leave us to join Playdom. I learned a lot in the past two years working with him. We are going to miss him a lot! Playdom is fortunate to have such a talented individual on board. I am sure he will be bringing a multitude of perspectives into the game development at Playdom. I wish him all the very best in his new exciting game development career.
  • I am using git as my primary version control system at work. Lately, more of my friends have shown interest towards using git. For them, I would recommend knowing why git is better than other version control systems.
  • Recently, I have started editing multiple files with the same name (under different directories) simultaneously on my GNU Emacs more often. This got me confused easily and made me prone to making mistakes by editing wrong files. Here is a cool way to make buffer names unique in GNU Emacs.
  • Due to certain changes that are happening recently in our team, being agile is more of a necessity that ever before. I am seriously thinking of attending Agile Open California. Agile Open California is a coalition of agile practitioners and advocates with an intention to provide an opportunity for learning, networking and growth to the Agile community in California and others who are interested.
  • We are currently working on transitioning our software to 64-bit on Solaris. We run into interesting problems each day. Solaris 64-bit developer’s guide is a source of must know information for anyone who is working on developing 64-bit applications on Unix like platforms, especially Solaris.
  • Since I returned from India after my recent vacation, I haven’t got much chance to workout in the gym. I would like to use this opportunity for refreshing my appreciation of the basics of weight training and get a fresh start as early as next week.

GNOME Metacity dual screen issue in OpenSolaris 2009.06

With the latest OpenSolaris 2009.06, maximizing windows managed by Metacity (GNOME) will maximize the windows across both screens. This is due to an issue that Metacity was trying to use a wrong Xinerama type. This issue is fixed in the mercurial repository. However, the fix was not on time to make it into the final release of OpenSolaris 2009.06. But, there is a quick workaround for this issue. Here is the set of instructions.

Step 1. Backup your current metacity.

$ pfexec cp /usr/bin/metacity /usr/bin/metacity.orig

Step 2. Download the fixed Metacity binary from developer’s site and replace the original binary.

$ wget http://www.gnome.org/~erwannc/bugs/8748/metacity -O /tmp/metacity
$ pfexec cp /tmp/metacity /usr/bin/metacity

Note: Don’t do this in one step using wget -O /usr/bin/metacity. This broke my system.

Step 3. (Optional) By now, your new Metacity should have already started working. If not, replace the current instance by hand.

$ metacity --replace

Happy dual-screening on your OpenSolaris 2009.06!

Creating OpenSolaris live USB sticks

OpenSolaris 2009.06 was announced yesterday. You can download the live CD image (ISO) from here. Here is the set of instructions to create a live USB stick from the live CD that you have downloaded.

Step 1. Install distro-construct.

$ pfexec pkg install SUNWdistro-const

Step 2. Generate the USB image from CD image.

$ pfexec usbgen osol-0906-x86.iso osol-0906-x86-usb.img /tmp/osol

Step 3. Copy the generated USB image on to the USB stick.

$ pfexec usbcopy osol-0906-x86-usb.img

On executing the above command, you will be shown the list of removable media and asked to select the one to use with usbcopy. If you have inserted only one USB media, you will see only one entry to choose from. Please note that you may have to unmount the USB media from your GNOME file manager or command line, before usbcopy starts.

Once usbcopy completes, your OpenSolaris live USB sticks are ready to boot a live environment and perform installation. I will be in Community One West, Deep Dive sessions today (Jun 2, 2009) at Intercontinental Hotel, San Francisco. If anyone needs to make their USB media an OpenSolaris live media, please contact me.