Sunday, February 28, 2010

Pop quiz, hotshot!

These four combos are something really special. Anyone know what?

J♣ 55♠ 5 + 5♣
J 5♣ 5♠ 5 + 5
J♠ 5♣ 5 5 + 5♠
J 5♣ 5 5♠ + 5

Friday, February 26, 2010

Until we meet again...

This has been quite a turbulent week emotionally for my family. Yesterday was so amazing watching my new daughter through the ultrasound monitor. Her 20 week old body so full of life and vitality; learning of her gender - which will define so much of her identity. It feels so surreal having that joyous day sandwiched between the day of my grandpa Jim's passing, and today - the day of his funeral.

There are so many wonderful memories I have of my grandpa. Christmas parties at he and grandma's house every year. Many, many trips to spend an overnight with my brother and sister at their house in Grandview as kids. Me getting bludgeoned and battered at cribbage again, and again, and again and coming back for more. Being on the 'mens' team with him at a game of canasta when I wasn't old enough to ever have been considered a man. Some vacations together, lots of meals together, Christmas morning visits at our house, and one very panicked drive with him back to our house when my brother Nick gashed his head open.  Lots of memories - I can still hear his gravelly voice and his laugh if I close my eyes tight enough.

One of my most treasured memories is from our wedding when we did the longevity dance and Jim and Betty were the last ones on the floor - having been married a zillion years to my mere milliseconds - always in love.

I'm pretty sure he never really knew he had another great-grandchild on the way - his mind was never quite the same after the heart surgery. But his heart was there - always a kind word and a gentle, loving spirit toward everyone he met. His legacy will live forever. And though we will morn as a family together today, we will not mourn as those who have no hope, for we know our goodbye is not the end.

Well done good and faithful servant.  Welcome home.

Thursday, February 25, 2010

Saturday, February 13, 2010

Uniformly random


Every software developer should recognize the above string as a GUID - pronounced goo-id, or gwid, it's a globally unique identifier.  It is a pseduo-random sequence that has 2128 or 3.4 x 1038 possible values.  If every computer in the world generated one GUID a second from the dawn of time until now, that GUID you see above theoretically would still never occur again.  A GUID consists of 32 characters with values from 0-F, or 0-15 for those who prefer to count in base 10.

One of the best properties of a GUID is that it's uniformly random, which means that each and every one of the 32 characters in the sequence has an equal chance of being any of the 16 possible values.  This is really handy, and has some nice applications when it comes to data analysis.  If you assign each data element a GUID and sort based on that GUID, you'll get a random sampling of data.

Specifically, lets say you have a SQL Server database table and you'd like to get a random sample of 1000 records, this query will get you there:

select top 1000
order by

Really neat.  Well, if you're a data geek it is at least...

Friday, February 12, 2010


I had a 'podcast day' - a day where I'm sick of listening to music while I work and just want to listen to some interesting talk radio. Unfortunately, my cube is in a dead zone and I only get the radio stations with a really powerful signal, so I've gotten into some really good podcasts - one of which is Radio Lab. Today I listened to an episode from October 2009 called Numbers, followed by one called Stochasticity. I was completely fascinated by both.

It's worth a listen, but the Numbers episode talked about  how childhood development as it pertains to an understanding of numbers, some interesting mathematicians, and Benford's law.  I'd never heard of Benford's law before, but since it's tax time, it seems especially relevant.

The story explained on the Radio Lab episode, which seems to have been sourced directly from this link, is that in 1938 Dr. Benford noticed that a book of logarithm tables was much more heavily worn in the pages with numbers stating with the digit "1" than the other pages.  From this, he began to do some research and discovered that the first digits of a large series of random numbers is naturally weighted in a logritmic scale, with the number 1 occurring more frequently than any other number.  This has amazing applications, including being able to detect fraud on tax returns - if the numbers on your tax return don't follow Benford's law, it's a trigger the IRS could use to investigate more or even perform an audit.

The main take-away from the Stochasticity episode is that people are not very good at understanding randomness - we are people of order.  One of the examples they used was a test where they had two groups of people - one who flipped coins 100 times and recorded the results, and the other who just pretended to flip a coin 100 times and recorded the faked heads/tails sequence.  The fakers were obvious because when the were trying to fake randomness, they wouldn't record 7+ heads or tails in a row.  It just doesn't seem random enough, but the team that really flipped the coin would invariably have those long sequences.

Another example they used is the concept of an athlete being on-fire - a basketball player who gets on a roll and hits 3 in a row starts to get the ball passed to them more often and starts to take riskier shots and invariably winds up hitting a lower percentage of shots than their normal average.  The concept of someone getting on-fire has the exact opposite effect than we intuitively think it would.  We universally misunderstand randomness because we were created as ordered beings in a universe of both order and chaos.

Thursday, February 4, 2010

It's all been done before...

One of the reasons I built our family's DVR is to keep from seeing all the terrible commercials. Specifically, a lot of the commercials for suspense and horror films are just awful. But, it's pretty difficult not to see the first and final commercials in the break. The first commercial is when you begin skipping if you can locate the remote, and the last one is the one you have to rewind back to when you skip ahead too far.

One of the commercials I keep accidentally seeing is for a movie called Shutter Island. I've not seen anything but the trailer, and I have no interest in seeing it at all, but it amuses me to no end what they're trying to pull. WARNING - SPOILER AHEAD...

This movie is based on a book I haven't read, or even heard of, but it's so obvious what the plot is. I'm 99.999% positive it's the same plot twist as A Beautiful Mind and Fight Club. You're supposed to identify with the main character and be so engrossed in his plight that you don't realize that's he's completely insane. He's not some outside investigator researching the asylum, but an inmate in the asylum himself. There - I saved you from wasting 2 hours of your life.

Wednesday, February 3, 2010

Wotch Awt!

As my oldest learns to read and write, I am daily reminded of the complexity of the English language.  Ian has a remarkable ability to understand letters and sounds, and teases out words from the context of a sentence as much as the interplay of letters.  We've been told by his teacher that he's one of the best readers in his Kindergarten class.  He's reading some complicated stuff, but it's his writing that is most interesting to me now.  I'm daily reminded that there are just some things in English that you can't tease out - you have to memorize.  "Pizza" has no T's in it.  "Of" looks like it should be pronounced "Off", but is instead a very bizarre "Uv".  Enuf and fone and luv and thru are phonetic and even readable, but inaccurate.

When I took Spanish in high school and college, it was strange to me that words were assigned a gender, and that word suffixes would denote who you were talking to, and even the level of familiarity or respect you had for the person with whom you're conversing.  But supposedly (so I've heard), English is still harder to learn.

Case in point - Ian has a reversible sign on his bedroom door, which he made one day when he was in a particularly foul mood.  On one side it says - "Grumpy Mood Doo Not Dystrakd" (hover for translation), and on the other side it says "Happy Mood Fry To Cum En" (hover for translation).

Today, he spilled a whole cup of juice on the floor unbeknownst to his mother. He took care of the mess, and then fessed up to Beth. He had made a sign that said "Wotch Awt Slipry" (hover for translation). The picture is of a bald, frowny-faced little orange man, falling - with a large down arrow indicating the action sequence. What a remarkable kid he is.

VB.NET Corner - fun with Linq, lambdas, and anonymous types

In my post, C# Corner - fun with 'yield' and extension methods, I discussed the common scenario of iterating over an IEnumerable<T> collection while maintaining an index.  Due to playing around with the 'yield' keyword, VB.NET was excluded from the fun.  Well, using Linq, lambda expressions, and anonymous types, we can accomplish the same results I was describing in my previous post, but now VB can participate too.  Here's the code:

Dim names = New String() {"You", "Me", "Dupree"} ' Or GetLazyLoadedNames() if you want
For Each n In names.Select(Function(x, i) New With {.Index = i, .Item = x})
   Console.WriteLine("{0}-{1}", n.Index, n.Item)

This code is chock full of goodies, which doesn't make it the most readable thing in the world, but lets break it down:

The .Select() function is a simple extension method inserted into any IEnumerable via the inclusion of the System.Linq namespace.  It can take a lambda expression of the item you're interating over, as well as the index of that item.  That's the Function(x, i) part.  And finally, we have the anonymous type mimicing the data structure we discussed in the previous post consisting of the two properties - Index and Item.  VB.NET uses the New With {} syntax to define an anonymous type.  The x and i variables only have scope within the context of the Select function's lambda expression, so you can't accidentally use those variables somewhere unintended, and the anonymous type means that you don't have to have any of the supporting infrastructure classes required from our previous discussion.  All in all, not a bad way to do things (at the expense of a little readability at first).  And, just for fun, here's the C# version too:

var names = GetLazyLoadedNames();
foreach (var n in names.Select((x, i) => new {Index = i, Item = x})) {
   Console.WriteLine("{0}-{1}", n.Index, n.Item);

So, in these two posts, I've barely mentioned most of the feature awesomeness of the 3.5 framework just in time for the 4.0 stuff to hit the shelves.  The things I'm now able to do with the addition of Linq have made the past year of development a total joy, and I'm really interested to see what the 4.0 framework brings to the table.  Is the Entity Framework 4.0 release finally usable?