Archive for the ‘Programming’ Category

Weather Station more stable…

Tuesday, January 8th, 2008

The weather station software stopped working a couple of times in the past 24 hours, so I tried another Serial to USB converter I had available. I’m pretty sure the converter that shipped with the La Crosse WS-2316 was the culprit because I could get things working by stopping the software, removing the USB device, reinsert it, and reenabling the software. The symptoms seem likely to be a driver issue with the original adapter. I guess I’ll know if that is true after this new adapter runs for a while.

I wonder if the protocol for the WS-2316 is published anywhere… It would be interesting to see what it provides and perhaps create some different software to process the data. After a bit of searching, it appears there is a little information on the protocol here and here. Maybe if I can find some free time, I’ll try to put together an application to get the data from the unit. I’m using the WUHU software right now, and it works ok, but I’d like to optimize the data I collect for what I am interested in.

A disturbing idea in hiring…

Thursday, July 5th, 2007

This video on YouTube highlights an alleged issue in American labor. The problem seems to focus on engineers, primarily software engineers.

This is disturbing on many fronts, and I agree with Lou Dobb’s comments at the end of this second video.

Yahoo Messenger 8.0 has a really annoying bug

Tuesday, October 24th, 2006

It looks like I’m not the only one that has run into this issue. I’ve had to stop running Yahoo Messenger 8.0. It has a bug in that it steals focus from all applications running, including its own windows. If you minimize it when you are signed in, it pops right back up. Even if you aren’t signed in, the window keeps popping up in front when you switch to another application. I have noticed that when you aren’t signed in, you can minimize the window and it doesn’t appear anymore.

I’ve turned on and off (it was already off) the “keep yahoo in front of other applications” option. It doesn’t help. The odd thing about it is that it seems to be some interaction with another application. It seems to happen less often if I launch YM before other applications, although it has started happening after it has been running for a bit. I tried to submit a defect report through the menu option, but the main window kept stealing the focus from the defect report window. I had to keep clicking in the defect window between each letter I typed (including spaces). It took me over 10 minutes to type a couple of sentences. In the link I mentioned above, someone has been seeing this issue since September, and I couldn’t find anything on the Yahoo site about it. Are you listening Yahoo???! You are losing users over this issue.

Updates:
Yahoo Messenger 8.1 fixes that annoying bug
Yahoo Messenger 8.1 doesn’t fix that annoying bug

Code Gem of the Day…

Wednesday, September 20th, 2006

I ran across this particular “gem” today in some C code:


char * string = Foo();

if (string == NULL)
{
   string = (char *)malloc(1);
   sprintf(string, "%c", NULL);
}

The intent was to guarantee that “string” contains a C string. This implementation is amazingly stupid for two reasons.

  1. It is really inefficient. What they really wanted on the sprintf line is string[0] = 0; The sprintf line, requires a function call, requires the stack be set up with the string parameter "%c", and requires the function decode the string to determine how to interpret the optional arguments. The alternative I propose ends up being a couple of assembly instructions, no function call, and certainly no format string being generated.
  2. It overruns the 1 byte buffer they allocated. sprintf null terminates the string it creates, without regard for the size of the buffer you provide for storage, and without regard for the content of the formatting values. A safer way to do this would be to use snprintf, which allows you to specify how much storage you are providing. Or better yet, use the suggestion above.

The whole function that this code was contained in was poorly written, but this “gem” stood out.

Powerball number generation in C…

Monday, June 5th, 2006

Jeff Spencer wrote a comment about my previous posting about powerball odds. He mentioned that he could only generate 27,000 entries. As my post showed, there are several hundred million. I wrote a small C program to generate the actual powerball numbers, minus the powerball itself. In a private email, I told Jeff where he could find this file. The text file is 80MB, so if you are interested in it, let me know.

The C program is pretty simple. Essentially the key is to iterate over all the possible number combinations without repeating any numbers. This can be done by setting up a loop for each of the five possible numbers. Each subsequent number is just a loop from the previous number +1 to 55. It looks like this:

#include < stdio.h >
int main()
{
   int i, j, k, l, m;
   unsigned int count;
   count = 0;
   for (i = 1; i < 56; i++)
   {
      for (j = i+1; j < 56; j++)
      {
         for (k = j+1; k < 56; k++)
         {
            for (l = k+1; l < 56; l++)
            {
               for (m = l+1; m < 56; m++)
               {
                  printf("%u: %d %d %d %d %d\\r\\n", count, i,j,k,l,m);
                  count++;
               }
            }
          }
       }
   }
   return 0;
}

In linux, you can save the above text to a file called powerball.c. Then using gcc, compile it into an application with the command “gcc powerball.c” (leave out the quotes). Execute this and redirect the contents to a file: “./a.out > powerball_entries.txt” (leaving out the quotes again).