Did you know the formula of love? It’s
Plotting this will result in a nicely hearth-shaped figure. The ultimate geek gift for his geek girlfriend!
I reproduced this plot using two methods: ColdFusion cfchart/cfchartseries/cfchartdata tags and a jQuery plotting library, called flot.

1. ColdFusion code

cflove.cfm (tested both on ColdFusion 8 and ColdFusion 9)

<cfchart format="flash" xaxistitle="X" yaxistitle="Y">
	<cfchartseries type="scatter">
		<cfloop index="x" from="-1" to="1" step="0.02">
			<cfset y1 = sqr(x^2)-sqr(1-x^2)>
			<cfchartdata item="#x#" value="#y1#">
	<cfchartseries type="scatter">
		<cfloop index="x" from="-1" to="1" step="0.02">
			<cfset y2 = sqr(x^2)+sqr(1-x^2)>
			<cfchartdata item="#x#" value="#y2#">

You will notice that the formula of love is composed by two curves:
-the upper part of the hearth: y = sqrt(x^2) – sqrt(1-x^2)
-the lower part of the hearth: y = sqrt(x^2) + sqrt(1-x^2)
The values of x are between -1 and 1.

Go ahead and load this file on your ColdFusion server. It will nicely draw the following image: (more…)

ColdFusion: cfquery and the SQL insert statements

Written on 12 March 2011, 01:09pm

Tagged with: , ,

Say you have a cfquery statement which does a simple insert in a table in your database:

<cfquery name="query_name" result="result_name">
INSERT INTO mytable(id,name) VALUES(1,'foo')

This post presents two very useful and least documented features of the cfquery tag.

1. How to get the newly inserted ID

The ColdFusion 9 documentation offers several solutions depending on your database:

3 things you probably did not know about cfcache

Written on 8 March 2011, 12:03am

Tagged with: ,

Note, February 17th 2014: this post was written on March 8th 2011, but I forgot to publish it. So here it is, almost 3 years later 🙂

I recently had to work with cfcache in ColdFusion 9 and I found a few interesting things. Two of them deal about the backwards compliance in ColdFusion 9, while the third is about caching page fragments.

  1. cfcache default action
    The default action of the cfcache tag changed from ColdFusion 8 to ColdFusion 9:

    • in ColdFusion 8, default action is cache (server-side and client-side caching)
    • in ColdFusion 9, default action is serverCache (server-side caching only)
  2. using cfcache to cache pages with URL parameters
    I found this one while reading the ColdFusion 9 book, volume 2.

  3. caching page fragments: ColdFusion stores the cfcache tag line number as part of the ID for the cached item.
    This one is a little bit more complicated and I found it on the Rob Brooks-Bilson‘s blog while reading about the second point above (caching pages with URL params).
    It deals with the number of items in the ColdFusion cache when the cfcache tag is used to cache page fragments.

    If you have a cfcache tag in your code, your cache will contain one item.
    If you change the position of the cfcache tag (you move it one line below), your cache will contain two items.
    You can read the cache content using the getAllTemplateCacheIds() function.
    The example in the link above is pretty suggestive.

    Each page fragments gets its own entry in the cache since fragments can be independently expired or flushed from the cache. […] What’s happening is that ColdFusion is using the position of the code in your page as part of the ID for the cached item.