Friday, September 28, 2007

 

Windows File Association Webservice

Microsoft should not be providing a feature if it's not working. Some features they implement and force users to use are just mediocre.  One of them is their File association webservice. It's a future that pops up the following window whenever user tries to open a file by double-clicking, for which Windows has no information about.

Windows File Association Webservice

Worst part is that when user selects it and click ok, it goes to a page on Microsoft site which displays this useless page.

image

Funny that website doesn't have information for well-known extensions like xml, msi (Microsoft Installer), C (C Programming).

Fortunately, it's possible to disable this and let Windows show the good old "Select a Program" list as described here. Linked Microsoft page describes to add a registry key, which novice users may find little confusing. Download this registry file, double click, and Click Yes when Windows prompts with below message. You are all set to go.

image


 

Adding timestamp to command output in Unix

Haven't you had the same irritating expression when you are trying to troubleshoot the performance problem in Unix and find out that vmstat command (and bunch of other commands) doesn't print the timestamp, leaving you in lurch to guess the probable time to which a line in vmstat maps to?

Same goes for JDK garbage collection log files (however JRockit provides a command line option to log timestamp along).

Well, there is simple way to do this using awk. Add the below variable and function addts (stands for "add timestamp") snippet to your .bash_profile (assuming you use bash or whichever place appropriate for your shell) and you have it handy whenever you want it.

export addtscmd='{now=strftime("[%b %d %Y %I:%M:%S %p] "); print now $0}'
function addts { awk "${addtscmd}"; }

Here is an example of using vmstat before and after the timestamp.

vmstat without timestamp

[lbs@lsctlnx48 lbs]$ vmstat  1 5
procs                      memory      swap          io     system         cpu
 r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
 0  0      0  77396 173080 848712    0    0     5     3    3     3  2  1  2  2
 0  0      0  77396 173080 848712    0    0     0     0  178    94  0  0 100  0
 0  0      0  77396 173080 848712    0    0     0     0  115   106  0  0 100  0
 0  0      0  77396 173080 848712    0    0     0     0  138   115  0  0 100  0
 0  0      0  77396 173080 848712    0    0     0     0  105    95  0  0 100  0

vmstat with timestamp

[lbs@lsctlnx48 lbs]$ vmstat 1 5 | addts
[Sep 28 2007 05:26:12 PM] procs                      memory      swap          io     system         cpu
[Sep 28 2007 05:26:12 PM]  r  b   swpd   free   buff  cache   si   so    bi    bo   in    cs us sy id wa
[Sep 28 2007 05:26:12 PM]  2  0      0  77380 173080 848712    0    0     5     3    3     3  2  1  2  2
[Sep 28 2007 05:26:13 PM]  0  0      0  77380 173080 848712    0    0     0     0  190   105  0  0 100  0
[Sep 28 2007 05:26:14 PM]  0  0      0  77380 173080 848712    0    0     0     0  159   113  0  0 100  0
[Sep 28 2007 05:26:15 PM]  0  0      0  77380 173080 848712    0    0     0     0  105   105  0  0 100  0
[Sep 28 2007 05:26:17 PM]  0  0      0  77380 173080 848712    0    0     0    30  111   124  0  0 94  6

The above command addts can be used with any tool output including tail -f. So it's as easy as it sounds to timestamp all garbage collection log files :)


Monday, September 24, 2007

 

Round Robin List

 

In one of the projects I needed a simple Round Robin list, which would just return the next object in round robin fashion.

Even though it's trivial to come up with one, surprised to find out that I didn't find any hits when I searched for one.

This is what I came up with after half-hour. Use it as you wish.  Download here.

package org.brsanthu.misc;

import java.util.ArrayList;
import java.util.Collection;

/**
 * Simple extension to <code>ArrayList</code> with round robin functionality.
 * <p>
 * Just adds one method {@link #getNext()} which would return the next object
 * in the list and the method starts over at first element after reaching the
 * end of list.
 * <p>
 * This class it NOT designed for multi-threaded access. So necessary synchronization
 * is required before accessing {@link #getNext()} method.
 *
 * @since Sep 24th 2007
 * @author Santhosh Kumar
 */
public class RoundRobinList extends ArrayList {
   
    private static final long serialVersionUID = 1L;
   
    /**
     * Last used index. Initially it would be -1, so that
     * first element returned is 0th element of the list.
     */
    private int lastIndex = -1;
   
    /**
     * Constructs a new round robin list with default capacity.
     */
    public RoundRobinList() {
        super();
    }

    /**
     * Constructs a new round robin list and pre-populates with the
     * objects found in given list.
     * <p>
     * For more information about usage of the c, see the <code>ArrayList</code> constructor
     * page.
     *
     * @param c - collection of objects to be added by default to the new list.
     */
    public RoundRobinList(Collection c) {
        super(c);
    }

    /**
     * Creates the new round robin list with specified capacity.
     *
     * @param initialCapacity - initial capacity.
     */
    public RoundRobinList(int initialCapacity) {
        super(initialCapacity);
    }

    /**
     * Returns the next object in the list.
     * <p>
     * First invocation of this method after creating the list, always returns
     * the 0th element. Starts over the 0th element after reaching the end of
     * list.
     * <p>
     * If there are no objects in the list, returns <code>null</code>.
     *
     * @return - returns the next object in the list. <code>null</code> if list is
     *          empty.
     *
     */
    public Object getNext() {
       
        if (isEmpty()) {
            return null;
        }
       
        lastIndex++;
        if (lastIndex >= size()) {
            lastIndex = 0;
        }
       
        return get(lastIndex);
    }
}
Java2html

This page is powered by Blogger. Isn't yours?