views:

732

answers:

11

Let's try to make this for our favourite technology too, how do you think?

Hidden code tricks, unknown usages of known features, application server easter eggs are what are we looking for.

So, proposed rules are simple:

  • One feature per answer.
  • Code example, if it is the CFML/CFScript feature.
  • Application server name and version where it can be reproduced.
  • Link on the source, if re-posting someone (let's be honest).
  • Any additional requirements/tips to reproduce.


Example (old one, many of us should remember)

Credits easter egg with custom IE language

Open your IE (6+), go to: Tools -> Internet Options -> Languages.

Add a new custom language called "CFML" (without quotes) and shift it to the top of list.

Then log into your ColdFusion Administrator and click on System Information.

Funny pop-up should show up.

It works in CFMX 6, 7.2 and Adobe CF 8 (9 not checked).

+1  A: 

Hidden Gems in CF8 (Scorpio)

Prepare to be surprised! In this talk (presented at 3am to the Auckland CFUG), veteran CFML developer Charlie Arehart introduced a few dozen little hidden gems coming up in CF8 (Scorpio). Sure, we've all heard about the big features, but in every release there are lots of little things, and in CF8 especially, Adobe has pulled out the stops! Come see if some long-standing problem has been solved, or learn of some new technique that's become available. You may be surprised at all the little things you may have missed! (Charlie's continued to update his presentation since then, so look for a later recording soon.)

Henry
+7  A: 

Not sure if this counts but I really like this feature of coldfusion:

<cfargument name="blah" default="#func()#">

This sure beats having to test using isDefined and then giving the argument a value if it's null.

This works in coldfusion 8.

Brian Bolton
Shouldn't it be default="#func()#"? Can you please clarify a bit how do you use it. Really interesting!
Sergii
@Sergii, probably just a typo. But yes it works with default="#funcName()#". @Brian - Good tip. Learn something new every day.
Leigh
+11  A: 

Technically this is documented in ColdFusion 9, but I think it's pretty handy.

<cfdump var="#foo#" abort />

No need to specify a value for the abort attribute (default is true if the attribute is specified).

Adrocknaphobia
That is a nice time-saver.
Leigh
Ctrl+Shit+A is faster than typing abort. :)
Henry
where's the shit key located on your keyboard?
orlandu63
lol, next to the omg key.
crosenblum
+1  A: 

oldie but goodie:

we all know that you can't do a valuelist() on a dynamic column name:

ValueList(loc.values.#arguments.property#)

so you're force to use evaluate() like so:

Evaluate("ValueList(loc.values.#arguments.property#)")

however, in adobe coldfusion you can eliminate the evaluate by using ArrayToList():

ArrayToList(loc.values[arguments.property])
rip747
+4  A: 

Though only supported for Microsoft Word and PowerPoint (97 to 2003), CF9's OpenOffice integration features can convert most formats to pdf. Basically anything OpenOffice supports: xls, xlsx, doc, docx, ppt, rtf, vsd, ..

<cfdocument format="pdf"  
  srcfile="c:\myFiles\myPowerPointFile.ppt"  
  filename="c:\myFiles\myPowerPointFileConverted.pdf" />  

<cfdocument format="pdf"  
  srcfile="c:\myFiles\myExcelFile.xls"  
  filename="c:\myFiles\myExcelFileConverted.pdf" />
Leigh
+3  A: 

Think this one should be here too:

<cfset test = {str='Yes',num1='100500',num2=100500}>
<cfset json = serializeJSON(test)>
<cfset fromJSON = deserializeJSON(json)>

<cfoutput>
    #test.str#<br>
    #json#<br>
    #fromJSON.num1#, #fromJSON.num2#, #fromJSON.str#
</cfoutput>

Adobe CF 8 & 9 output:

Yes
{"NUM1":100500.0,"STR":true,"NUM2":100500.0}
100500, 100500, YES 

Railo 3.1 output:

Yes
{"NUM2":100500,"NUM1":"100500","STR":"Yes"}
Yes, 100500, 100500 

Workaround for Adobe ColdFusion: prepend value with space or any other text character (space can be trim'ed later -- handy).

<cfset test = {str=' Yes',num1=' 100500',num2=100500}>

Be careful.

Sergii
+1  A: 

Don't forget the entirety of java is out there for ya...sometimes you just want to go to the basics...

See http://www.adobe.com/devnet/coldfusion/articles/java.html for way more details and hints...

np0x
+2  A: 

Not really hidden, but knowing that the following CF objects map to Java interfaces/objects has always been helpful:

Struct => Map<String,Object>
Array => Vector
Query => QueryTable (which implements RecordSet)
List => String

It allows you to drop down when it's convenient to write code like:

<cfset var iter = struct.keySet().iterator() />
Bialecki
Yup, and do not forget javaCast :)
Sergii
A: 

StructKeyList is an interesting little function that gets the name of the argument passed into a cffunction. This allows me to build a generic "WHERE CLAUSE" generator.

<cffunction name="Check">
    <cfset var local = {}>

    <cfset local.PK = StructKeyList(arguments)>
    <cfset local.ID = Evaluate("arguments.#local.PK#")>
    <cfif IsNumeric(local.ID)>
     <cfset local.result = "WHERE #local.PK# = #local.ID#">
    <cfelse>
     <cfoutput>Invalid Primary Key: #local.PK# = #local.ID#</cfoutput>
     <cfabort>
    </cfif>
    <cfreturn local.result>
</cffunction>

This allows me to do the following:

<cfset local.Criteria = Check(StateID=arguments.StateID)>
<cfset local.Criteria = Check(CityID=arguments.CityID)>

returns the following:

WHERE StateID=101
WHERE CityID=1001
cf_PhillipSenn
+2  A: 

<cfdump var="#getPageContext().getBuiltInScopes()#"> saves you a lot of typing when you want to dump all variable scopes.

Gert G