Did You Know

My buddy Josh posted this video on his blog the other day and it really makes you think. So... check it out!

No Comments

ColdFusion 8: Creating CAPTCHA images


I recently had a project where my customer was getting alot of spam thru a contact form. So I thought I could use some CAPTCHA on the web form to stop some spam. I knew CF8 had the functionality to create CAPTCHA images, but I didn't know how to actually implement it. So after a bit of googling, I found Ben Nadel's post on creating and validating CAPTCHA images on forms.

I will briefly go over his code and show you my final result...

No Comments

3 Days Til MAX

3 days til Adobe MAX and counting... see you all there!

No Comments

ColdFusion 8: Rounded Corners & Reflection


As you may have known, Foundeo has created an Image Effects CFC that can generate image gradients, reflection, drop shadows, and some more cool effects by taking advantage of the new image features in ColdFusion 8.

Some people have been trying to replicate some of the functions this package has, especially the gradients, reflection and rounded corners functions. John Hartmann did an excellent job in replicating the reflect() and gradientMask() functions.

Jeff Coughlin also started building a CFImage Effects Plugin for FarCry based off of John Hartmann's functions. His Plugin has code to replicate the rounded corners.

Now, lets get into the code...

No Comments

Search Thru a Multi-Dimensional Array

I ran into a situation today where I needed to search thru a multi-dimensional array to update quantities and total prices for backordered products coming from a query. Unfortunately ColdFusion doesn't have an ArrayFind() function like it does for structs. I did a search on CFLib and found a UDF that did the trick.

The ArrayFindByDimension() UDF allows you to pass it an array, the value to find, dimension to search and returns the numeric array position if found, 0 if not found.

Here is some of my sample code:

<!---
Search a multidimensional array for a value.

@param arrayToSearch     Array to search. (Required)
@param valueToFind     Value to find. (Required)
@param dimensionToSearch     Dimension to search. (Required)
@return Returns a number.
@author Grant Szabo (grant@quagmire.com)
@version 1, September 23, 2004
--->

<cffunction name="ArrayFindByDimension" access="public" returntype="numeric" output="false">
   <cfargument name="arrayToSearch" type="array" required="Yes">
   <cfargument name="valueToFind" type="string" required="Yes">
   <cfargument name="dimensionToSearch" type="numeric" required="Yes">
   <cfscript>
      var ii = 1;
      
      //loop through the array, looking for the value
      for(; ii LTE arrayLen(arguments.arrayToSearch); ii = ii + 1){
         //if this is the value, return the index
         if(NOT compareNoCase(arguments.arrayToSearch[ii][arguments.dimensionToSearch], arguments.valueToFind))
            return ii;
      }
      //if we've gotten this far, it means the value was not found, so return 0
      return 0;
   </cfscript>
</cffunction>

<!--- begin the count --->
<cfset i = 1>
<!--- create the array --->
<cfset products = ArrayNew(2)>

<cfloop query="backordered">
   <!--- search array --->
   <cfset arrPos = arrayFindByDimension(products, "#backordered.product_code#", 2)>
   <cfif arrPos EQ 0>
      <cfset products[i][1] = backordered.product_id>
      <cfset products[i][2] = backordered.product_code>
      <cfset products[i][3] = backordered.order_details_quanity>
      <cfset products[i][4] = backordered.order_details_price * backordered.order_details_quanity>
      <cfset i = i + 1>
   <cfelse>
      <cfset products[arrPos][3] = products[arrPos][3] + backordered.order_details_quanity>
      <cfset products[arrPos][4] = products[arrPos][4] + (backordered.order_details_price * backordered.order_details_quanity)>
   </cfif>
</cfloop>

<!--- dump the array --->
<cfdump var="#products#">

No Comments