Monthly Archive for March, 2008

New Cyclic Data Structures Utility

Back in October I posed a fledgling cycle-safe CFDUMP replacement.  Today, I had need for that same anti-cycle processing in serializeJson, so I abstracted the processing out into a CFC that handles both breaking cycles (for serialization) as well as restoring them (for deserialization).  By running a cyclic data structure through the breakCycles method, you can use CFDUMP, serializeJson, or whatever other context-free recursive algorithm you want on it without fear of infinite looping.  If you later turn that data structure back into an in-memory structure, you can use the restoreCycles method to recreate the cyclic references that breakCycles removed.

You can download the CFC (as a text file) here: cyclicutils.cfc.txt.  If you have the example from the cycle-safe CFDUMP somewhere, save the CFC in the same directory and tack this code on to the end of the test case:

<cfset cu = createObject("component", "cyclicutils") />
<cfset b = cu.breakCycles(b) />
<cfdump var="#b#" label="b" />
<cfset b = cu.restoreCycles(b) />
<u:dump var="#b#" />

You'll see the cyclic structure dumped with the cycle-safe CFDUMP as before, then the cycles are broken and it's dumped with the standard CFDUMP, and then the cycles are restored and it's dumped with the cycle-safe CFDUMP again.

Otherwise, just create yourself a cyclic structure and pass it to breakCycles.

CAPTCHA is the Devil

I know, I know. I've said this before. Trying to have a conversation on another blog and the CAPTCHA … oh my god. If you insist on using CAPTCHA (for some unknown reason), follow some rules:

  1. only letters and numbers, and never l, o, I, O, 1, or 0
  2. don't make the comparison case sensitive
  3. make sure all the characters are fully in the view window
  4. don't use session scope (use a hash)
  5. don't make the same person enter more than one CAPTCHA if they're otherwise identifiable

If you're rational, install anti-spam software (Akismet works great), throw some JS in there for robots to fail to deal with, and use per-contributor moderation. Please, lets not make the blogosphere into a hostile world of mistrust when it doesn't have to be.