Sunday, October 31, 2010

Random Enum in C#

I wrote this because.. well.. I can. 8D

If you use this code, please give Protiguous some credit. (Too bad adSense doesn't allow one to ask for clicks. Because that'd be cooler!)

Explanation:
  1. Initialize a newly seeded rng with an overkill of LINQ.
  2. Initialize a thread safe access control.
  3. Generate a list of names for each defined enum.
  4. ... and return one of those enums.


Here is some untested sample code:
enum ourEnums { One, Two, Three, Four, Five };

//I know we could use a for loop, but I love foreach so much more..
foreach ( var i in Enumerable.Range( 0, 10 ) ) {
   Console.WriteLine( RandEnum() );
 }

Note: If there are any uppercase/lowercase/typos... let's just blame it on blogspot/browser/politics/etc... as always: It Works On My Machine.

And here is my sample code for returning a random enum in C#:
namespace Examples {
    using System;
    using System.Linq;
    using System.Threading;

    public class Example {

        private static readonly Random oti = new Random( Guid.NewGuid().ToByteArray().Sum( b => b * b.GetHashCode() ) );

        private static readonly ReaderWriterLockSlim otia = new ReaderWriterLockSlim( LockRecursionPolicy.SupportsRecursion );

        public static T RandEnum() {
            if ( !typeof( T ).IsEnum ) { return default( T ); }

            var names = Enum.GetNames( typeof( T ) );
            try { otia.EnterWriteLock(); return ( T )Enum.Parse( typeof( T ), names[ oti.Next( 0, names.Length ) ] ); }
            finally { otia.ExitWriteLock(); }
        }

    }
}

Wednesday, October 27, 2010

A Big Blue Brain Bug!

An excerpt from BugBrain that tickled my funny bone:

Oh, yes… I have received a lot of questions like "So, what the hell is bugbrain?":-)

Well, in my early school days I had my personal molester (as every skinny guy with glasses, I presume).

One day he stepped to me, poked with his finger to my head and asked:

"No…?", I answered meekly.

"A big blue brain bug!"

"Oh!"

"And do you know what he's doing?"

"No…?"

"He's starving!" he tittered, poked me again and went away.

And since then, I just cannot get this bug out of my head...

Tuesday, October 19, 2010

Tips to increase AdSense revenue

    Here are some ways to help increase your AdSense revenue:
  • Promote your web site to get more visitors. More visitors should mean more adclicks. Try submitting your pages to multiple search engines and forums.
  • Cross link more of your pages to increase page views. More page views could mean more adclicks.
  • Tweak the AdSense placement. Does it look right to you? Does it look natural? Tweaking the placement could generate more clicks because the reader does not feel like an ad is being forced upon them
  • Use text ads if possible. They will load faster than images and blend better with more themes.

Wednesday, October 13, 2010

Curb Raping Women

Women drivers.
Why do they enjoy raping the curbs?
You know.. they take a right turn and they let the back (and on the really good drivers: the front) wheels drag slowly across the the sidewalk curb.

Usually scraping up the tire's sidewall and possibly even the wheelwell..

I just don't get it.
Don't women have an overall sense of the vehicle's position?

Oh well, love 'em anyways.. :()

Tuesday, October 12, 2010

No offense

FYI, saying "No offense" doesn't make what your going to say or already said any less hurtful.

Monday, October 11, 2010

Breasts: Quality vs Quantity

Breasts: Quality vs Quantity?

Definitely Quality. :)