Winners Of My 1,000th ColdFusion Post

Posted January 26, 2009 at 9:53 AM by Ben Nadel

Tags: ColdFusion

Last Friday, I posted my 1,000th ColdFusion blog post on Kinky Solutions. In the spirit of loving ColdFusion, I reflected upon the last 8 years of my ColdFusion life regarding what ColdFusion has meant to me and I asked others to share their stories as well. I had said that from those pro-ColdFusion comments, I would pick some winners this morning to receive Amazon.com gift certificates. I wanted to pick those winner randomly. Now, picking random numbers in ColdFusion is a rather straightforward task. But, I wanted to keep this task interesting (it's Monday morning after all). So, rather than just using ColdFusion's RandRange() method, I created a custom RandRange() method powered by Google's "I'm Feeling Lucky" search functionality:

  • <cffunction
  • name="GoogleRandRange"
  • access="public"
  • returntype="numeric"
  • output="false"
  • hint="I use Google's Im Feeling Lucky functionality to help pick out a random number.">
  •  
  • <!--- Define arguments. --->
  • <cfargument
  • name="MinValue"
  • type="numeric"
  • required="true"
  • hint="I am the lower-bound inclusive value."
  • />
  •  
  • <cfargument
  • name="MaxValue"
  • type="numeric"
  • required="true"
  • hint="I am the upper-bound inclusive value."
  • />
  •  
  • <!--- Define the local scope. --->
  • <cfset var LOCAL = {} />
  •  
  • <!--- Create a random set of keywords. --->
  • <cfset LOCAL.Keywords = [
  • "sexy", "muscle", "voluptuous", "saucy", "naughty",
  • "protein", "hairy", "sweet", "squating", "kinky",
  • "amazon", "fetish", "plump", "smooth", "fitness",
  • "smile", "fresh", "pumped", "delicious", "happy"
  • ] />
  •  
  • <!---
  • Shuffle keyword array to get a new, random result from
  • Google's I'm Feelin Lucky search results.
  • --->
  • <cfset CreateObject( "java", "java.util.Collections" ).Shuffle(
  • LOCAL.Keywords
  • ) />
  •  
  • <!--- Build the search query with the first 3 keywords. --->
  • <cfset LOCAL.Criteria = (
  • LOCAL.Keywords[ 1 ] & " " &
  • LOCAL.Keywords[ 2 ] & " " &
  • LOCAL.Keywords[ 3 ]
  • ) />
  •  
  •  
  • <!---
  • Get the first result from Google search. Wrap this in a
  • Try/Catch incase it timesout and throws an error.
  • --->
  • <cftry>
  •  
  • <!--- Grab random result. --->
  • <cfhttp
  • method="get"
  • url="http://www.google.com/search"
  • useragent="RandomizerBot"
  • timeout="5"
  • result="LOCAL.HttpGet">
  •  
  • <!--- Referer from google. --->
  • <cfhttpparam
  • type="header"
  • name="referer"
  • value="http://www.google.com"
  • />
  •  
  • <!--- The search query. --->
  • <cfhttpparam
  • type="formfield"
  • name="q"
  • value="#LOCAL.Criteria#"
  • />
  •  
  • <!--- Im Feeling Lucky submit button. --->
  • <cfhttpparam
  • type="formfield"
  • name="btnI"
  • value="I'm Feeling Lucky"
  • />
  •  
  • </cfhttp>
  •  
  • <!--- Catch http connection errors. --->
  • <cfcatch>
  •  
  • <!---
  • There was an error connecting to this site.
  • Try another attempt.
  • --->
  • <cfreturn GoogleRandRange(
  • ARGUMENTS.MinValue,
  • ARGUMENTS.MaxValue
  • ) />
  •  
  • </cfcatch>
  • </cftry>
  •  
  •  
  • <!--- Check to see if we connected. --->
  • <cfif NOT FindNoCase( "200", LOCAL.HttpGet.StatusCode )>
  •  
  • <!---
  • The random result may have failed. Return a
  • new random result.
  • --->
  • <cfreturn GoogleRandRange(
  • ARGUMENTS.MinValue,
  • ARGUMENTS.MaxValue
  • ) />
  •  
  • </cfif>
  •  
  •  
  • <!---
  • ASSERT: At this point, we know that the CFHTTP get
  • was successfull.
  • --->
  •  
  •  
  • <!--- Remove any non-word characters. --->
  • <cfset LOCAL.Content = REReplace(
  • LOCAL.HttpGet.FileContent,
  • "[^\w]+",
  • "",
  • "all"
  • ) />
  •  
  • <!--- Grab a random character in the content. --->
  • <cfset LOCAL.Char = Mid(
  • LOCAL.Content,
  • RandRange( 1, Len( LOCAL.Content ) ),
  • 1
  • ) />
  •  
  •  
  • <!--- Get the difference betweent he min and max value --->
  • <cfset LOCAL.Range = (ARGUMENTS.MaxValue - ARGUMENTS.MinValue) />
  •  
  • <!---
  • To make sure we get a sufficiently large value from
  • which to pick (increasing the randomness), let's multiple
  • the selected ASCII value by the length of the content.
  • --->
  • <cfset LOCAL.HighAscii = (Asc( LOCAL.Char ) * Len( LOCAL.Content )) />
  •  
  • <!---
  • Return the lower bound value plus the MOD of the high
  • ascii to the range.
  • --->
  • <cfreturn (
  • ARGUMENTS.MinValue +
  • (LOCAL.HighAscii MOD LOCAL.Range)
  • ) />
  • </cffunction>

Now, obviously, this method is not completely random since the I'm Feeling Lucky site is picked from a finite set of keyword combinations. However, for our purposes (which is just to have fun), this should be sufficient.

Picking The Winners

Once I had the above function in place, I counted up the qualifying comments from my previous post and then called the GoogleRandRange() method four times. Here are the winners of my 1,000th ColdFusion post and a $25 Amazon.com gift certificate:

  1. Tom Chiverton
  2. David Stamm
  3. Yves
  4. Matt Gifford

Congratulations guys! Let's keep the ColdFusion party going!




Reader Comments

Jan 26, 2009 at 10:10 AM // reply »
29 Comments

Holy cow - what a delightful surprise on a Monday morning!

And congratulations on your 1001st post, which includes one of the wackiest random number generators I've ever seen. :)


Jan 26, 2009 at 10:10 AM // reply »
18 Comments

Awesome!

Thanks Ben. You've made my Monday afternoon complete!
And with a truly 'Nadel' way of solving the winners. :)

Thank you


Jan 26, 2009 at 10:14 AM // reply »
42 Comments

Thank you very much Ben !
I'll let you know what it ends up being...


Jan 26, 2009 at 10:47 AM // reply »
7 Comments

Awesome!

You've made my day!!

I'm mostly a "lurker" on the blogosphere.... I've enjoyed reading many of your posts... loved the Object Orientation posts.

ColdFusion rocks.

;-)

Peace dude!


Jan 26, 2009 at 11:00 AM // reply »
153 Comments

That is a truly twisted and inspired way to get a random number. I'm a little bummed that you couldn't work QoQ into it, but then I know you need to protect the image of your sanity with the community.

Gratz on your kilopost.


Jan 26, 2009 at 11:00 AM // reply »
10,640 Comments

Congratulations guys. Thanks for sharing your stories. And please, feel free post comments any time - I love a good conversation.


Jan 26, 2009 at 11:01 AM // reply »
10,640 Comments

@Rick,

I was actually a bit inspired by your comments the other day. I can't remember the post, but I remember it has a query of queries :)


Jan 26, 2009 at 11:04 AM // reply »
110 Comments

Fix! Fix! :)

Congrats to all the winners and thanks Ben for giving back yet again to the community.


Jan 26, 2009 at 11:15 AM // reply »
10,640 Comments

@Gareth,

Blame Google :)


Jan 26, 2009 at 2:36 PM // reply »
42 Comments

A couple notes here-

First, is it possible to search ANYTHING related to programming without your site coming up first? It always even comes ahead of livedocs (which I am glad about). Great job.

Second, are there more than 24 hours in your day? You pump out a ton of content for only a 24 hour day. Keep it up. You inspire us all.


Jan 27, 2009 at 2:37 AM // reply »
14 Comments

haha, GoogleRandRange(), love it :)


Jan 27, 2009 at 6:35 PM // reply »
3 Comments

This is all backwards... Ben, the community owes you a huge debt for your hard work and dedication. I've said it many times and I'll say it again, THANK YOU!

Next time I'm in New York, I'd like to take you out for a beer or three ;-)


Post A Comment

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

Author Name:


Author Email:

Author Website:

Comment:

Supported HTML tags for formatting: <strong>bold</strong>   <em>italic</em>   <code>code</code>







  • Help Wanted - Find Your Next ColdFusion Job
InVision App - Prototyping Made Beautiful With Prototyping Tools Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
Feb 10, 2012 at 7:21 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
Update! Instead of $(eval(options.insertAfter)).after(data['insertData']); I now use: var ajaxNode = document.createElement('span'); var parent = $(eval(options.insertAfter))[0].parentNode; ... read »
Feb 10, 2012 at 6:18 PM
jQuery AJAX Strips Script Tags And Inserts Them After Parent-Most Elements
encountered this same, what I consider, jQuery bug last week. I'm building a site in which I load some content via AJAX. This content contains Linkedin share button placeholders which Linkedin API ne ... read »
Feb 10, 2012 at 11:30 AM
Cross-Origin Resource Sharing (CORS) AJAX Requests Between jQuery And Node.js
After you understand the concepts here, this is an awesome cheatsheet for enabling CORS in just about anything http://enable-cors.org/ ... read »
JM
Feb 10, 2012 at 9:10 AM
My Safari Browser SQLite Database Hello World Example
@Amy, Here is a very good tutorial on how to use JOIN: http://www.sqltutorial.org/sqljoin-innerjoin.aspx ... read »
Feb 10, 2012 at 4:42 AM
Building A Twitter-Inspired RESTful API Architecture In ColdFusion
This is great, very useful Ben. I spotted a small typo in the api.cgm listing: <cfthrow type="Unauthroized" /> Cheers Stefan ... read »
Feb 9, 2012 at 10:35 PM
CFDirectory Filtering Uses Pipe Character For Multiple Filters (Thanks Steve Withington)
I was wondering if there would be a filter you could apply so that you got everything but what you included in the filter. As in show me all docs that are not a .pdf. ... read »
Feb 9, 2012 at 10:29 PM
Learning ColdFusion 9: Application-Specific Data Sources
@Ben, No offence, but if people were really wanting advanced features they would be using a platform like ASP.NET MVC. CFML is so structurally compromised as a tag-based scripting language that ... read »
Feb 9, 2012 at 10:03 PM
Subversion - Cleanup Failed To Process The Following Paths
@Leviaguirre, do you still have problems with this? ... read »