Friday, May 6, 2011

Fail Loop


This gem is part of a code (C#) example that we got from a vendor recently. This exact same pattern appears multiple times in the example.

It stands out because it does manage work correctly...


using (FileStream rdr = new FileStream(contentInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{                    {
    index = 1;
    while (true)
    {
        long offset = (index - 1) * chunkSize;
        long remaining = contentInfo.Length - offset;
        if (remaining < 1) break; // Stop processing, at the end of the file

        // stuff that doesn't ever touch the index variable 

        index++;
    }
}

Friday, March 11, 2011

Gasoline Boycotts - How much do big oil companies care?

Recently I've gotten a rash of Facebook event invites, emails, and other general online suggestions that I should participate in various gas boycotts. The proposal is that we all setup a a single day where no one in the country buys any gasoline at all.

Sadly, there is no single organizer for these protests, so there are literally hundreds of different groups advocating boycotts on different dates. But, aside from the logistical challenge, I'm still confused as to exactly how  people think this kind of boycott would achieve anything.

These groups either claim to want to "send a message" to the "big oil companies", or they claim that this will "hit them in their bottom-line". These groups are run by idiots.

How does not buying gas on one day matter to the "big oil companies"?

Have you actually thought about this at all? It isn't like I buy my gas straight from big oil... sure, the local gas station's signs have BP logos all over them, but BP doesn't actually own and operate those individual gas stations. It isn't like the money flows from my debit card straight into some big oil company's bank account.

Sure, the gas station owners would really notice, and they may even be inconvenienced slightly. But the gas stations aren't the ones that set your gasoline prices.  And gas stations don't pay their big oil suppliers on a daily basis either; they tend to pay their gasoline bills on a monthly or quarterly basis.

It really doesn't matter to the big oil company on which specific day any particular individual choses to pump gas into their little car.

And what message are you planning to send with this boycott? It isn't like people are advocating a day of not driving, so just as much gasoline would be used up that day anyway; boycott or not. The small fraction of people that would normally have chosen to buy their gas on boycott day would just have to fill up the tank a day earlier or later; but they'd need to buy exactly the same amount as they would have had there been no boycott at all.

Unless you actually reduced the actual usage of gasoline, it doesn't matter exactly when you buy the gas. But  even if you did manage to get everyone in the U.S. to stop using gasoline for one day the best you could achieve by a one day reduction in gasoline usage would be a 0.27% drop in oil company profits (and that, only if you make the false assumption that their profits only come from gasoline sales).

Let's put that in perspective...

Let's assume that we had boycotted, successfully, for one full day last year. And we further assume that during the boycott we also didn't use any gas either. And then we made the (blatantly false) assumption that all oil company profits come from U.S. gasoline sales.

How much would it matter to big oil?

Well, using the simplest math possible; such a boycott in 2010 would have reduced Exxon Mobile's bottom-line by around 67 million dollars. So yeah, Exxon would have only made 30.43 billion in profit, instead of the full 30.5 billion that they actually reported last year.

I'm sure big oil is just terrified of those gasoline boycotts and is slaving away right now trying to find some way to appease those disgruntled U.S. motorists.

Saturday, February 26, 2011

Review: TuneUp - Organizing My Music Library

If you are like me, you have a massive music collection with tens of thousands of amazing songs; all of which you purchased completely legally (of course). If your collection is like mine though, it is also an organizational catasterfuck... duplicates, mis-tagged songs, missing artwork, random file names, etc.

So, if you find yourself facing the daunting task of organizing a massive collection of music, then you should totally buy this shit from TuneUp Media. You managed to steal buy over 100 GB of music, so the least you can do is cough up $20-$30 so you can tag and organize your collection.

TuneUp is an add-on for Windows Media Player and iTunes (same app, works with either/both).

I had no luck getting it to work with Windows Media Player reliably, but I HATE WMP, so... no loss there really. As an add-on for iTunes though, it works really well.

I really don't like iTunes either, at least not as a daily-use media player, but for the task of organizing a large library I have been reasonably impressed with it's ability. There are better general tools, but when you add-on TuneUp to iTunes it goes from being merely a capable library manager, to being outright amazing!

To perform my tuning, I used this procedure:

  1. Clear everything from the iTunes library
  2. Set TuneUp to write a message to the comments of the songs it tags (so you can see in the library which files you've updated).
  3. Modify iTunes library details view to display the comments column 
  4. Copy all of your busted music collection into the "MyMusic" folder in windows
  5. Drag 5 folders from MyMusic (in windows explorer) and drop them into the iTunes library window
  6. Select the songs in iTunes, right-click, and choose "get info"; check the box for "comments" and save the changes  to remove any existing comments from the songs.
  7. Drag the files from the iTunes library and drop them into the TuneUp's "clean" window
  8. Let TuneUp do it's thing and locate the info for your songs, then save all the appropriate suggestions from TuneUp (this updates the tags, and syncs the changes back to iTunes)
  9. Make any manual changes you need using iTunes media library (it actually has decent mass-tagging features)
  10. Select the newly fixed files in iTunes, right-click, and choose "consolidate files". This copies the files to the iTunes media folder.
  11. Copy the fixed-up folders and files (in windows explorer) from the iTunes media folder to an external drive or some other destination folder where you want to keep the polished-up collection.    
  12. Select all files in the iTunes library and delete them; choose send to recycle bin. This gets iTunes ready for the next batch of files you want to sort out. 
  13. Repeat from step 5 for the remainder of your collection.

TuneUp isn't perfect, but it has access to a very nice range of online music databases, and it also performs a playback analysis of your music, so it doesn't rely just on the existing tags and file names to match the files to the online databases. Because it listens to the files and uses existing tags and filenames too; it is very good at tracking down the right CD info for you. But sometimes, you'll still need to manually manage parts of your collection. The nice thing about TuneUp is that it doesn't automatically write changes; it tells you what it came up with, then lets you decide if you want to save the changes back to the files.

TuneUp does other stuff too. It has features I personally don't care about such as locating concerts, suggesting similar music to what you are listening to, and even the obligatory social networking stuff. But for organizing a media library, it has more than earned the $30 I spent on the full license. The fact that it does other stuff might matter to you though; especially if you are debating the annual license ($20) vs. the full unlimited use license ($30).