eTechtips

Tech Tips and Insights

  • Passing JVM options to Maven

    If you are using maven to build your projects , then you might have found an out of memory condition in your tests.  Well, setting the MAVEN_OPTS variable with JVM specific options will help with this.

    Example:

    MAVEN_OPTS=-Xmx1024

    Depending on what environment you are in, you will need to set this variable.

    This will give the JVM more 1024 megs to work with and you can customize the number to fit your needs.

    0 Comments
  • Printing background Images in Firefox

    In an effort to save toner/ink, some browsers shut off the ability to print the background images and colors.

    In Firefox:

    1) Select  File->”Page setup”

    2) Select the  “Format & Options” tab

    3) Check the “Print Background (Colors and Images)” box

    In Internet Explorer:

    1)  Select  Tools->”Internet Options”

    2)  Select the Advanced tab

    3) Scroll down in the Settings window until you find the heading “Printing”

    4) Select the checkbox next to “Print background colors and Images”.

    Remember to undo this if you want to conserve ink/toner.

    0 Comments
  • Capturing the screen in Windows

    For the longest time, I thought the “Print Screen” or “PrtScr” Key on my keyboard was a throw back to much older computers with sheet fed dot matrix printers and would just print out the current Dos command shell.

    Once I figured out how to use it in windows, it has become an invaluable tool.

    I used to create presentations of source code issues. It was a great help to be able to grab a copy of the screen and place it in a Powerpoint slide or Word Doc.

    If you need a complete screen capture or even just the current window, here is what you can do.

    If you need to capture the complete screen, press the “Print Screen” button located near the top of the keyboard with the scroll lock or Pause key.   It may seem like nothing has happened, but the complete image of your current desktop has been saved into the clipboard in windows.

    If you want to just capture the current window, make sure the window you want is active and press the  Alt and “Print Screen” keys together.

    Now open Paint, MS Word or any other program capable of handling images, and type Ctrl-V.  This will take the image that has been captured into memory and place it in the program.  Now you can manipulate the image to crop it or use it in your document.

    This is a built in function of the MS Windows Operating system.

    If you need more control there are other applications that can let you capture portions of the screen at any time and create a file with a simple keystroke, such as SnagIt!

    0 Comments
  • Java formatting a number with leading zeroes

    Recently, I had a Java project that needed to encode a set of numbers and I needed a fixed number of digits used for each number. I found the DecimalFormat class a good solution for my needs.

    Here is a snippet of code to show a simple way to format a number with a fixed number of digits.

    import java.text.DecimalFormat;
    
    class TestEncoder
    {
            public static void main(String[] args)
            {
                    // This program expects one integer 
                    // argument and places it in the num1 
                    // variable. This program is not very 
                    // robust as to watch for no arguments
                    // or to check if the argument is not 
                    // an integer.
                    String num1 = args[0];
                    String output;
    
                    // This creates the Decimal Format instance 
                    // and assigns the formatting that we want 
                    // to use, in this case three characters .
                    DecimalFormat dfmt = 
                                 new DecimalFormat("000");
    
                    // This does the work of formatting the number
                    // passed in on the command line to be at least
                    // three digits. 
                    output = dfmt.format(new Integer(num1));
                   
                    // This just displays the results of the 
                    // dfmt.format(new Integer(num1)) command.
                    System.out.println("Output: " + output);
    }
    }
    

    The Decimal format allows for many more formatting options for numbers.

    Make sure to look a the API docs for the version of Java that you are using:
    http://java.sun.com/j2se/1.5.0/docs/api/java/text/DecimalFormat.html

    0 Comments
  • Enable 30 second skip with Comcast DVR

    Motorola DCT6412 (Comcast DVR) 30-second skip

    I have a Tivo and missed the 30 second skip that was available and I found that the same was available with the Comcast Cable remote.

    1) Press the button at the top of the remote to put it into Cable Box control mode.

    2) Press and hold the button until the button blinks twice.

    3) Type in the code 994. The button will blink twice.

    4) Press (do not hold) the button

    5) Type in the code 00173 (for 30 second Skip).

    6) Press whatever button you want to map the skip, I used the help button as I have never used it myself.

    Welcome to 30 second skipping.

    0 Comments
  • How to split large files for emailing

    I had to send a large file (about 100MB) to a client for analysis.  They did not have an anonymous ftp server so I had to figure a way to e-mail the file to them and then have a way to put it back together.

    I found the split command very useful.  I use Linux when I can but have installed Cygwin on my Windows PC to get the same functionality.

    Here is a way to break the file into 5 megabyte chunks:

    # split -b 8m veryLargeInputFile

    This instance splits veryLargeInputFile 8MB segments named xaa xab xac…xap.

    Now put the file back together  at the distant end:

    # cat xaa xab xac xad xae xaf xag xah xai xaj > veryLargeInputFile

    or

    # cat * >veryLargeInputFile

    Note: ensure xa* are the only files in the directory when using the wildcard
    For ASCII files: Split lines — This example splits a document into 1000 line segments.

    # split -l 1000 veryLargeTextFile

    Use the same process to put the file back together again.

    Note: For larger files, find a ftp server or make your filesize increments bigger.

    Split options

    -b ##   — replace ## with the number of bytes you want in a file

    -C ##   — replace ## with the number of SIZE bytes of lines per output file

    -l ##     — replace ## with the number of lines per file.

    -d          — use numeric suffixes for output files instead of alphabetic

    0 Comments
  • Welcome to eTechTips

    Say goodbye to the bouncing ball!

    As this site has been close to 10 years in the making, it is time to say goodbye to the basic flash animation that I started with on the main page.

    So feel free to ask questions or give me suggestions for topics.

    0 Comments
  • Using Variable Argument lists in functions for C and C++

    Using Variable Argument lists in functions for CC++

    In C there are times when you may want to have a variable amount of arguments passed into a function.  This can be accomplished when you pass the ellipses(…)  in as the last argument on your function.  The ellipses ,(…),  stands for zero  or more arguments.
    There are a set of functions available to handle accessing this data and making it available to your function.

    The source code example displays a version of the code for a printf like function and how to handle the optional arguments.

    One note is that the arguments passed in to this function are not typed.  The handling of the argument depends on either a specific type passed in(ints only) or as is the case of the example, a formatted string to define the types of the arguments. What this means is that if you pass random sets of arguments, (such as ints, strings,chars, floats) there is no data type that is directly associated to the variable being passed in.

    Required include file
    #include <stdarg.h>
    /* Old include <varargs.h> From before ISO C standard, GNU C compilers still support this */

    Available functions:
    Macro: va_start(va_list , last-required argument)
    This sets up the pointer for va_list with the avaiable argument list.

    Macro: va_arg(va_list, type)

    This returns the value of the next argument and modifies the va_list argument
    to point to the subsequent(next) argument.  The type of the value returned by
    va_arg is type as specified in the call. type must be a self promoting type
    not char or short int) that matches the type of the actual argument.

    Macro: va_end(va_list)

    This ends the processing of the va_list element and subsequent va_arg calls
    may no longer work.  Note: In the GNU C library implementation this does nothing
    and is used for portability.

    Sample Function Call:

      int int1 = 1;
    
        char char1 = "s";
    
        char *str1 = "test";
    
        /* Sample function call. */
        ecdprintf("Int=%d Char=%c String=%sn",int1,char1,str1);
    
    Sample Code follows:
    
    int ecdprintf(const char *pstr, ...)
    
    {
        const char *lstr;
        va_list argp;
        int lint;
        char *lchar;
        char strarr[255];
    
        /* This is the start of vararg processing. The first argument is the
             container argument of the vararg list and the second argument
             is the last fixed parameter passed into the function. */
    
        va_start(argp, fmt);
        for(lstr = pstr; *lstr = ''; lstr++)
        {
            if (*lstr != '%')
            {
                putchar(*lstr);
                continue;
            }
    
            switch(*++lstr)
            {
                case 'd':
                    i = va_arg(argp,int);
                    s = itoa(i,strarr, 10);
                    putchar(i);
                    break;
                case 'c':
                    i = va_arg(argp, int);
                    putchar(i);
                    break;
                 case 's':
                     lchar = va_arg(argp,char *);
                     fputs(lchar,stdout);
                     break;
                  case 'x':
                     i = va_arg(argp,int);
                     s = itoa(i, fmtbuf, 16);
                     fputs(lchar, stdout);
                     break;
                   case '%':
                      putchar('%');
                      break;
    
                   default:
                        break;
    
                 }
    
        }
    
        va_end(argp);
    
        }
    
    }
    

    This example created the a simple printf like function using characters within the string to let the function know how to deal with the extra variables used.

    0 Comments
  • Welcome To eTechtips – Day One

    Welcome to day one of the revamped eTechtips informational blog.

    Please feel free to request information about any topics that interest you.

    0 Comments