You got lucky, punk.

I'll go out on a limb and say that this is a Southern thang. I just couldn't wrap my mind around a Wall Street stockbroker, upon congratulating a colleague on some lucky stock picks, saying "Well dear sir, the sun even shines on a dog's ass occasionally!" But, with typical Southern loquacity, the phrase just rolls off the toungue of any true good ol' boy—"Shit Johnny-boy! Did you see me nail that buck right thru the eye?" "Yea, Dwight. I guess the sun even shines on a dog's ass occasionally."

I have to fight the urge to add a ;-) at the end of Johnny's reply, not in the least because Johnny's never been on the internet and would beat me six ways from Sunday for such a "pansy waste of time". But rarely, if ever, would this phrase be used to express genuine disgust or resentment of the luck of another. Normal delivery comes amidst good friends, with a cock-eyed smile and a sarcastic twang. How could it be otherwise? Just try saying it aloud. Go ahead, right now, try saying in your best Foghorn Leghorn impression

Shoot, the sun even shines on a dog's ass occasionally.

Now if that didn't bring a shit-eatin' grin to your face, then you're a humourless old fart and should never be allowed south of the Mason-Dixon line!

Etymology

I can't quote any official sources on this, but I'd say the derivation of this phrase is fairly obvious. There just ain't too many times when a dog's ass is pointed at the sun, and even when it is there's a tail usually in the way. I couldn't find any information on the poet laureate who first observed this phenomenon and coined this fine turn of words, but I'll bet you the gun rack off my 4x4 that he was a southerner.

Proper Usage

Situation: Your buddy just scored the final bullseye in a round of darts at the bar.
Response: Say "I suppose the sun even shines on a dog's ass occasionally!" and then chug your beer like the sporting loser you are.

Situation: The little league team you coach just lost the championship game and are looking a little downcast.
Response: Tell them "Well fellas, I think we had 'em as good as beat, but I reckon the sun even shines on a dog's ass occasionally. And today must have been their day!" and then take them out for all-you-can-eat pizza.

Related Terms

The sun don't shine on the same dog's ass every day

Other Solid Southern Expressions

Finer than frog's hair
Happy as a puppy with two peters