2009-02-12

I don't like all those decimals anymore

So I'm working on a project, and I'm using the SQL Server CE engine as my database. The database engine recently had an upgrade to 3.5.1, so when my client got a new computer and needed to install my program on it, the upgraded database engine was what was downloaded from Microsoft's web site. I didn't think much of it, as I had downloaded it as well, and I hadn't had any issues. However, when he started using the program with real-world data, he got an error:

SqlCeException: 'A parameter is missing. [ Parameter ordinal = 1 ]'

Ok, maybe I goofed. Perhaps in one of my updates, which added a column to one of the tables, I left off a parameter. So I tested the code on my machine, and it of course performed flawlessly.

I went to the client's site and tested it there. Sure enough, there was the error. I copied his database and ran my code against it, in debug mode, and… yes, I finally duplicated the error. Well, at least that told me the error was real.

Then commenced the tedious task of analyzing the SQL command being constructed; ensuring that all parameters were accounted for, all columns were spelled correctly, and all parameter names in the statement matched the names of the parameter objects added to the command; comparing his database to mine to make sure all table columns were accounted for and of the correct types. Everything matched. There were no parameters missing, misspelled, or misplaced.

After I fully convinced myself that everything was in order, I finally went to Google with the full text of the error, and I was fortunate to stumble across a bug reported on Microsoft's Connect site that indicated a problem with decimal values in SQL CE 3.5.1 under "certain conditions". Fortunately, the workaround listed helped me identify those conditions and what to do about them: it has to do with the number of decimal places one attempts to pass to SQL CE.

Fortunately, when building parameters, I pass every value through a function that checks for null and converts to DBNull (I have yet to hear a convincing reason why these must be different), and checks for bool types and converts true/false to 1/0. All I needed to do to fix this was to add code that checks for the decimal type and return Math.Round(value, 4) (although it took a little experimentation to determine that "4" was the correct number of decimals).

All because Microsoft decided they didn't like seeing all those decimal places anymore; and instead of rounding or ignoring them like they did in a previous revision, suddenly they were going to throw a completely incorrect error message (no parameter was missing, and the one it suddenly found "questionable" was not in position 1).

2009-02-11

What are you, Picasso(.Net)?

There is a form in our application that draws very, very slowly. I'm trying to fix that.

In .Net, you have very little control over a border. In many cases (in particular, in this instance, with a Panel), you only get to set whether or not the control has a border, and whether that border is solid or rendered with a 3D effect. If you want more control over the border (such as setting its thickness or color), you have to draw one yourself. Since WinForms.Net has no "Line" control, this means you have to draw the line on the form at runtime by subscribing to the form's Paint event and inserting your line-drawing code there.

You have slightly more control over a background, being able to set the color in most cases; but if you want anything fancy like a gradient, it again requires custom paint code.

It is, therefore, not surprising that we have quite a few Paint event handlers on this particular form.

The layout of our form is as follows:

  • There is data in a couple panels at the top of the form.
  • There are submit and cancel buttons in a panel at the bottom of the form, along with an information panel.
  • In the center of the form is a large area. This area (which is itself a panel) contains one to many user controls.
  • Each user control is designed first as a panel.
  • The panel contains five "header-style" panels and three user controls.
  • The top-most and bottom-most header panels contain summary information — the top being the name of this whole grouping of data, and the bottom being a subtotal.
  • The middle three header panels contain a summary of the data on each of the "sub-user controls", plus a button that hides or shows that user control.
  • On load, the sub-user controls are hidden, so a "collapsed" view of all header panels is shown.
  • The header panels are filled with a gradient fill. This gradient creates a much more visually-appealing division between header rows than solid colors with lines between them would do. (There are lines between them as well, but even with 3pt black dividing lines, solid colors just blend together across those lines in a way gradients don't.)
  • There are drawn borders around each header panel, and around the entire user control itself. There are also separator lines between most of the panels on the form elsewhere.

I thought maybe the gradient fill was just causing too much overhead, but when I replaced it with a solid fill, it had no effect on the overall speed of the form. So, I put debug code in all the Paint event handlers, to see how often the paint events were firing, as I figured this might be the source of my problem. The paint events for each of the panels on the main form fired 2-10 times each (the one panel containing the user controls firing the most often). The paint events for the innermost user controls (the "sub-user controls") fired three times each, which made sense given there were three sets of them loading — except for the first of the group, which fired six times (twice per control).

The containing user control is where things go insane. There are three of them, remember, containing five header panels and three (hidden, at startup) user controls inside. The header panels' paint events fired 5 (for the header itself) to 25 (for each of the sub-controls' headers) times each (which, I suppose, you can divide by 3 to get approximate firings per control). The user control's large panel containing all child controls (header panels and sub-user controls), its paint event fired 651 times, and the paint event for the user control itself fired 747 times!

And that's just when the form is created. I added a button that resizes the form by increasing the width by about 10 pixels, just to see the effect, and I got 153 panel paint events and 168 control paint events.

The maddening thing is, the user control's paint event handler is empty. It does nothing (except for the debug code that notes the firing). Oh, it did do something — it did draw a gradient pattern under the entire control — but since the drawing it was doing was completely covered by all the controls that were placed on top of it, I removed it.

The panel's paint method actually does something — it draws a heavy border around all the subordinate controls. And, aesthetically-speaking, it's really needed. What I can't understand is why exactly it's needed over 200 times per control, especially when the containing and contained controls combined aren't getting painted as often (by a factor of about 7).

So, what's my solution? Well, aside from making sure the paint events did as little work as possible (why is e.Graphics.SetClip(e.ClipRectangle) not automatic in a Paint event?), drawing gradients in Rectangle rect only if (e.ClipRectangle.Contains(rect) || e.ClipRectangle.IntersectsWith(rect)), and then only in the part rect.Intersect(e.ClipRectangle); but I also completely unbound the Paint event handlers in the user control, and instead of drawing a thick border on the panel, just used the default BorderStyle.FixedSingle.

It's still slow, although not as slow as it was (I'm sure those events are still getting fired, just with no custom code to process); and it doesn't look the same with the change in border, but there's enough padding between user control instances that I think I can get away with it.

In short, I didn't solve the problem; I still can't find the cause, and I've only been marginally successful in treating the symptom.

2009-02-08

A Whole New Url

I've had the domain yakkowarner.com for a couple years now. I originally used it when I decided to try out Microsoft's Office Live service. Well, I didn't really have any use for it, so I thought the URL could better serve me elsewhere.

Microsoft doesn't provide an easy-to-find link to instructions for how to grab your domain name, so I tried the back-door approach: I contacted the registrar to request a domain transfer. I got to send my very first international fax, to Melbourne, Australia. Excitement. (I actually had to do it four times. The first one didn't go through, the second one I realized I put the paper in upside down [oops], the third time didn't go through again.) Doing so prompted a tech rep from Microsoft's Office Live team to send me a very helpful and detailed message, with links, with exactly what I needed to do to release my domain so I could transfer it to my control.

So, welcome to www.YakkoWarner.com! It's the same blog with an easier-to-type address. :)

2009-02-06

Live CNN video turns your PC into a P2P server

Here's something I think should get a little more attention. According to Windows Secrets, CNN's live video streaming application turns your PC into a peer-to-peer video server, using your PC to stream the video to other PCs as well.

Personally, I don't find anything wrong with the concept. World of Warcraft uses similar technology to improve the speed of distribution of their software updates. It's what P2P tech is good for. Windows Secrets takes exception to the fact that CNN isn't exactly forthcoming about what is happening, though, and rightly so. If they came out and said what was happening when you were asked to install the "Octoshape add-in for Adobe Flash Player", then it would be less of an issue — people tend to be much more forgiving if you're up front about what you're doing. (Granted, there are other valid concerns about CNN's use of Octoshape posted there, but I won't address those here.)

What makes this such a large concern is that they are using other people's bandwidth, without their notification or explicit consent, at a time where many people's ISPs are capping their usage. The ISPs have declared that we must be conscious of how much data we consume and produce. Having an application that is uploading up to three times as much data as it's downloading, especially without our knowledge, is an issue, when every byte is being counted.

On the one hand, I fully support the concept of new technologies that help to distribute content efficiently. I don't think Blizzard is wrong to use it in distributing WoW patches, and I don't think CNN is wrong to use it in distributing video. (Again, the other issues that Windows Secrets brings up — specifically, "deceptive marketing", "ludicrous license terms", "security vulnerabilities", etc., are worth criticism, but are out of scope here.) However, they're trying to shift the cost to the end users, and we may not have the cost to spare, now that we're being limited.

I know it probably seems odd to hear me complain about bandwidth caps when mine is so large compared to what I use, but as I've said before, knowing I have a limit makes me much more conscious of the throughput I generate, and it makes me much more sensitive to anything that increases that value. Besides, just because I'm fortunate to have a wide use-to-limit margin doesn't mean everyone else is — or that I'll always be, for that matter.

2009-02-01

Bandwidth for January

It's a new month, and a new set of data for my ongoing bandwidth analysis.

There's a big spike around the 9th and 10th. Tech-savvy users may recognize this date as the day the Windows 7 beta was released. I downloaded both the 32-bit and 64-bit releases for testing. (My laptop has a 64-bit CPU, but it came pre-installed with a 32-bit version of Vista. I wanted to test how it would do upgrading to the next 32-bit OS, and how it would compare running in its native 64-bit mode.) If the downloads could've completed within the one day, it would've been the single largest day since I started tracking. As it stands, however, the 9th is only my second-largest day of consumption; the record still maintained by one day in October watching streaming video of my church's general conference.

The total for the month comes to 24.64GB down, 5.44GB up, 30.08GB total. This puts it second behind October, at 37.77GB total. My total data consumption for five months, up and down, is 148.71GB, still under the 250GB cap for a single month.

What's kind of interesting, though, is that there is news that Comcast is about to launch an online backup service. They'll have a tiered pricing plan, where you can purchase up to 200GB of online storage at a monthly rate. But, according to a Comcast representative in the linked article, transfer to and from this service is not exempt from the bandwidth cap. So, they'll be offering a service whereby you pay to use it (a lot more than you could find from other providers, too), but if you use what you pay for, you'll come close to having them cut you off of the internet. <sarcasm>Oh yeah, sign me up for that…</sarcasm>

2009-01-23

Sending email in C# - Maybe there *is* a way

Almost a year ago, I was bemoaning the fact that sending email is hard. Well, recently, my client went from a PC to a Mac, and he needed some help installing the program in the virtual XP session. When I was there, I set up the Outlook Express client so that the PDF statements could be emailed out from the virtual XP world. I figured that, since I know his email client, perhaps I could find something specific to that client for sending email.

Googling around for sending email from C# with Outlook Express, I eventually came across this CodeProject article: Programmatically adding attachments to emails in C# and VB.NET. I took the code and dropped it into my project pretty much as-is. My development machine is now a Windows Vista laptop, but this code worked just fine, starting up a Windows Live Mail window with the file attached.

There were a couple issues. One, if Live Mail wasn't started first, then I'd get an error from the MAPI call — apparently the client needs to be initialized before the call is made. (The MAPI call was starting Live Mail, but Live Mail did not appear to be in a ready state then the email was sent to it.) The second is that the SendMailPopup call (which is the one I want) blocks until the email message is closed (i.e. sent or discarded). The comments in that article, however, mention a method to split that call onto another thread, so I should be able to prepare and open several emails at once.

So I think I will create a configuration parameter that will allow the toggling of attempting to use MAPI. It should work, but it'll be preferable to have something to fall back on.

Incidentally, a discussion thread over at Channel 9 pretty much summed up the problem as such:

  • If you have Outlook, you can do it. (Use Outlook automation)
  • If you have a MAPI profile (e.g. Outlook Express), you can do it.
  • If you have SMTP, you can do it. (System.Web.Mail standard)

To which I'll add:

  • If you don't know what you have, you can try it. (mailto: link, attachments not supported)

Just for kicks, I tried this on my PC at work, which is running XP and has the Mozilla Thunderbird email client installed. It worked beautifully, whether I had Thunderbird running before I called SendMailPopup or not. I don't know if Outlook would also respond to this code or not. (I'll have to try the compiled program on my desktop with Outlook when I'm done.) If so, it could simplify things, as much as they can be considered "simplified" in what seems to be a complicated situation.

At least I'm in the fortunate situation that I'm writing this for a known, single client and a known configuration.

I do wonder why there's not a managed MAPI wrapper though. For my own convenience, I'm gathering emails into a collection of System.Web.Mail.MailMessage objects before I try sending them. Why is there no System.Web.Mail.Mapi.Send method? Maybe a System.Web.Mail.Mapi.IsClientRunning method, and so on.

2009-01-20

The Civility Project

My wife sent me a link to an article about two people with very different political, religious, and ideological views ended up forming a correspondence when one recognized and commended the other for acting courteously towards those who disagreed with him on several television appearances.

The two got together and realized that there is so much anger and divisiveness in America today, particularly about politics and religion. People talk and debate not to share ideas and encourage discussion, but to attack, divide, and belittle convictions and beliefs they don't agree with.

To that end, they came up with The Civility Project, a web site that encourages people to be civil by taking "The Civility Pledge":

  • I will be civil in my public discourse and behavior.
  • I will be respectful of others whether or not I agree with them.
  • I will stand against incivility when I see it.

The site also encourages people to post examples of civility and incivility reported in the media, and to comment on it — an open invitation to civil discourse.

It's a fairly new site, with not a lot of content as of yet, but I do hope it gets more attention. Wouldn't it be nice if people could just talk and listen, instead of berate and attack?

2009-01-12

I know you are listening

Either someone on the Aurora City Council is reading this blog, or it just so happens that that someone else had a similar complaint and was already in the process of changing something I blogged about earlier.

In this post, I suggest that the very large "Speed Limit 40" sign before the end of the school zone is very misleading. It's been this way since I've traveled this road, at least a couple years. And yet, I noticed when I took my kids to school as the school year started up again for 2009 that the very large "Speed Limit 40" sign has been removed, and now a much more normal-sized sign — one of equal size as the "End School Zone" sign — is posted instead, on the same post as the "End School Zone" sign.

Coincidence? Maybe I should test this theory.

You know, I find it annoying that large piles of generic cash don't randomly show up on my doorstep.…

2009-01-09

Bandwidth for December

I almost forgot to check my bandwidth for December — and it shows. Unfortunately, vnstat only keeps the daily stats for the last 30 days, so the daily stats for the beginning of December are lost:

 

However, the total stats for the month are stored: 20,391MB down, 6,449MB up, 26,841MB total. I'm not sure what accounts for the spike in activity on the 30th, but the 31st may have been caused by us watching the Times Square festivities on the internet (which for some reason had a lesser effect than whatever happened the day before).

Worthy of note this month is that I've started watching the online web series The Guild in high-definition on Xbox Live. Although HD, they are short, less than 10 minutes each, so the file size each is only a couple hundred Megabytes apiece, about once a week.

Totals are down about 700MB from last month, with December showing the lowest usage since I started monitoring.

2009-01-07

DTC and Windows Firewall - A Rant

Let me preface this by saying: If you're looking for a solution to getting Microsoft Distributed Transaction Coordinator (MSDTC) working through Windows Firewall, this is not the post you're looking for. No solution exists here.

I'm working on a project that is in three parts — a rich Windows Forms client, a Web Service business and data access layer, and a SQL Server database. The QA guy was having an issue where some web service calls were timing out, causing the application to crash. While I couldn't replicate it, I did notice that the web service calls being made resulted in a spike of read locks on the database. I figured a viable option would be to have that service set a transaction scope with an isolation level of Read Uncommitted. It was a quick and dirty way to get it to read data without locking in a condition where, for whatever reason, it seemed that read locks were colliding. (Doesn't make a lot of sense to me, as nothing was writing to the database at the time, but it's all I had to go on.)

After trying and failing to use the Enterprise Library to create a transaction (it kept insisting the transaction and the command objects belonged to different connections, even when I created them equal), I decided to go with the System.Transactions namespace to manage it. From a code perspective, it would be much, much cleaner anyway.

It did perform much faster, without the spike in database locks, but it revealed another problem. In trying to solve the problem himself, QA guy thought he should try splitting the application up instead of running everything on one machine, so he put the database in a virtual PC. When he got the new web service code, it threw an error about being unable to connect to the DTC service on the database server.

This was a fortunate discovery, as it would've been a problem if we got to a client's environment and found this issue.

I created three VPCs of my own and put the three pieces each on its own VPC. The rest of the next two days, I spent trying to get DTC to work between the web service and the database server.

Everything ran fine when the Windows Firewall was disabled on all machines. First, DTC had to be configured on both the web service server and the database machines by enabling "Network DTC Access" and inbound and outbound "Transaction Manager Communication". Also, the DTC service on the SQL Server had to be started and set to Automatic start. (The web service server would start its own as needed.) Also, since my VPCs were in a workgroup and not a domain, I had to set DTC to use "No Authentication" rather than "Mutual". Quite a bit of extra work, but so far, not completely outside the realm of what we might possibly have to ask a client to do to their own servers.

Turning on the firewall on the client wasn't an issue. Turning on the firewall on the web service server caused an issue with both the servicing of web service requests and database access. The former was relieved by allowing port 80 through, naturally. The latter was relieved by creating an exception for the process C:\Windows\System32\MSDTC.exe, which was recommended by articles I found describing DTC and Windows Firewall (namely, that all machines participating in distributed transactions should have this exception).

Then there was the firewall on the database server. I had to allow port 1433 for SQL Server access. No problem. Doing that meant non-transactional methods worked without a hitch. But from there, for the life of me, I couldn't get DTC to go through. I tried allowing port 135. I tried adding MSDTC.exe as an exception. Nothing. It just wouldn't work.

One or two sites suggested opening up a range of ports that DCOM uses. However, since port ranges are not a valid exception for Win32's firewall, I did not feel adding a series of exceptions for each individual port from 5000 to 5020 was a viable option — not for me, and certainly not for our clients. Not all articles indicated this was necessary anyway.

It just. Wouldn't. Work.

Incidentally, the utility DTCPing apparently works fine (once you enable RPC on both machines through the Group Policy Editor, which I had to do since my VPCs are running XP Pro). This would seem to indicate that it's not a networking issue or even a firewall issue, just a DTC-refusing-to-work issue.

A lot of things bug me about this. For one, setting up DTC requires a lot of extra steps (turn on network access, mess with authentication, start service and set startup option on database server, create firewall exceptions) that can't (easily) be done in an install routine. Two, the fact that DTC was even used at all — the code in question created a TransactionScope object, created a DbCommand, and called LoadDataSet on a Database, before disposing of everything (except the DataSet). This, to me, should not be taking more than one connection to the same database, and therefore it should not require a distributed transaction coordinator at all. And of course the typical "this (apparently) fundamental piece of Windows systems is broken thanks to a new 'security' feature" problem.

Since the only solution was to disable the firewall completely on the database server, and since this is not something we are going to ask our clients to do, I rolled back the change that added System.Transactions to the project. Right now, we're going with the assumption that the timeout errors were a problem with QA guy's machine, as it only happens when everything is running all in the process space of his primary machine. If he moves anything to a VPC (even just breaking it in two pieces, whether the web service ends up with the client or the database), it runs fine; and installing everything on the demo machine (which is actually older, less-performing hardware) also doesn't have the issue.

There go my plans for cleaning up the code, too.

2008-12-28

Focus on the Prejudice

Recently, the evangelical group Focus on the Family was promoting a certain book, The Christmas Sweater, written by Glenn Beck. In a nutshell, at least from what I can gather from the Amazon summary and other news reports, it's a book about Christmas, God, family values, and redemption. One that seems to be quite popular, and one that seems to be in line with what Focus on the Family might promote.

Unfortunately, it was "outed" that the author, Glenn Beck, was in fact Mormon (gasp). From Beck's web site here, which ultimately leads to the story at Mormon Times, an anti-Mormon group posted a release to Christian News Wire calling Mormonism a cult, saying they were not Christian, and condemning Focus on the Family for not calling attention to the "differences" between Mormonism and Christianity, and therefore implying that Beck is a Christian and promoting the "false religion".

Focus is headquartered not far from here, and I have heard of Mormons who have been denied working there because of their insistence on their employees being Christian and their rejection of the Church of Jesus Christ of Latter-day Saints as a Christian church. (Might as well "out" myself here as well; I've heard these reports first-hand from members of my own congregation, being a Latter-day Saint myself.) So I suppose this can only be seen as "corrective" action on their part. It's still fairly disappointing, for apparently it reveals them as being more focused on their prejudice against a religion they don't agree with than the message being promoted.

I think the news wire release contains a couple of particularly damning points of these anti-Mormons that I found particularly interesting, in the one paragraph in which they actually reference Mr. Beck.

While Glenn's social views are compatible with many Christian views, his beliefs in Mormonism are not. Clearly, Mormonism is a cult. The CitizenLink story does not mention Beck's Mormon faith, however, the story makes it look as if Beck is a Christian who believes in the essential doctrines of the faith.

I underlined the things that stood out to me. Why do I find these parts so interesting? Well, first off, they fail to take into account that these social views are influenced by the very religion they're attempting to discredit. Likewise, if the story accurately reported on Beck's views (at least as presented in the particular book), and the results of the story are a set of views that "look like the essential doctrines of the faith", well, then, it stands to reason that Beck's beliefs are comparable to "the essential doctrines of the faith".

Are Mormons Christian? We steadfastly believe so. The name of the church — The Church of Jesus Christ of Latter-day Saints — directly names Jesus Christ, and we study the Old and New Testaments as sacred books of scripture. The subtitle of the "controversial" book of scripture, the Book of Mormon, is "Another Testament of Jesus Christ". Our weekly sacrament service, as the name implies, centers around the partaking of the sacrament, in memory of the Savior and his sacrifice for us in body and blood. We pray in the name of Jesus Christ. "And we talk of Christ, we rejoice in Christ, we preach of Christ, we prophesy of Christ, and we write according to our prophecies, that our children may know to what source they may look for a remission of their sins." So from a very simple definition of Christian — a disciple of Jesus Christ — we certainly seem to pass. But for a more scholarly discussion and research, there exists The Foundation for Apologetic Information and Research, which has collected several articles, talks, and responses to the "you're not Christian" accusation.

In the meantime, I'll continue to follow Christ according to the dictates of my own conscious, love my neighbor, be honest and true to my fellow men, and do my best to be a good husband and a father. If someone thinks that makes me or the church that teaches these principles un-Christian, despite evidences to the contrary, I suppose that's the price of discipleship, but in the end, I'll let God be my judge.

I do have to wonder how Focus on the Family managed to promote this book in the first place. From what I can tell, it didn't seem like Glenn Beck had been hiding his religious affiliation before now, so a very simple bit of fact-checking by Focus's PR department would've revealed this "inconvenient truth" well in advance. Perhaps it was a moment of weakness where they were focused more on the message than the specific religion of the author.

2008-12-19

Don't miss it 'til it's gone

When I was growing up, "humidity" was one of those things that was considered an undesirable thing. It made heat hotter and cold colder. It turned days that were just "warm" into miserable, muggy, don't-want-to-move days.

When I first moved to Denver, one of the things I enjoyed was the lack of humidity in this essentially desert climate. Hot summer days were bearable with just a fan. Opening a window was a viable option. Clothes could actually drip-dry. Even my naturally oily and acne-ridden skin started to clear up for the first time in my life.

When my dad got us a deal on a new furnace for our home (he was working in the industry at the time, so it was a good time to buy), I was somewhat bemused as to the existance of the option of a "whole-house humidifier". Why on earth would you want to add humidity to your house? My wife, on the other hand, a Utah native (where they also have a fairly dry climate) and owner of naturally dry skin, was very excited by this attachment, though.

After a couple seasons, I've gotten to understand this concept. The winter can get very dry, especially with the heater running as much as it does to keep the interior of the house above freezing. The extremely dry air ends up being very uncomfortable — it feels like you're living in a desert. Plus, there's an awful lot of static electricity that builds up in everything. The humidifier helps to make it more comfortable. It also makes it feel a little warmer, and it has the nice side effect of lowering static potential.

This winter has been especially bad. The power outlet attached to the furnace is dead. This outlet is powered by the furnace, so that it's on when the fan is on and off when it's off. So the humidifier hasn't had any power. I hadn't made getting that repaired a priority.

Then I noticed the problems. First, my shoulders would itch terribly. Yes, I, the one with the oily skin, had to start putting greasy gel on my shoulders to moisturize them after my shower in the morning. Then, my throat felt sore, the dry, parched sore of eating sand for two weeks. No matter how much water I drank, it always felt dry, and I would wake up in the morning feeling like it was on fire.

Then my oldest son started having the same throat issues. And my youngest was having trouble breathing at night. My wife broke out the portable cool mist humidifier, and that helped the toddler immediately.

That pretty much decided my course of action. Last night, when I got home from work, I ran an extension cord from a working power outlet to the humidifier. Since we run the fan full-time, it doesn't need to switch on and off, so that wasn't a concern. (That's a trick my dad taught me — if you set the "Fan" switch on your thermostat from "Auto" to "On", it runs the fan continuously instead of just when the heater or A/C is running. This keeps the air in the house circulating and at an even temperature, so you don't have the upstairs at 75° and the main floor at 65° and the furnace still burning fuel because the thermostat set at 70° is on the main floor. You do have to clean the air filter more often, but ours are the metal kind you vacuum out and reuse instead of disposable.)

I then had to run to Home Depot to get a new pad for the humidifier, since the old one from last year was scaly and wouldn't hold water (they're only $12 and typically last a winter season). Switched it on and set the humidity level to 20% (the markings have a recommended level based on outside temperature, but I've found that a constant 20% works ok, even if it means the windows occasionally show a layer of condensation on the really really cold days), checked for leaks, and closed it up.

Already, I can tell a difference. I woke up this morning and my throat didn't feel like it was full of sand.

Still, if you had told me a decade ago, before I had moved to Denver, that I would be voluntarily adding humidity to my own home, I would've laughed in your face.

Interesting side note: before we got air conditioning, we would cool our home with evaporative cooling fans. They actually work on the same general principle as the humidifier — a pump pumps water into a pad, and a fan blows across it. The cooling comes from the water evaporating. They actually work quite well in this climate, where water actually evaporates. I hadn't ever seen them before, which isn't surprising, since I had lived in places where it was more common to see water spontaneously condense out of the oversaturated air than evaporate into it.

2008-12-17

I CAN HAS LOLCODE?

One of the guys in my office showed me a list of "If Programming Languages were Religions". I'm sure I had seen it before, years ago, but it had been updated to include some more recent languages. It was pretty good (I was even able to chuckle at the inclusion of my own religion in there, whose reference was surprisingly tasteful).

One that took us both by surprise was "LOLCODE". I forget to what religion it was compared, but we had to look it up, to see if it was as bad as it sounded.

It is.

Observe the following code samples, starting with, of course, the ubiquitous "Hello World":

HAI
CAN HAS STDIO?
VISIBLE "HAI WORLD!"
KTHXBYE
HAI
CAN HAS STDIO?
PLZ OPEN FILE "LOLCATS.TXT"?
   AWSUM THX
      VISIBLE FILE
   O NOES
      INVISIBLE "ERROR!"
KTHXBYE
HAI
CAN HAS STDIO?
I HAS A VAR
GIMMEH VAR
IZ VAR BIGGER THAN 10?
   YARLY
      BTW this is true
      VISIBLE "BIG NUMBER!"
   NOWAI
      BTW this is false
      VISIBLE "LITTLE NUMBER!"
   KTHX
KTHXBYE

You can read more about it at LOLCODE.COM. Or don't. ;)

School Zones are for Losers

I drive the speed limit. When I see a speed limit sign, I moderate my speed to that number, and I set my cruise control. It's not out of any sense of moral superiority (although I will admit such thoughts do cross my mind when someone starts riding my bumper in an effort to push me above the legal limit); it's simply because I've received two speeding tickets in my lifetime, and I've decided that is plenty. Even if the chances of being pulled over for going a mile or two or five over the posted limit are remote, I've just decided it's not worth any added stress.

Does that mean I sometimes get to my destination later than someone else who might push the pedal down a little further? Sure. I've seen plenty of people speed by me and get rewarded for their transgression by getting through a street light that turns red after they pass but before I do. I've also seen plenty of people speed by me and get caught by street lights or traffic and end up no further ahead for their efforts.

Some people seem to take offense at being forced to follow the speed limit, though. Aside from the aforementioned tailgater who will follow dangerously close when I'm traveling the speed limit (usually when the limit drops or, for some reason, is posted slower than what one would think is necessary for a particular road), is this situation that I encounter each morning:

Traveling left to right (in this picture), I enter a school zone, which at the time of day is almost always active (lights flashing). I approach this intersection after making a left turn on a light from another main street, and it seems the lights are timed such that, after making that left turn and traveling to this point, I nearly always am stopped at this red light (often behind a long line of cars — there are probably about 10 car lengths between the start of the school zone and the light). Shortly after the intersection (just a few yards) is a rather large "Speed Limit 40" sign — however, this is not the end of the school zone, as evidenced by the (much smaller) "End School Zone" several yards beyond it (and the corresponding "Begin School Zone" for the traffic in the other direction at the same point). I have to wonder if the large "Speed Limit 40" sign was placed there with the intent to confuse people and entice them to accelerate to 40mph early — but that's the conspiracy theorist in me thinking.

As I approach the 25mph blinking school zone sign, slowing down is not usually a problem, as, as I've noted, there is usually a long line of stopped cars waiting for the light. Even if there are no cars or the light is green, I can typically slow to 25 without incident, although people in the left lane rarely slow completely to that speed. (I'm always in the right lane, as at the next intersection beyond this, I need to make a right, usually as well as a long line of people that would make trying to push in from the left lane difficult [but not beyond what some people will do to try and save a few seconds].)

What is more common is, after being stopped by the red light, when the light turns green, people will "forget" that they're in a school zone and begin accelerating. I'll get up to 25 and set my cruise control, as people in front pull ahead and people on my left pass me by.

What happens here more often than not is the person behind me will ride my bumper for a while, usually about halfway between the "Speed Limit 40" sign and the "End School Zone" sign. They will then lose patience and speed around me. If they've waited too long (i.e. I've reached the "End School Zone" and started accelerating to 40 myself), they will then slam on the gas to get around me.

And what do they get for their efforts? Well, I've yet to see a cop there in this, my third year of driving this route in the morning, so not even the chance of a ticket. But it does put them in front of me (although pulling away isn't possible — remember the line of people turning right at the next intersection ahead that I mentioned earlier?), and I guess that's all that matters. *sigh*

2008-12-06

Bandwidth for November

Another month, another bandwidth analysis.

The total bandwidth for November was 23,648MB down, 3,843MB up, 27,492MB total. The total bandwidth consumed for November was actually less than that for October by nearly 11GB.

This actually surprised me quite a bit. With the extremely graphic-heavy redesign of the Xbox dashboard, and with what I thought was a lot of videos and demos downloaded over the month, I would have expected a lot more usage. I even watched a couple episodes of South Park streamed from their web site. Sure, I haven't started downloading motion pictures yet, but I haven't exactly been conservative with my internet usage, either.

2008-12-05

PropertyInfo.PropertyType - is it Nullable?

Here's what I learned in school today.

I extended an object in our product with some nullable data types (something that, maddeningly, the previous programmers seemed to have an aversion to using, preferring instead to passing around "magic numbers" to represent null values — nice work, guys). Unfortunately, it bombed in one screen that used reflection to take objects and make datasets out of them.

The offending section of code looked like this:

PropertyInfo[] pInfo = myType.GetProperties();
for (int i = 0; i < pInfo.Length; i++) {
    DataColumn dCol = new DataColumn();
    dCol.ColumnName = pInfo[i].Name;
    dCol.DataType = pInfo[i].PropertyType;
    resultTable.Columns.Add(dCol);
}

The error thrown was that datasets don't support the "System.Nullable" type. Well, technically, they do, in that everything is nullable in a dataset, but that's beside the point. The solution is, I need, when building this dataset, to see if the type is Nullable, and if so, use the underlying type instead. No problem, right?

Not if you happen upon this post by the user "OregonGhost" on StackOverflow.com. He may not have invented the solution, I don't know; I just know that after searching for a bit, his post was the first answer I actually found to my question.

My code now looks like this:

PropertyInfo[] pInfo = myType.GetProperties();
for (int i = 0; i < pInfo.Length; i++) {
    DataColumn dCol = new DataColumn();
    dCol.ColumnName = pInfo[i].Name;
    Type dataType = pInfo[i].PropertyType;
    if (dataType.IsGenericType && dataType.GetGenericTypeDefinition() == typeof(System.Nullable<>)) {
        dataType = System.Nullable.GetUnderlyingType(dataType);
    }
    dCol.DataType = dataType;
    resultTable.Columns.Add(dCol);
}

And it works.

2008-12-02

Try...Catch in WinForms Main() method not Catching

Had a really bizarre and annoying error. I had a .Net WinForms app that started with a code block like this:

[STAThread]
static void Main() {
   try {
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      Application.Run(new MDIFormMain());
   } catch (Exception ex) {
      using (FormShowException showException = new FormShowException()) {
         showException.Display(ex);
      }
      Application.Restart();
   }
}

The only problem was, after one exception caused a restart (which had a side-effect of detaching the debugger), every other exception would throw a standard .Net "unhandled exception" box. Huh?

The right combination of Google search terms finally brought me to this page. Yes, apparently the above construct is fine running in a debugger, but not so much in stand-alone.

The solution, as described on the referenced page, is instead of using try...catch, bind to the Application.ThreadException event (which works both with and without a debugger attached), like so:

[STAThread]
static void Main() {
   Application.EnableVisualStyles();
   Application.SetCompatibleTextRenderingDefault(false);
   Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
   Application.Run(new MDIFormMain());
}
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) {
   using (FormShowException showException = new FormShowException()) {
      showException.Display(e.Exception);
   }
   Application.Restart();
}

Very simple fix for a very aggravating little problem. Thank you, Craig Andera.

2008-11-30

Did Thomas's mouth just move?

I finally got around to replacing the network cable on my wife's MythTV box, and it is back to recording TV shows for the kids again. I started up a new recording of Thomas the Tank Engine for the toddler, and I had to do a double-take when I saw his face actually move when he spoke.

If you're not familiar with the show, it's done with model trains that have faces. The faces change from scene to scene, but never "on-camera". The only thing that you ever saw move was the eyes, which could shift (or spin on some comical occasions). The faces were very expressive, but they were always static plates that would be interchanged when the camera cut away.

Well, no more. It appeared that the faces were now animated, although the rest of the show did appear to be the same model sets. A quick google did seem to confirm this guess, that as of this season, the face plates in filming were replaced with a target that a computer used to overlay with a CGI face. The effect is actually pretty well done; to me, the face does indeed look like it is part of the train.

Oh, and the people, which were before just wooden models, are now completely CGI. They still have the same look as their wooden model counterparts, but now they can move around, although they are animated to be almost robotic — probably to keep the impression of their wooden heritage?

Of course, the internet being what it is, as I was googling, I came across the melodramatic reaction that they've "ruined" Thomas the Tank Engine. I dunno, my kids (after getting over their initial shock of first seeing Thomas "blink" and then actually "talk") thought it was pretty cool.

I'm still a little undecided. Not that I spend a ton of time analyzing Thomas, but it is getting watched a bit more often now that our toddler has decided he likes watching "woo-woo" (train whistle, although the "word" also applies to cars) almost as much as he likes "Wawwy" (that's "Larry" from Veggie Tales). It's definitely different.

What does concern me a bit is that the press release indicates that while the faces are CGI this season, next season the entire show will be CGI. Because they use models now, it has that "model railroad" feel. Going all CGI would make it possible for them to completely change the look and feel of the show to however they want. Hopefully, they won't, because I think that's part of the show's charm.

I can definitely see, though, how it might be almost a little sad to think that there aren't actual model trains behind the show anymore. I grew up with model trains. But I also am a computer geek, and I can understand why they would want to move to using computers to produce their show. I imagine their models need a lot of maintenance, and creating a new character or even a facial expression is a costly amount of work, involving real, physical materials.

But they've always done it so well. Hopefully they don't end up trivializing it.

The press release also indicates they're moving the show Bob the Builder from stop-motion to CGI. I'm surprised they didn't do that sooner. I can't imagine how much time and energy and patience must go into making a stop-motion video.

2008-11-16

Don't say that word!

Religious discussions (particularly on the internet) rarely end well. No matter what forum, someone will bring up the ways religion has been perverted to propagate fraud for someone's financial gain, or how many people have died because of arguments that have led to violence that have led to wars over religious differences, or some other list of atrocities. And, nearly always, someone will posit that religion itself is the cause of those travesties, arguing they would not have happened if religion had not existed, and therefore, the world would be a much better place, and indeed would have been a much better place for all of history, if religion didn't exist.

It's a hurtful thing to say to someone of faith, that the world would be a better place without something that you believe to be important. I don't think it's necessarily said with the intent to be hurtful. It's just an expression of their opinion.

Because opinions differ to such a degree, however, it's considered "conventional wisdom" that, to avoid hurt feelings, one simply does not discuss religion.

I've thought about this, though, and something occurs to me. If I were Satan, and I wanted to stop people from drawing closer to God, it seems that one very effective way to do this would be to stop people from talking about Him. I think that spreading it around that it was somehow "impolite" to talk about religion might be a good way to make people stop talking about it. In fact, it might have the added bonus of making people expect a religious discussion to be impolite before it even began, to make them less likely to respect another's point of view (even if they disagree with it) and more likely to use absolute statements that are hurtful and mean, perhaps without even realizing it.

So that means the only appropriate response is to talk about it.

The argument goes that religion is the cause of so much evil and horror in the world, leading to many of the wars in history. However, I look at our current government. It has ruled under a policy of not governing according to a religion. And yet, it has had plenty of opportunity to wage wars for different reasons. So to suggest that wars were caused by religion would also suggest that, without religion, the wars wouldn't exist. And yet, mankind seems to find plenty of reason to wage war outside of religion.

Some people point to the instances of people using religious influence to swindle people out of money for their own personal gain, or even violations of person. This, too, has plenty of evidences outside of religion to be considered a flaw of religion itself.

The very argument that religion should be thrown out based on these examples is flawed anyway. It is an extreme solution that focuses on the negatives of people misusing the tool. One could make the same argument with governments. Or public schools. Or armies. Or the Boy Scouts. Or the internet. Guns. Television. Oil. You name it; somebody has used it to hurt someone. Maybe even lots of people. Maybe started wars over it. And yet to say "it" is bad is just scapegoating at best.

I'm not sure why someone would say the world would be better off without religion. Maybe it's scapegoating. Maybe it's just that they don't like it and would rather not hear about it anymore (akin to me saying "The world would be better off without rap music," no matter how many people like it). Maybe it really is an attempt to say something so extreme and hurtful that it closes off any further conversation. It's hard to say, considering a statement like that does close the door to any meaningful dialog.

Which, unfortunately, is probably very pleasing to a certain enemy to all righteousness...

2008-11-12

A boycott of United Airlines

Greg Dean of Real Life Comics posted a rant today about some really insulting fleecing from United Airlines. I know this blog doesn't get a whole lot of traffic, but it's something that I think is important to note. This kind of behavior is just inexcusable.

I already avoid flying for the expense. Even when gas prices were at an all-time high this summer, I chose to drive my family out to California rather than battle the airlines and airports who have seemed out to make flying as inconvenient and expensive as possible. You can be sure I won't be flying United if I have anything to say about it.

2008-11-06

Calling a Web Service in a loop

Wow, does this ever suck.

Ok, so here's the problem. I have a service that takes an XML file, which contains a list of parts from another system, and I need to synchronize the list of parts with our system. In order to do this, the service loops through the list of parts, and for each one, it attempts to look up the part in our system. If it exists, it gets it, and updates its properties with data from the file. If it doesn't, it creates a new one, with properties from the file. It gathers all these creations/changes into a collection, and then saves the batch to the database.

Seems pretty straightforward, right? The catch is, the interface to our system is through an authenticated web service.

Well, gee, that's not so tough, right? After all, in .Net, you just create a reference to the web service, and it does most of the work for you, creating all the wrapper classes and so forth. And, most of the time, it's as simple as that.

The problem, though, is that in this sample data set, we had about 5,000 parts. For each part, a query had to be made to the web service: Give me this part. (It'll return either the part, if it exists, or a null, meaning it doesn't, and I have to create one.) And for some reason, after about 3800 or 3900 calls to the web service in rapid succession, it would just quit. "Unable to connect to web service." The inner exception revealed a little more detail: "Only one usage of each socket address (protocol/network address/port) is normally permitted."

Huh?

After considerable digging and googling, I finally unearthed this blog post by Durgaprasad Gorti, which reveals the problem. An authenticated call closes the connection, but the Windows TCP stack holds the socket in a "TIME_WAIT" state for four minutes by default before it can be reused. While he does offer a registry hack to tell Windows to cut that time shorter, I wanted to find a way to do it in code, so it's one less variable to keep track of on a client's machine.

Unfortunately, all of my experimentation proved fruitless. No matter how I played with the ServicePoint, trying to forcibly close it, setting its timeouts to minimum values, whatever, the sockets stayed open too long.

So much for trying to out-think the Microsoft guy.

His code-based solution, therefore, is the one I'm using. Unfortunately, it's not great in that it basically just delays the problem — by expanding the range of sockets it can use, instead of crashing in under 4,000 calls, the limit is raised to 60,000.

He gives the basics of how to implement it, but unfortunately he doesn't indicate where the code needed to go. Fortunately, I found another blog post, by Kamil Pakur, that gave me just the clue I needed. (Incidentally, he's trying to solve the same problem, but his solution — forcing the KeepAlive to false and the HTTP protocol version to 1.0 — didn't change anything in my scenario; it still crashed in under 4,000 calls. In fact, it would seem that KeepAlive=false, which is automatic in an authenticated scenario, is the source of the problem.)

So, here's what I did:

  1. Copied the "namespace" and "public partial class" lines from the auto-generated Reference.cs file representing my web service into a new code file.
  2. In that file, copied Gorti's public static IPEndPoint BindIPEndPointCallback method.
  3. Added to that file a protected static int m_LastBindPortUsed = 5001; line (which is used in the "BindIPEndPointCallback" method).
  4. Added a method to override the service's GetWebRequest event that set the ServicePoint.BindIPEndPointDelegate to the BindIPEndPointCallback method (the first line on Gorti's code block).

My entire class file looks a lot like this:

namespace ProjectName.ServiceName
{

 public partial class Service : System.Web.Services.Protocols.SoapHttpClientProtocol
 {
  protected override System.Net.WebRequest GetWebRequest(Uri uri) {
   System.Net.HttpWebRequest webRequest = (System.Net.HttpWebRequest)base.GetWebRequest(uri);
   webRequest.ServicePoint.BindIPEndPointDelegate = new System.Net.BindIPEndPoint(BindIPEndpointCallback);
   return webRequest;
  }
  //protected override System.Net.WebResponse GetWebResponse(System.Net.WebRequest request) {
  //    if (request is System.Net.HttpWebRequest) {
  //        System.Net.HttpWebRequest httpRequest = (System.Net.HttpWebRequest)request;
  //        System.Net.WebResponse response = base.GetWebResponse(httpRequest);
  //        httpRequest.ServicePoint.MaxIdleTime = 1;
  //        httpRequest.ServicePoint.ConnectionLeaseTimeout = 1;
  //        httpRequest.ServicePoint.CloseConnectionGroup(httpRequest.ServicePoint.ConnectionName);
  //        return response;
  //    } else
  //        return base.GetWebResponse(request);
  //}
  protected static int m_LastBindPortUsed = 5001;
  public static System.Net.IPEndPoint BindIPEndpointCallback(
   System.Net.ServicePoint servicePoint,
   System.Net.IPEndPoint remoteEndPoint,
   int retryCount) {
   int port = System.Threading.Interlocked.Increment(ref m_LastBindPortUsed);
   System.Threading.Interlocked.CompareExchange(ref m_LastBindPortUsed, 5001, 65534);
   if (remoteEndPoint.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) {
    return new System.Net.IPEndPoint(System.Net.IPAddress.Any, port);
   } else {
    return new System.Net.IPEndPoint(System.Net.IPAddress.IPv6Any, port);
   }
  }
 }
}

(I left in the code for the GetWebResponse override, just so you can see some of the things I tried to clear up the sockets. It's all commented out now, of course, because it, quite simply, just doesn't do a blasted thing.)

The service now completes the run on our test data. However, I'm still not comfortable with the solution. There is an upper limit to the amount of data that it can process at a time.

Maybe a better solution is to ship the file across to the web service and do the processing there. (It would certainly make for a cleaner interface, an actual web service that does tasks, instead of the glorified and bloated data access layer we have now.) But that, too, is a double-edged sword. Web services have limits on how much data can be shipped, plus timeouts on how long the client will wait for a response.

What really surprised me in researching this is how little information there was on this problem. I guess calling an authenticated web service in a loop isn't a common scenario. It was only when I googled the text of the inner exception that I found it, amongst a lot of results pointing to people actually opening a lot of TCP connections manually.

I did come across a few posts of people complaining about web services failing in a loop, but the responses (when there were any given) were nowhere near the actual solution (suggesting a timeout issue with the session or authentication cookies). Maybe this post will be of more help, since I tried to bring the problem and solution together.

2008-11-05

Cell-ing Out

This MSN Tech article asks the question, "Are all the extra features really necessary? Or should a phone just be a phone?"

An interesting stat mentioned is that "camera phones … outsold regular cell phones for the first time in 2007", but what it doesn't say is why. Last time I looked at cell phones (which must've been four or five years ago, as that's at least as long as I've had my current phone), you had to look hard to find one without a camera, whether you wanted one or not. It's almost like Microsoft bragging about how computers with Vista are outselling XP, when it's extremely difficult to find a computer with XP anymore.

Personally, I don't even use my phone for text messaging, let alone email; but that has more to do with cost than with preference for the feature. I would love to surf or instant message from my phone, or use it to play music. But a full-featured phone like that starts at over a hundred dollars, and a data plan would increase my monthly cell phone bill by close to 50% (just for my line, and if I got it, my wife would want it, too, thus doubling the cost). Even text messaging plans are getting expensive (as I've ranted about before).

I've used a Pocket PC for a time (before the battery stopped holding a charge), and I thought it was wonderfully convenient, even if it lacked connectivity. I think one with a built-in phone and Wi-Fi would be the cat's meow. But, it's just not a need, certainly not compared to not spending the extra money per month.

Makes me wonder about these people who do use the extra services — "the youth", the article says. Are they paying their own cell phone bills, or is it coming out of mommy and daddy's account?

The winds of "Change" stink

Well, media's darling boy has been elected president.

It's being said that this was a historic day, as it was the day when America finally elected a black man as president, thus proving that the color of your skin doesn't matter. (Looks to me more like the day we elected the wrong man president, chosen by the media months in advance, thus proving the content of your platform doesn't matter if you have a buzzword, a logo, and a catchy motto; but let's MoveOn, shall we?)

I don't think prejudice is out of the picture at all. To satisfy my own morbid curiosity, I snuck a peek at a certain online community I know of that is extremely left-leaning in its membership, just to see how hard they were patting each other on the back (and mentally compare it to the prophecies of doom and gloom of four and eight years ago).

Among the comments of smug satisfaction, I noticed one referring to "the new monkey in the White House". This post was followed by calls for moderation and censoring for such a racist statement.

What's very interesting, however, is that our current president, George Bush, has often been compared to a monkey. How many pictures have we seen with Bush's face side-by-side with faces of monkeys showing strikingly similar expressions? I know I've seen a few, probably had the same set in my email box a dozen times in the past eight years. However, to extend this same metaphor to president-elect Obama ("the new monkey" definitely alludes to there being an "old monkey") is now taboo because of the color of the man's skin.

This point was brought up in the forum. The administrative conclusion was that the initial comment would be allowed a pass, but a repeat comment would be considered malicious and subject to disciplinary action.

I predict we'll see a lot more of this during the next four years. Criticisms and jokes that would've brought cheers and howls of laughter levied against the Bush or Clinton presidencies will, when made against the Obama Administration, bring howls of protest and accusations of racism. Dis the president now, and you're not just unpatriotic, but a racist.

If this is used to shut down right-wing media outlets (at worst, or "merely" as a way to institute the "Fairness Doctrine"), it wouldn't surprise me.

2008-11-03

Bandwidth for October

Just to continue the analysis, bandwidth usage for October was 32,094MB down, 6,580MB up, 38,674MB total. Aside from the extra video watched one weekend earlier this month, there were a lot more demos to download from the Xbox Live Marketplace for my Xbox 360.

Still, the total bandwidth consumed was only 10GB larger than my September "baseline", and over 200GB shy of the cap.

Even the psychological effects of the cap are starting to wear off at this point.

I wonder if there's something I can torrent, to see what kind of effect that has on bandwidth.…

Morpheus, Grokster, Limewire and Kazaa!

Yep, I said some dirty words. Or at least according to MTV. Weird Al Yankovic, my most favoritest artist evar, mentions those file sharing sites (two of which don't even exist anymore) in his song "Don't Download This Song" (which he offered up for download upon release), but MTV refused to run the video with those names mentioned.

So, Yankovic obliged by censoring the video. But, he did so in the most obnoxious way possible, with very loud, irritating beeps. Why? In his words:

Instead of subtly removing or obscuring the words in the track, I made the creative decision to bleep them out as obnoxiously as possible, so that there would be no mistake I was being censored.

Techdirt reported on this here. They link to the New York Times article here, although I don't know if the Times will hide their article behind a paywall eventually (the major newspapers seem to be going back and forth on this idea), hence the Techdirt link.

I like Weird Al. :D And, he's a very nice guy in person, too, or so says my lucky brother who happened to meet him and was able to taunt me with this picture.

my brother and Weird Al

No, I'm not jealous. Why would I be jealous? Just because he happened to meet the one musician I happen to be a big fan of... :P

Sex on TV Increases Teen Pregnancy, Says Report

Just another reason why you shouldn't let TV raise your kids.

2008-10-30

Is this file open?

Coding problem of the day: I have a service (written in C# .Net) that monitors a folder for incoming files, and when a file appears, it needs to process it. At the moment, it is using a FileSystemWatcher object. I don't know if I'll continue to use that or not (it was written by someone else before I got here), as it doesn't guarantee any sequence of events, nor does it help if files exist before the service is launched. But that's beside the point.

The problem I discovered is, if the file is coming from another computer over a slow link (e.g. an FTP or other slow network transfer), the FileSystemWatcher will raise its Created event as soon as the file appears, but the file is not yet ready. (I simulated this by writing another program that slowly writes a very large file to the target directory, using a loop and a Thread.Sleep.)

The solution, like a lot of other things in programming, is a little convoluted, but it seems to work for the time being. The gist of it is, in the Created event handler, I first call a function that tries to open the file for exclusive read access. If the file is still open, this will fail.

Testing for this failure is the hard part. The exception that gets thrown is a fairly generic IOException, and while a "file in use" is one condition for which I want to stop and wait, there are other conditions that I would quite definitely not want to wait to magically resolve themselves. The MSDN doc on IOException lists several derived classes that, for example, I would rather treat as critical errors immediately, like PathTooLongException, DirectoryNotFoundException, FileNotFoundException…. If I waited on those, I have a feeling my code would be waiting a very long time.

So, here's my "is this file locked" function:

using System.IO;
using System.Threading;

/// <summary>
/// Makes sure a file is closed before attempting to use it
/// </summary>
/// <param name="fullFilePath"></param>
public void WaitForFileClose(string fullFilePath) {
 while (FileIsLocked(fullFilePath)) {
  Thread.Sleep(new TimeSpan(0, 0, 15));
 }
}

/// <summary>
/// Determines if a file is still locked by attempting to open it for unshared (exclusive) read access.
/// If an IO Exception occurs that includes the text "another process" in the message (i.e. "in use by
/// another process"), the file is assumed to be locked.  Any other exceptions are rethrown.
/// </summary>
/// <param name="fullFilePath"></param>
/// <returns>
/// true if the specific "another process" exception was found trying to open the file, false
/// if no error occurred.
/// </returns>
/// <remarks>
/// May not work on systems in other languages.  There is no specific "file locked" exception to
/// test for, and there are other exceptions that derive from IOException (like FileNotFoundException)
/// that should not be waited on.
/// </remarks>
private bool FileIsLocked(string fullFilePath) {
 try {
  using (FileStream fs = new FileStream(fullFilePath, FileMode.Open, FileAccess.Read, FileShare.None)) {
   fs.Close();
   return false;
  }
 } catch (IOException ioex) {
  if (ioex.Message.Contains("another process"))
   return true;
  else
   throw;
 } catch {
  throw;
 }
}

As I note in the comments, I'm concerned this might not work on other locales, since I'm specifically looking in the exception's message text for the string "another process". Unfortunately, I don't have a better way to determine what IOException got thrown. I set a breakpoint and tested it, and (at least in .Net 2.0 on Windows XP SP3), it was indeed throwing a base System.IO.IOException with that text in the message.

I'm open to any better ideas, though….

2008-10-28

The DMCA, 10 years later

The EFF is "celebrating" the 10th anniversary of the Digital Millennium Copyright Act with a report of the unintended consequences its use and abuse has had on research, trade, and civil liberties. It's a worthy read, even if they do leave out one of my favorites — that Sharpies were suddenly circumvention devices because they could be used to defeat CD copy protection*. :D

*Ok, no legal action was ever taken against Sharpies, or even web sites for describing the process as far as I know; but the fact that this joke popped up around the internet more than once just shows how ridiculous the whole thing is, and how easily it was recognized as such back in 2002.)

2008-10-27

If the MPAA Did Handbags

Continuing the theme I seem to have picked up lately, in linking to random articles I find interesting, was this one I saw via Techdirt. It's from the "Pure Purse Passion" site BagBunch.com, and it's an article that claims to, in its own words, "[show] the bad ethics, hypocrisy and stupidity of the companies behind our TV Shows, our documentaries, our movies, and our music." In short, what would happen if the handbag industry created an "HIAA" and adopted the same practices as the MPAA and RIAA? clicky

Granted, the analogy isn't perfect (and they admit as much in their opening statements). For starters, music these days as a digital good can be copied infinitely, with zero degradation, for essentially zero cost; whereas a handbag as a physical good would still require materials and labor.

Despite the flaws, I think it's a worthwhile article. By applying the *AAs' "logic" to a physical (and non-technical) context, perhaps it'll help make more people more aware of what is going on, instead of just being iTunes sheep who unknowingly lock themselves into whatever draconian DRM rules Apple throws at them.

2008-10-23

Biden's Bungles: A Blatant Bias

Wow. When the New York Post starts to report on media bias (and even Dan Rather is commenting about it), you know there are problems.

2008-10-21

Would the Last Honest Reporter Please Turn On the Lights?

Hear, hear!

How dare you obey the rules of the road

According to the Colorado Driver Handbook, which I just downloaded from the DMV website for confirmation, section 10.1a, if a traffic signal is malfunctioning or not operating, the intersection should be treated as a four-way stop. If the lights are on but flashing yellow, it is a warning of hazard, to slow and proceed with caution (but not "treat as a four-way stop").

For some reason, people in Colorado don't seem to understand these. When they're not completely ignoring them, they get these rules completely backwards.

Last week, I was driving home in the middle of the day to shuttle my wife to the auto shop, as we were down to one car while the minivan was having some maintenance (an $800 repair of the climate control system — ouch), when I noticed a stoplight was completely out. The road I was on was a six-lane divided road, and the intersection was with a small, two-lane road. A pickup was waiting on the cross street.

I slowed to a stop. A truck in the lane next to me blowed through the intersection, and I honked at him — which earned me an irritated honk from the truck behind me. I waited patiently as three more cars blew through the opposite direction before the pickup finally got his turn to go through the intersection, which, as you'll note in my first paragraph above, is legally a four-way stop at this point.

The next street light is also in a "non-standard" mode, but this one is blinking yellow. (The street I'm on has reduced to a two-lane road by this point.) Wouldn't you know it, traffic coming the other way is actually stopping at this blinking yellow light. I slow a bit, to make sure the car waiting on the cross street at his blinking red light doesn't try to pull out in front of me, and cautiously proceed through the intersection.

After I pick up my wife, we head back on the same road. I notice people are now treating the dead light like a four-way stop, but I believe this is due to the police car that has stopped beside the intersection, as a cop is donning an orange vest to direct traffic.

Slow down, so I can cut you off!

My friend, the "Top Hat Rabbit", just made a blog post that reminded me of a driving incident. This happened many years ago, but I still remember it clearly.

I was driving home from work one day, and to avoid traffic, I cut through a neighborhood, taking a route I had taken many times before. At one point, I came around a curve, where a side street joins the main road I was on. A couple guys in a little red convertible were at the stop sign. The driver was talking to his passenger, not paying any attention, and started to pull out in front of me as I came by. To avoid getting hit, I hit the gas and swerve around him. My sunroof was open, so I heard him yell, "Slow down, a**hole!"

Of course, he couldn't let this go. He had to prove to his friend how big a man he was. Up at the street light exiting the neighborhood, I waited to turn left, and he pulled up beside me in the right turn lane, arm and middle finger extended. When I refused to so much as glance in his direction, he tried to get my attention. "Hey a**hole!" he called. Still no reaction. (Nice language to be shouting in a neighborhood, I thought.)

He inched his car forward, I suppose so he could get a look at my front license plate, which I guess he wrote down, because he then started waving a piece of paper in the air, calling, "A**hole!!!"

The light turned green. I finally looked over at him, blew him a kiss, and drove off.

Hope I didn't make his boyfriend jealous.

2008-10-07

SQL 2005 getting too smart?

We had a bug with one of our clients that had just upgraded from SQL Server 2000 to 2005. In the process, we were deploying some new application features to them, and one was crashing. This same feature was working just fine for other clients (and in-house, of course), so we were puzzled.

The problem is actually from something I used to wish SQL Server was smart enough to figure out on its own for a long time. Namely, when you write a SQL statement such as this:

Select U.UnitId, U.UnitName, UT.UnitTypeName
From Unit U 
Inner Join UnitType UT On U.UnitTypeId = UT.UnitTypeId
Order By UnitTypeId

you will get an error to the tune of "Ambiguous column name 'UnitTypeId'", because (in this case) you reference it in the Order By clause but don't indicate which source table you want, since the same column name exists in both tables referenced in the From clause.

Logically, it doesn't matter which one, because you mandate in the From clause that both UnitTypeIds are equal, but SQL syntax dictates you must specify which one you want.

Despite seeing this many times, it's still not automatic that I'll specify the table in my Select and Order By clauses, so I still see this error a lot.

I hadn't seen it recently, but suddenly it popped up on this one client's database. Sure enough, I hadn't specified the table in the Order By clause again. Yet it was working fine on other clients' databases, and working fine internally.

Our QA guy managed to find the "SQL Compatibility Mode" option on the database. Because they had upgraded this database from a SQL 2000 database, it was still in "SQL 2000" mode. Because of this, it was revealing the error in my SQL that was going through undetected on servers running in native SQL 2005 mode. He flipped the switch to "SQL 2005", and it let my bug go through.

Needless to say, my local database is now in the more restrictive "SQL 2000" mode, so hopefully I can catch more bugs before they're revealed by environment. It should also help if we ever decide to migrate to other database servers, such as MySQL.

Impact of video on bandwidth

Continuing the saga of bandwidth, I had an interesting data point come up this weekend. My church has a general conference twice a year, where we have an opportunity to hear from the leadership of the church. This is streamed live over the internet in fairly decent quality video (in my completely unscientific opinion, it looked just as good as any standard TV show might look on a 12" laptop computer screen).

The conference spans the entire weekend, with two 2-hour sessions broadcast each on Saturday and Sunday. At the end of the second Sunday session, the thought suddenly occurred to me; I wondered how much bandwidth I was using up.

Fortunately, this is something I can check without too much difficulty. A quick call to vnstat reveals the following statistics:

DayInOutTotal
Saturday4.68 GB206.82 MB4.88 GB
Sunday3.98 GB123.33 MB4.10 GB

Saturday will of course include some extra bytes for online gaming, which doesn't happen on Sunday.

Interesting thing about those stats: if that happened every day, watching four hours of streaming video, I still wouldn't hit the cap. I'd come far short of it, in fact.

2008-10-01

Bandwidth - the Baseline

September is now over, so I now have my baseline for monitoring my bandwidth, to see how I fare against the bandwidth cap. Total data used for the month of September: 22.36GB down, 5.44GB up, 27.80GB total.

September was a bit of an odd month, though. For about a week and a half, I was without an Xbox 360; and for almost the whole month, my wife was using my laptop while we tried to get hers repaired (the wireless network card was fried). However, even with those odd variables, there are some worthwhile data points.

First off, there is only one day in the entire month of September that shows a total over 2GB (2.24GB used on 1 Sep) — every other day is under 2GB, and only 5 days total are over a gig and a half, with an additional 7 days between the 1G and 1.5GB marks.

There is a definite dip in usage around the time my 360 died, so its effects are noticeable. There's also a spike on the 13th that would represent when I got my new 360 and proceeded to play the heck out of it all day. Another sweep up starts on the 23th, which could represent when I and three others decided to make a speed run at a Halo campaign level for a competition that Friday night (we practiced every night that week). The extra boost starting on the 25th may come from my wife finally getting her laptop back from HP and having to download updates and reinstall software.

Even with the up-ticks, there's still not a lot of bandwidth being used. If you take the heaviest of the days that should represent things getting "back to normal", the 25th, and multiplied that by the entire month, it's only 50GB, or about a fifth of the cap.

But how could that change? If I wanted to ditch the $40+/month "digital voice" service from Comcast and shop around for other VOIP options, I'd be looking at an increase in usage just for using my phone. If I wanted to take advantage of the upcoming Netflix integration with the Xbox 360, that would cause a huge increase in bandwidth, depending on how many movies I tried to watch. For that matter, the "New Xbox Experience" is creating a new paradigm for interacting with friends (i.e. they're ripping off "Miis"); will this have an impact on how much bandwidth is used just sitting in the dashboard, while my friends' avatars are displayed on my console?

I think I've come to the conclusion that it's safe not to worry yet, but it still makes me nervous about trying new and potentially high-bandwidth-eating applications or services. And I still think that's just the way Comcast likes it.

2008-09-16

Zune Software Revisited

The Zune software player has gone through an update or two since I last checked it out at the beginning of the year, so I thought I'd give it another look. Unfortunately, I'm still not impressed.

The player is responding to the media keys on my keyboard, so I can play, pause, and skip quickly. It also does the neat (and useless, but I like it, so there) trick of updating your Windows Messenger status line. And it hasn't caused my computer to blue screen (yet).

However, when I set up the software, plugged in my Sansa media player, and told Zune to watch the E:\MYMUSIC folder, it did absolutely nothing. I thought it was supposed to automatically add the files to the library? I tried dragging and dropping the files from Explorer to Zune, but still nothing happened. It wasn't until I selected the files in Explorer, right-clicked, and said "Play with Zune" that the Zune player would play the files. It still didn't add them to the library, but it did at least create a playlist of all the files.

There are still features that are just missing. Automatic volume leveling, quiet mode, a graphic equalizer, crossfading, a mini-mode... These are all features that I can remember being built-in to programs for years, and are, in fact, built-in to Windows Media Player.

Now, when I first started writing this post, it was about a week ago, and as I was checking the Zune.net forums to see if I was the only one to complain about this, I noticed that Zune 3.0 was to be released very shortly. New features, including crossfading, were coming. So I decided to wait until now to install the new version and finish this post.

Unfortunately, if there are any new features, they seem to be reserved for the Zune device itself, as the desktop player is almost entirely unchanged.

I'm not suggesting the Zune team reinvent the wheel. There's no point. What they should be doing is making this a WMP plug-in. Not only would I, as a user, be able to take advantage of the features that already exist in WMP, but I could also download and/or purchase other plug-ins for WMP that enhance my music however I like, and I'd still have the "Zune Social" connection.

I've posted this suggestion in the Zune wishlist forum, and basically the response I got back was, "The Zune team couldn't do everything they wanted with the software within the confines of a WMP plug-in." To which I say, "Do they have to?" Keep their software with whatever it does as a separate app. Heck, all I really want is a plug-in for WMP that updates my Zune card with my plays, but let me use WMP as my player.

I suppose what I'm asking is not entirely reasonable. The Zune Social is meant for people who own Zunes and is meant to interact with Zunes. I don't expect any sort of DirectX plug-in that adds the PC games I play to my Xbox Gamercard, as that is meant for people who own Xboxes and is meant to interact with Xboxes. Still, it seems almost cruel to have a taste of this "social experience" thing and have it be so crippled when it could be solved by the simplest little piece of code.

*sigh* Maybe I'll check on it again in another nine months...

2008-09-15

Best Buy Store 694 Customer Service

I've had to deal with the customer service desk at Best Buy Store #694 in SE Aurora, CO on four occasions since it opened (about 3 years ago). I have to say, I'm very happy with them.

The first time was when I had to exchange an Xbox 360 that was giving me the infamous "red ring of death". Since this was before Microsoft had owned up to their hardware failures and started fixing problems after 3 months, I decided to invoke the Best Buy product replacement plan. Took the box to the desk, they brought me a new one. I asked if I could keep my old hard drive, and they said it would be no problem. (It was a common request by this point.) They helped me unpack the new console and swap hard drives. Aside from time spent in line, I was in and out in probably 10 minutes.

The second time, I had ordered a game from BestBuy.com, and when it was finally delivered (UPS mis-routed it first, and then severe snowstorms prevented its final delivery another week), it ended up being the wrong game. I brought it to the customer service desk, and the gal working there explained that Best Buy stores and BestBuy.com were separate entities, so they were limited to what they could do. They checked to see if they had the game I wanted in stock, but they didn't (which was why I ordered online in the first place), so she said I'd have to deal with BestBuy.com's customer support. She then picked up the phone and called BestBuy.com's customer support, explained the situation, and turned the phone over to me so I could finish the details. She could've very easily just told me to go home and call them, but the fact that she took an interest in getting me in touch with whom I needed to talk to, to get my issue resolved, really went a long way to winning my respect.

The third issue was when we had just picked up a business points membership or some such promotion. We bought a couple items, and we were supposed to get a certain amount discounted. The register refused to give us the appropriate discount, and the cashier wasn't able to do much about it. (Not surprising. I've been a cashier, albeit in a grocery store, and for better or worse, you're given very little control.) She directed us to customer service. We took our receipt over, and the gal there worked with the register for a bit. Then fought with it. She wasn't able to get it to give us the precise amount of credit back on our credit card, but she figured out a way to coerce the register to give us a discount that resulted in a slightly higher amount (like a buck and a half), so she went with that and called it good. All the while, she had a very positive attitude about helping, even when the system was obviously frustrating.

And then comes the most recent experience. I figured this one might be the most... interesting. Once again, I had an Xbox 360 that needed replacing. Because the hard drive sizes had been increased, I figured this time, I didn't want to just keep my old hard drive; I'd want to transfer my data from the old drive to the new. I'd done the research to see what it would take and invoked the GeezerGamers.com network to obtain a hard drive transfer kit that Microsoft provides for this purpose. I entered the store, armed with the transfer kit and some fresh Krispy Kreme donuts for bribery.

Once I had selected my replacement system (a 360 Elite, which, since the Best Buy replacement plan is based on original purchase price and the console prices had dropped quite a bit, only cost me the price of a new replacement plan if I wanted it -- "You better believe it" was my reply to that), I explained what I wanted to do. I explained that I had the transfer kit with me, and donuts. She politely declined the donuts (saying that, oddly enough, I was the third person to offer her donuts that day) and asked what I would need. Just a TV, and I made a point of saying it would probably take an hour. (I figured it was only fair that she knew exactly what I was asking.) As it so happened, the Geek Squad desk around the corner had a TV monitor that they rarely use, and they were happy to let me use it. They couldn't assist with the actual transfer (a policy that comes from wanting to avoid getting into legal tangles transferring songs between MP3 players), which I understood completely. About an hour later, I handed her the old hard drive, thanked her again, again offered her donuts (which she again politely declined), and walked out with my shiny new Elite.

So I just have to give "mad props" to this store's customer service team. They've really helped me out. I'm not saying I'd expect them to break rules for me, though — before helping me, the gal (who is likely a customer service manager, which is probably why she was able to get me set up on a TV for an hour) had to be called over to explain to someone else that they can't price-match another store's bundle deal. But as far as helping me out with issues, they've been nice, friendly, willing to help, and willing to do what it takes to resolve whatever problem I've had.

2008-09-04

I may be slow, but I'm FIRST!

I've been meaning to add this to my driving posts for a while. I just read an interesting article on Ars Technica, titled Selfish driving causes everyone to pay the Price of Anarchy, which is a pretty interesting discussion about an upcoming research article on traffic patterns and how, when each person is driving according to their own personal best interests, the entire group (including themselves) suffer.

It doesn't really have anything to do with this particular post, but it did remind me of one behavior I've observed and thought worth mentioning.

Many times, I've approached a stop light on a multi-lane road, where my lane is clear, but adjacent lanes have multiple people waiting at the light. Since I tend to accelerate fairly quickly "off the block", I like seeing this, because it means I'll get to reach cruising speed much faster. (One theory is, for better gas mileage, one should accelerate more slowly; however, in a hybrid car such as I drive, the theory is reversed, as faster acceleration is supposed to induce more assistance from the electric motor and actually decrease gas consumption.)

However, quite often, as I'm approaching the stop light, someone from an adjacent lane will pull out in front of me and take the "pole position". (If I'm lucky, it'll happen far enough in advance that I won't have to slam on my brakes to avoid a collision.) There are two possible, logical reasons for this behavior: (1) this person likes to accelerate quickly, and therefore wants to be where no one is in front of him, or (2) they need to make a turn soon and are changing lanes while they have a chance. However, way, way too often, this person will end up accelerating more slowly than the person they just got out from behind, and keep going straight for quite some time (i.e. several miles), even moving back into the lane they just left.

So what was the point of changing lanes? A better view of cross traffic before the light changed? A desire to witness the changing of the light for one's self? Mistrust that the car in front of them would actually be able to go once the light changed? Or that irrational fear of someone passing them, that same one that causes people in the right lane on the interstate to suddenly accelerate as I approach alongside in the left lane (note that I habitually drive with cruise control, so I'm reasonably certain my speed is constant)?

Or maybe this pathological desire to be "FIRST!" extends beyond internet comment boards?