ColdFusion


In case I ever need it again, this is the CSS to force a "proper" ordered list hierarchy all the way to 6 layers deep. (pro tip – if it's 6 layers deep, you're doing something wrong)

<style type="text/css">
  OL { list-style-type:upper-roman }
  OL OL { list-style-type:upper-alpha }
  OL OL OL { list-style-type:decimal }
  OL OL OL OL { list-style-type:lower-roman }
  OL OL OL OL OL { list-style-type:lower-alpha }
  OL OL OL OL OL OL { list-style-type:lower-greek }
</style>

I have no idea why this information was so difficult to find, but I'm posting it here in case I ever need it again.

To do a reverse lookup in coldfusion:

<cfscript>
rawIP = createObject("java", "java.net.InetAddress").getByName('#ipaddress#').getAddress();
hostname = createObject("java", "java.net.InetAddress").getByAddress('#rawIP#').getHostName();
chostname = createObject("java", "java.net.InetAddress").getByAddress('#rawIP#').getCanonicalHostName();
</cfscript>

Note — this is slow. If you're doing them in bulk, you may need to go in small batches or set a higher timeout.

Also, this was perhaps useful: http://api.hostip.info/get_html.php?ip=#ipaddress#&position=true — returns the country, city, state, and geotag info for an IP address, where available.

Assumption: table named locations that has a location name and the location's latitude & longitude as a single field, with lat and lon comma separated, both in signed degrees format.

This is an intentional cartesian join… so if you have a lot of locations, use with care.

<cfquery datasource="MyDSN" name="getDist">
SELECT DISTINCT   
    a.latlon AS thestart,
    a.locName AS startname,
    b.latlon AS theend,
    b.locName AS endname
FROM     locations a
CROSS JOIN    locations b
WHERE     a.locName<> b.locName
ORDER BY     a.locName, b.locName
</cfquery>

<cfoutput query="getDist" group="startname">
<h4>#getDist.startname# to…</h4>
<ul><cfoutput>
<li>#getDist.endname# — #3963.0*acos(sin(listfirst(thestart)/57.295779513082323)*sin(listfirst(theend) / 57.295779513082323)+ cos(listfirst(thestart) / 57.295779513082323)*cos(listfirst(theend) / 57.295779513082323)*cos((listlast(theend) – listlast(thestart)) / 57.295779513082323))# Miles
</li>
</cfoutput>
</ul>
</cfoutput>

———————

This is based on a snippet of SQL code someone forwarded to me which was signed "RBarryYoung, 31-Jan-2009″ — so credit to RBarryYoung for it. :)

A month or so ago I had to throw together a script to help with some forensics, it strikes me that it might come in handy for other people, so I'm going to post it here. Just edit the first bit and provide it with your datasource name, and run it. You might need to adjust the timeout settings in ColdFusion Administrator — if your database user has access to a lot of stuff, it could take a very long time to run. 

It uses one of the new CF8 tags, CFDBinfo, that hasn't gotten much press. It also highlights something that I found a bit disturbing, though I guess it makes sense… even though you assign a database name to your DSN in CF, CF isn't locked down to that DSN, it can interact with any database on the server that the user you put in there can access.

This snippet of code is also pretty useful — it shows all your DSN settings at once:

<cfset sf = CreateObject("java", "coldfusion.server.ServiceFactory")>
<cfdump var="#sf.DataSourceService.getDatasources()#" expand="true">

With either of these, please exercise caution.. don't put them somewhere anyone but you can execute them, and don't leave them up there any longer than it takes for you to extract the data you need. :)

I keep this in a file on my desktop.. may as well put it here, too… maybe it'll help someone someday.

CRLF:
cfset crlf = #chr(13)#&#chr(10)#

Variable Variables:
cfset varvar = "MyVarName"
cfset "#varvar#" = "whatever"
#evaluate(varvar)# outputs "whatever", #varvar# outputs "MyVarName"

Existence/Type Test:
StructKeyExists() IsDefined() (isDefined fails on complex vars with[], use dot notation) IsArray() IsStruct() IsQuery() IsSimpleValue() IsNumeric() IsDate() IsBinary() IsBinary()

CFHTTP Connection Failure
Gzip bug — add this:
cfhttpparam type="Header" name="Accept-Encoding" value="deflate;q=0″
cfhttpparam type="Header" name="TE" value="deflate;q=0″
Also check for redirect="yes|no" — sometimes redirect needs to be set to no

Query Variables:
query_name.currentRow, query_name.columnList, query_name.RecordCount, result_name.sql

Query of Queries:
cfquery dbtype="query" name="foo" — select * from query_name

CFDirectory Performance:
listinfo="name" significantly improves performance, if you don't need other columns

CFQueryParam:
Null="#YesNoFormat(NOT LEN(MyVar))#" will make the value NULL instead of empty
List="yes" will internally CFParam all list values so you can do WHERE ID IN (cfqueryparam… list="yes") and get a valid list format. Add separator = '|' instead of delimiter='|' — for some reason this tag is different than all the other ones.
CF_SQL_TIMESTAMP — datetime, smalldatetime (use CreateODBCDateTime() for this)
CF_SQL_CHAR — char, nchar, unique identifier
CF_SQL_VARCHAR — varchar, nvarchar, sysname
CF_SQL_LONGVARCHAR — text, ntext
CF_SQL_NUMERIC — numeric (scale='2′ for 2 decimal places)
CF_SQL_INTEGER — int
CF_SQL_SMALLINT — smallint
CF_SQL_TINYINT — tinyint
CF_SQL_BIT — bit
CF_SQL_FLOAT — float
CF_SQL_DECIMAL — decimal, money, smallmoney (scale='2′ for 2 decimal places)
CF_SQL_BINARY — binary, timestamp

Merge Log Files (Not CF, but useful!)
copy *.log merged.log

CF Regex:
rereplace(foo, "[[:space:]]+", " ", "all") — turns all whitespace into single space
rereplace(foo, ".*?", "", "all") — strips all HTML tags (probably fails if they span multiple lines)

(updated July 16)

Here's a little thing I ran across today that might be worth noting — in CF8 there were apparently some changes in how a couple of the system commands work. I had an old snippet of code set up as a custom tag, it dumped out the last modified date of the file at the bottom of any page it was included in. Prior to CF8, CGI.CF_TEMPLATE_PATH and also getCurrentTemplatePath() would refer to the template which was calling a custom tag; post CF8, they refer to the custom tag. Which they probably should have done from the beginning… but it broke my code.

Oh, and the revised code snippet:

<cfset fileObj =createObject("java","java.io.File").init(getBaseTemplatePath())>
<cfset fileDate =createObject("java","java.util.Date").init(fileObj.lastModified())>
<cfoutput>Last Modified: #dateformat(fileDate,"m/d/yyyy")# #timeformat(fileDate)#</cfoutput> (Much more efficient than the lovely looping through cfdirectory cruft that was leftover from CF 4.5)