Log analyzer plugin for Railo admin
A briljant and long missing plugin for log analyzing within the admin of Railo. Made by my good friend Paul Klinkenberg, a must have for every Railo user.
4091 viewed | Your opinion... | Tjarko @ 11:03 cet


All files are strictly confidential: all information is classified.
© Copyright 2002 - 2013 mximize.com.
All right reserved.
A briljant and long missing plugin for log analyzing within the admin of Railo. Made by my good friend Paul Klinkenberg, a must have for every Railo user.
4091 viewed | Your opinion... | Tjarko @ 11:03 cet
8252 viewed | 16 opinion(s) | Tjarko @ 17:19 cet
7363 viewed | 1 opinion(s) | Tjarko @ 12:13 cet
7400 viewed | 1 opinion(s) | Tjarko @ 9:48 cet
<cfset stAllow = structNew() />
<cfset stAllow["image"] = "jpg,gif,png,jpeg" />
<cfset stAllow["file"] = "doc,xls,pdf,rtf,txt" />
<cfset stAllow["application"] = "zip,rar,doc,pdf,xls,ppt,swf,flv,txt" />
<cfset stAllow["audio"] = "mp3,mpa,mpg,ra,wav" />
<cfset stAllow["video"] = "mov,qt,mpeg,mp3,mpa,mpg" />
<cfset stAllow["text"] = "txt,htm,html,log,css" />
<cfif structKeyExists(stAllow, file.contenttype) && listFindNoCase(stAllow[file.contenttype],file.serverfileext)>
You may pass...
<cfelse>
You will NOT pass!!!
<!--- Delete the file or something --->
</cfif> 6589 viewed | 2 opinion(s) | Tjarko @ 12:27 cet
4864 viewed | 22 opinion(s) | Tjarko @ 10:04 cet
<cffunction name="isMobile" returntype="boolean">
<cfset var ret = false />
<cfif cgi.http_accept contains "text/vnd.wap.wml" || cgi.http_accept contains "application/vnd.wap.xhtml+xml" || structKeyExists(cgi,"HTTP_X_WAP_PROFILE")>
<cfset ret = true />
<cfelseif findNoCase("iphone", cgi.http_user_agent)>
<cfset ret = true />
</cfif>
<cfreturn ret />
</cffunction>
<cfoutput>
Is it a mobile? #yesNoFormat(isMobile())#
</cfoutput> 8145 viewed | 2 opinion(s) | Tjarko @ 22:21 cet
<cfset var = 1 />
<cfif !var>
Do something
</cfif>
To use ! is the same as using NOT in the cfif statement. Pretty darn nice!! Probably old news but for me it was something I never saw anywhere in CF code.5455 viewed | 7 opinion(s) | Tjarko @ 17:33 cet
5376 viewed | 9 opinion(s) | Tjarko @ 7:48 cet
16139 viewed | 18 opinion(s) | Tjarko @ 12:10 cet
4647 viewed | Your opinion... | Tjarko @ 13:05 cet
9081 viewed | 15 opinion(s) | Tjarko @ 16:38 cet
5731 viewed | 2 opinion(s) | Tjarko @ 11:37 cet
4412 viewed | Your opinion... | Tjarko @ 11:55 cet
<cfdocumentitem type="footer">
<cfif cfdocument.currentpagenumber eq 1>
Do this only on the first page
</cfif>
</cfdocumentitem> 4817 viewed | 2 opinion(s) | Tjarko @ 15:04 cet
<!---Read the image into an object --->
<cfimage action="read" name="myImage" source="65.jpg">
<!--- Set the square size of the thumb --->
<cfset sq_size = 200>
<!--- Write the result to a file. --->
<cfset ImageSetAntialiasing(myImage,"on")>
<cfset ImageScaleToFit(myImage,sq_size,sq_size)>
<!--- Calculate the x and y position to paste the image --->
<cfif myImage.width GTE myImage.height>
<cfset x = 0>
<cfset y = ceiling((myImage.width - myImage.height)/2)>
<cfelse>
<cfset x = ceiling((myImage.height - myImage.width)/2)>
<cfset y = 0>
</cfif>
<cfset newimg = ImageNew("",sq_size, sq_size, "rgb", "FF0000")>
<cfset ImagePaste(newimg, myImage, x, y)>
<cfimage action="WRITETOBROWSER" source="#newimg#" format="JPG"> 
15710 viewed | 6 opinion(s) | Tjarko @ 12:29 cet
<!--- Create square --->
<cfimage source="#org_img#" name="myImage">
<!--- See which side is bigger --->
<cfif myImage.width GTE myImage.height>
<cfset y = 0>
<cfset x = ceiling((myImage.width - myImage.height)/2)>
<cfset dimension = myImage.height>
<cfelse>
<cfset x = 0>
<cfset y = ceiling((myImage.height - myImage.width)/2)>
<cfset dimension = myImage.width>
</cfif>
<cfoutput>
x= #x#<br />
y= #y#<br />
w= #myImage.width#<br />
h= #myImage.height#<br />
dim= #variables.dimension#<br />
</cfoutput>
<cfset ImageCrop(myImage,x,y,dimension,dimension)>
<cfimage action="WRITETOBROWSER" source="#myImage#" format="JPG"> What I do is the following, first I check which side is bigger. For the CROP action I need the correct x,y values and the way to get those is by calculating the longest side minus the shortest and divide that by two. ceiling(longest-shortes)/2) The ceiling function will make it a nice round number.
I can now use these values to CROP the image into a nicely calculating square. After that I could resize the image to every dimension i would like, in my case 100x100
8931 viewed | 1 opinion(s) | Tjarko @ 14:58 cet
SELECT pset.pst_urlsave
,pset.pst_name
,photo.pho_id
FROM photo INNER JOIN photoset pset ON pset.pst_id = photo.pho_pst_id SELECT photoset.pst_urlsave
,photoset.pst_name
,photo.*
FROM photo INNER JOIN photoset ON photoset.pst_id = photo.pho_pst_id 5997 viewed | 8 opinion(s) | Tjarko @ 11:31 cet
4192 viewed | Your opinion... | Tjarko @ 10:13 cet
You probably encountered this lot's of times, the need for a simple next / prev function to page thru your recordset. If not... uhm.. yeah.. ok.. continue. What I created is a simple function that will calculate the x pages to view and will give you back some variables that you can use to create your own navigation set. First let me show you the function. <!--- Next x record function --->
<cffunction name="nextXpage" access="public" returntype="struct" hint="Next x page function" output="No">
<cfargument name="recordcount" required="Yes" default="0" type="numeric" hint="The total numbers of records / values">
<cfargument name="page" required="Yes" type="numeric" default="0" hint="The page number that you are currently on. (for example URL.page)">
<cfargument name="maxrows" required="No" type="numeric" default="10" hint="The maximum records / values to be displayed per page">
<!--- Define the return structure --->
<cfset var nextXpage = structNew()>
<!--- Calculate how much page are available according to the maxrows displayed --->
<cfset nextXpage.pagecount = CEILING(arguments.recordcount / arguments.maxrows)>
<!--- Set the maximum rows to be displayed --->
<cfset nextXpage.maxrows = arguments.maxrows>
<!--- Set the currentpage --->
<cfset nextXpage.currentpage = arguments.page>
<!--- Set the currentpage --->
<cfset nextXpage.recordcount = arguments.recordcount>
<!--- Set the startrow value --->
<cfif arguments.page eq 1>
<cfset nextXpage.startrow = 1>
<cfelse>
<cfset nextXpage.startrow = (arguments.page * arguments.maxrows) - (arguments.maxrows -1)>
</cfif>
<!--- Define the previous and next values. --->
<!--- Next values --->
<cfif arguments.page neq nextXpage.pagecount>
<cfset nextXpage.next = true>
<cfset nextXpage.nextpage = arguments.page + 1>
<cfelse>
<cfset nextXpage.next = false>
<cfset nextXpage.nextpage = 1>
</cfif>
<!--- Previous values --->
<cfif arguments.page eq 1>
<cfset nextXpage.previous = false>
<cfset nextXpage.previouspage = 1>
<cfelse>
<cfset nextXpage.previous = true>
<cfset nextXpage.previouspage = arguments.page - 1>
</cfif>
<!--- Return the structure --->
<cfreturn nextXpage>
</cffunction>
As you can see the function needs 2 values to work and one is and those are the total numbers of records you have,the page you are on (default 1) and the maximum rows you would like to show on your page (default 10). Put this functionbetween cfcomponent tags and save as functions.cfc. Below is the code to make this all work. <cfparam name="URL.page" default="1">
<!--- Determine the navigation parameters --->
<cfset functions = createobject("component","functions")>
<cfset nav = functions.nextXpage(somequery.recordcount,URL.page,15)>
The function will now return a structure with variables you can use to build your own navigation for paging thru the recordset. I normally use the following to let the user see on which page he/she is and how many pages there still are. <cfoutput>
#nav.recordcount# items (page #nav.currentpage# of #nav.pagecount#)
<cfif nav.previous>
<a href="somepage.cfm?page=#nav.previouspage#">Previous</a>
<cfelse>
Previous
</cfif>
<cfif nav.next>
<a href="somepage.cfm?page=#nav.nextpage#">Next</a>
<cfelse>
Next
</cfif>
</cfoutput>
As you can see, a simple way of paging a recordset. There are probably much better ways of doing this but until my favorite server MSSQL (still 2000 i'm afraid) doesn't include paging query's I keep on using this bit of code to browse my recordsets
Oeps.. forgot a major piece of code to let all this work correctly!!! You have to set your cfoutput tag with the following settings.
<cfoutput query="yourquery" startrow="#nav.startrow#" maxrows="#nav.maxrows#">
<!--- Output here --->
</cfoutput> 10982 viewed | 1 opinion(s) | Tjarko @ 15:40 cet
<cffunction name="isDateBetween" returntype="boolean" output="false">
<cfargument name="dateObj" required="yes" type="date">
<cfargument name="start" required="yes" type="date">
<cfargument name="end" required="yes" type="date">
<cfreturn yesnoformat((DateCompare(dateObj, start) gt -1) AND (DateCompare(dateObj, end) lt 1))>
</cffunction> <cffunction name="isDateBetween" returntype="boolean" output="false">
<cfargument name="dateObj" required="yes" type="date">
<cfargument name="start" required="yes">
<cfargument name="end" required="yes">
<cfset var ret = 0>
<cftry>
<cfif yesnoformat((DateCompare(dateObj, start) gt -1) AND (DateCompare(dateObj, end) lt 1))>
<cfset ret = 1>
</cfif>
<cfcatch>
<!--- Do nothing, wrong dates or no dates --->
</cfcatch>
</cftry>
<cfreturn ret>
</cffunction>5181 viewed | 1 opinion(s) | Tjarko @ 14:31 cet
<cfset msg_digest = hash(hex_key)>
<cfset msg_digest = hash(hex_key,"SHA")>
<cfset msg_digest = hash(hex_key,"SHA-256")> <cfset msg_digest = hash(hex_key,"RipeMD160")> 4938 viewed | 1 opinion(s) | Tjarko @ 23:04 cet
If you do not specify the scope of the variable, according to the docs, CF will search for it in the following order (this is called the order of precedence):
Other scopes always need to be scoped:
10053 viewed | 6 opinion(s) | Tjarko @ 15:33 cet
<cfset id = lcase(listLast(cgi.query_string,"/"))>
<cfquery datasource="">
SELECT title, description
FROM article
WHERE art_urlsave = '#variables.id#'
</cfquery>
<cfset art_urlsave = lcase(rereplace(form.art_title, "[^A-Za-z0-9]+", "-", "all"))>
<cfquery datasource="">
INSERT INTO article (art_title, art_urlsave, art_description)
VALUE ('#form.art_title#', '#variables.art_urlsave#', '#form.art_description#')
</cfquery> <a href="/#art_urlsave#">how to get search...</a> 8815 viewed | Your opinion... | Tjarko @ 11:02 cet
For a project that i am working on at the moment I needed some commentspam protection. Project Honeypot is an project (really?!!) that collects IP addresses of harvesters, spammers and other people/computers you don't want on your website.
You can register with them and use the code below to protect your comments with there Reverse DNS tools. The function returns the threat value, type value and how many days ago the IP address was recognized as a spammer/harvester. Based on those return values you can for yourself create a system that blocks the IP address.
I give back an 404 page to all IP addresses with a type of 4 and more. See code below.
<!--- Check Project HoneyPot --->
<cfinvoke returnvariable="stCheck" method="honeypotcheck" component="cfc.dns">
<cfinvokeargument name="ip" value="#cgi.remote_host#" />
</cfinvoke>
<!--- Don't display the personal information --->
<cfif isDefined("stCheck") AND (stCheck.type GTE 4 AND stCheck.type LTE 7)>
<!--- Send 404 message --->
<cfheader statuscode="404" statustext="Not Found">
404 Not Found
<cfabort>
</cfif>
Below the code of the component i've written. Just copy paste and it should work just fine.
<cfcomponent displayname="DNS functions">
<cffunction name="gethostaddress" returntype="string">
<cfargument name="host" required="Yes" type="string" />
<cfset var obj = "">
<!--- Init class --->
<cfset obj = CreateObject("java", "java.net.InetAddress")>
<!--- Return result --->
<cfreturn obj.getByName(host).getHostAddress()>
</cffunction>
<cffunction name="reverseip" returntype="string">
<cfargument name="ip" required="Yes" type="string" />
<cfset var aIp = listToArray(arguments.ip,".")>
<!--- Return IP reversed --->
<cfreturn aIp[4] & "." & aIp[3] & "." & aIp[2] & "." & aIp[1]>
</cffunction>
<cffunction name="honeypotcheck" returntype="struct" hint="Check Project HoneyPot http:BL">
<cfargument name="ip" required="yes" type="string">
<cfset var aVal = "">
<cfset var hpkey = "-- your honepot key --">
<cfset var stRet = structNew()>
<!--- Get the different IP values --->
<cfset aVal = listToArray(gethostaddress("#hpkey#.#reverseip(arguments.ip)#.dnsbl.httpbl.org"),".")>
<!--- Set the return values --->
<cfset stRet.days = aVal[2]>
<cfset stRet.threat = aVal[3]>
<cfset stRet.type = aVal[4]>
<!--- Get the HP info message --->
<cfswitch expression="#aVal[4]#">
<cfcase value="0">
<cfset stRet.message = "Search Engine (0)">
</cfcase>
<cfcase value="1">
<cfset stRet.message = "Suspicious (1)">
</cfcase>
<cfcase value="2">
<cfset stRet.message = "Harvester (2)">
</cfcase>
<cfcase value="3">
<cfset stRet.message = "Suspicious & Harvester (1+2)">
</cfcase>
<cfcase value="4">
<cfset stRet.message = "Comment Spammer (4)">
</cfcase>
<cfcase value="5">
<cfset stRet.message = "Suspicious & Comment Spammer (1+4)">
</cfcase>
<cfcase value="6">
<cfset stRet.message = "Harvester & Comment Spammer (2+4)">
</cfcase>
<cfcase value="7">
<cfset stRet.message = "Suspicious & Harvester & Comment Spammer (1+2+4)">
</cfcase>
<cfdefaultcase>
<cfset stRet.message = "IP-Address not known">
</cfdefaultcase>
</cfswitch>
<cfreturn stRet>
</cffunction>
</cfcomponent>
42532 viewed | 6 opinion(s) | Tjarko @ 12:38 cet
I'm really bad at remembering how to do certain things, one of them is the header statuscodes in ColdFusion. Today I was... again... looking for the piece of code to give back a 301 statuscode for a job detailpage that didn't exist anymore. You have that sometimes with jobsites.. that jobs that where ones open are now closed... :-)
After searching on the internet with the wrong words I finally found the piece of code I needed! And because this site is my personal "do not forget this solution" archive, i'm placing it here.
<cfheader statuscode="301" statustext="Moved permanently">
<cfheader name="Location" value="http://www.mximize.com">
<cfabort>
Off course you need to wrap this in a
<cfif>
or something to only give this message back when an article, job or whatever does no longer exist on your website.
If you want to give back a "404 Not found" than the code would be this.
<cfheader statuscode="404" statustext="Not found">
<cfabort>
Oh.. and i place the
<cfabort>
there because I don't want to process the page further then this statuscode i'm giving back.
9308 viewed | 4 opinion(s) | Tjarko @ 21:18 cet
I would like Coldfusion to execute my robots.txt file. In the web.xml I already added the following servlet-mapping
<servlet-mapping id="macromedia_mapping_14">
<servlet-name>CfmServlet</servlet-name>
<url-pattern>*.txt</url-pattern>
</servlet-mapping>
But after restarting the ColdFusion service it did not work... I get a 403 error page...
I do have a wildcard application mapping in IIS 6 (windows 2003) but that should pick up the web.xml file... wouldn't??
Thanks for any help in the right direction!!
10799 viewed | 2 opinion(s) | Tjarko @ 16:34 cet
When you get the following error while using a component in ColdFusion MX 6.x or 7 then there is a simple solution for it.
AXIS error
Could not resolve CFC datatype
etc....
The solution is this. Go to your ColdFusion Administrator mappings and find the mapping "/" if this is not there find the mapping with the same name as your first subdir... hmmm an example is better i think.
http://yourdomain.com/cfc/mycomponents/com.cfc?wsdl
Search for a mapping "/cfc".. if its there and it does not point to the same dir as where "mycomponents" is in, then that's your problem. The same for the "/" mapping.. if that point's to a different directory.
The solution:
Make a mapping that points to the same place as where your components are.
7042 viewed | 1 opinion(s) | Tjarko @ 10:33 cet
Strip all except numbers and letters
<cfset newstr = rereplace(str, "[^A-Za-z0-9]+", "", "all")>
Strip all except numbers
<cfset newstr = rereplace(str, "[^0-9]+", "", "all")>
Strip all except CAPITAL letters
<cfset newstr = rereplace(str, "[^A-Z]+", "", "all")>
You get the point, this post is just for my own records. I keep forgetting how to do this and now I can look it up on my own blog.. thank god for that!!
18955 viewed | 7 opinion(s) | Tjarko @ 21:39 cet
<cffunction name="initcap" returntype="string" output="no">
<cfargument name="str" required="yes" type="string">
<cfset var capStr = "">
<!--- Uppercase the first character --->
<cfset capStr = ucase(left(arguments.str,1)) & lcase(mid(arguments.str,2, len(arguments.str)-1))>
<cfreturn capStr>
</cffunction>
9843 viewed | 8 opinion(s) | Tjarko @ 12:35 cet
En weer gaan we richting London!! Dit keer omdat er een nerd bijeenkomst is van alle ColdFusion developers in en rond Europa. CFDevcon (http://www.cfdevcon.com) is een evenement georganiseerd door developers voor developers.. kortom.. relaxte sfeer en hopelijk wat nieuwigheidjes binnen het CF wereldtje....
Als er nog wat mensen gaan op 8 November tot 10 November dan stel ik voor om op 9 November ergens in London wat af te spreken om te eten en drinken.. ja Remy.. zoek maar weer wat leuks uit! ;-)
4746 viewed | Your opinion... | Tjarko @ 13:58 cet
When you make use of a function to strip whitespace, like for instance the two examples I have on this site (see below) you have to make sure that you have commented your javascript in the right manner, otherwise you don't get the result you want.
Strip whitespace will remove all linebreaks, tabs en double spaces from your code.. and the tricky part is the linebreaks. Take a look at this piece of code.
<script>
//alert the user.
alert('Eeej!!');
</script>
After strip whitespace the complete statement has become a comment, because you didn't close the comment.
<script>//alert the user. alert('Eeej!!');</script>
Correct way of having comments in your code is like this.
<script>
/* alert the user. */
alert('Eeej!!');
</script>
This way the code won't break down when you use a whitespace removal script or tool. Also important in this manner is the use of the ; to close every line of code!!
links:
http://www.mximize.com/index.cfm?searchword=whitespace
8968 viewed | Your opinion... | Tjarko @ 11:26 cet
For a big global application that is currently being developed by my company Carlos Gallupa (http://carlosgallupa.com) I need the following...
Is there a component that can give me based on the used Locale of my application a correct mask/hint on the used dateformat?? We here in the Netherlands use the dateformat dd/mm/yyyy and if I use LSparsedatetime on this while setting te locale to "dutch (standard)" this works great... an vice versa for US dates. But here comes the problem!!!
When my Locale is set dynamicly to a certain Locale, my application does not know what the "mask/hint" of the Locale should be.. in other words "dd/mm" or "mm/dd".
Can someone point me to a good source for answering this question? The best thing would be something like this.
<cfset setLocale("dutch (standard)")>
<cfset stLocale= getlocale()>
<cfoutput>
#stLocale.name# translates to "dutch (standard)"
#stLocale.datemask# translates to "dd/mm/yyyy"
</cfoutput>
8865 viewed | 8 opinion(s) | Tjarko @ 22:55 cet
It's been quiet for quite some time on this blog and i'm sorry to say that that will be the case for quite some time (weeks).The reason is this, I started my own company http://carlosgallupa.com and that takes up a lottatime. But.. yes there is a but, mximize.com will continue, and better than ever!The future of mximize will be a ColdFusion,xHTML and CSS related topics.
4723 viewed | Your opinion... | Tjarko @ 20:15 cet
Sometimes you have a construction where you have to have a query output inside a query output inside a.... a well you get the picture. When the inner query output needs a variable from the outer query output and you reference the query with it's scope "queryname.variable" then most of the time you end up with getting the first row of your outer query... not what you want!!
So I normally would <cfset> the outer query variable to a local and use that in the inner query. Works fine!
I was just sitting in the train and thought of a rowcopy function so you can copy an entire row of data in a single structure. Don't know exactly the good use for it but here it is anyways...
<cffunction name="rowCopy" returntype="struct" output="No">
<cfargument name="q" required="Yes" type="query">
<cfargument name="rowindex" required="Yes" type="numeric">
<cfset var ret = structNew()>
<!--- Loop over the columnlist and get the rowindex needed. --->
<cfloop list="#q.columnlist#" index="column">
<cfset ret[column] = q[column][rowindex]>
</cfloop>
<cfreturn ret>
</cffunction>
<cfoutput query="SomeQuery">
<cfset row = rowCopy(qTest,currentRow)>
<cfloop query="OtherQuery">
<cfif row.id eq otherquery.id>
#row.name#
</cfif>
</cfloop>
</cfoutput>
Too bad you can't do
<cfset row = qTest[currentRow]>
If someone knows an easier way or better.. a better way, please feel free.
17824 viewed | 15 opinion(s) | Tjarko @ 18:20 cet
<cfset wsdl="http://domain/service.cfc?wsdl">
<cfset factory = CreateObject("JAVA", "coldfusion.server.ServiceFactory")>
<cfset rpcService = factory.XmlRpcService>
<cfset rpcService.refreshWebService(wsdl)> 7106 viewed | Your opinion... | Tjarko @ 13:49 cet
Bummer... I thought this was a done deal after the cookies and all, but it seems that you can't have a <cflocation> after a <cfloginuser>.
So what I did now is build a bit of logic around the <cflogin> tag to enable this. When a user is logged in I also give him/her a few session variables to work with, such as the name of the person. I now look if this variable exists and if not show the login form inside my <cflogin> logic.
<cfif NOT isDefined("session.user.name")>
<!--- To make sure when the session was 'killed' the 'maybe' logged in user also logs out --->
<cflogout>
<!--- Show the page with the form and login logic --->
<cfinclude template="inc_login.cfm">
<cfif len(GetAuthUser())>
<!--- Send to own personal website --->
<cflocation url="/?app_id=#qGetLogin.usr_app_id#">
</cfif>
<cfelse>
show message that session.user.name is logged in
</cfif>
This works fine now!!
8562 viewed | Your opinion... | Tjarko @ 0:08 cet
A millisecond freak.. if that's a term for it is what I am, and one of the things that makes your application go blazing fast is caching your query resultsets into the memory of your server.
Drawbacks of caching in memory is that you also need a way of "refreshing" the resultset. One way of doing this is putting all your database traffic statements into a CFC (best practice) and make sure that a change to the database will also trigger a "refresh" of your resultset.
Ok.. let's show an example CFC that will get reactions posted by users on a blog.
The extends attribute points to a settings.cfc that holds certain functions and variables. All my cfc's look at settings.cfc and settings.cfc in it's turn looks at functions.cfc but that all together is worth a different blog.
<cfcomponent extends="settings">
<cffunction name="getreactions" access="public" returntype="query" output="false">
2 arguments for getting the reactions for a certain log and a refresh parameter to refresh the content for the cached query
<cfargument name="log_id" required="no" type="string">
<cfargument name="refresh" required="no" type="boolean" default="0">
<cfset var qry_recordset = "">
If the query isn't already cached or you need to refresh, then execute a SQL statement that will get the resultset from your database
<cfif NOT isDefined("application.recordsets.reactions") OR arguments.refresh>
<cfquery name="qry_recordset" datasource="#this.dsn[1]#">
SELECT columns
FROM reactions rec JOIN logfiles log ON log.log_id = rec.rec_log_id
</cfquery>
Save the resultset in your application scope, the variable application.recordsets is defined as a new structure "structNew()" in my Application.cfc on startup.
<cfset application.recordsets.reactions = qry_recordset>
<cfelse>
When the query is already cached, go get the information from the cached query instead of your database (saves milliseconds ;-))
<cfquery name="qry_recordset" dbtype="query">
SELECT columns
FROM application.recordsets.reactions
WHERE 0 = 0
<cfif isDefined("arguments.log_id") AND len(arguments.log_id)>
AND log_id = '#arguments.log_id#'
</cfif>
</cfquery>
</cfif>
<cfreturn qry_recordset>
</cffunction>
The next function is an insert statement to add a reaction to the database, after the insert we call the above function with the refresh argument set to TRUE because that will "refresh" the cache, and the content is updated.
<cffunction name="insert_reactions" access="public" returntype="string" output="false">
<cfargument name="stForm" required="yes" type="struct">
<cfquery name="insert" datasource="#this.dsn[1]#">
INSERT INTO reactions (column)
VALUES ('#stForm.value#')
</cfquery>
Refresh applicaton var
<cfset qTmp = getreactions(refresh=1)>
</cffunction>
</cfcomponent>
By now you will probably get the basics and figure out for yourself that the update en delete functions are also in the same CFC and that they also "refresh" the cached query. This way I always use the cached query instead of going to my database each and everytime.
11767 viewed | 1 opinion(s) | Tjarko @ 10:41 cet
After coding yet another "#trim(form.var)#" statement in a <cfquery> or some other piece of code a couple of years back, I was thinking that this was a total waste of code... so I came up with the following solution that is now permanetly in my Application.cfm or Application.cfc.
This piece of code will make sure that you never have to think about trimming your form scope again, it is always done automaticly.
<!--- Check if there is a form being submitted --->
<cfif isDefined("form.fieldnames")>
<cfloop collection="#form#" item="formfield">
<cfset form[formfield] = trim(form[formfield])>
</cfloop>
</cfif>
This method also works with every STRUCT scope there is within ColdFusion. (NOTE: it should be a scope you can overwrite, you can't overwrite the CGI scope by instance...)
5929 viewed | 5 opinion(s) | Tjarko @ 9:07 cet
After reading a comment from Dmitry Namiot that he posted on http://weblogs.macromedia.com/cantrell/archives/2005/01/eliminate_coldf.cfm, I tried it out.. but it didn't do what I wanted. Below I changed the code a bit so that I have all the control on what to strip and what not. I didn't want the code to be on 1 line.. for that you can just use the regular expression. "[[:space:]]{2,-}"... I wanted to have a certain control on what and how my code was stripped.
Put the code below in an onRequestEnd.cfm and see what it could do for your bandwidth!! A better solution is always welcome :-)
Oh.. and the servlet idea on the above post didn't do it for me.. it had problems with RDS, cflocation etc, etc.
<!--- copy the current contents of out (which is what cfmx will send to the browser at the end of processing) --->
<cfset pageContent = getPageContext().getOut().getString()>
<!--- now we have a copy, clear the out buffer --->
<cfset getPageContext().getOut().clearBuffer()>
<!--- tidy up --->
<cfset pageContent = reReplace(pageContent, chr(9),"", "all" )>
<cfset pageContent = reReplace(pageContent, " ","", "all" )>
<cfset pageContent = reReplace(pageContent, chr(13)&chr(10)&chr(13)&chr(10),chr(13)&chr(10), "all" )>
<cfset pageContent = reReplace(pageContent, chr(10)&chr(13),"", "all" )>
<!--- send our cleaned content to the browser --->
<cfset writeOutput(pageContent)>
<cfset getPageContext().getOut().flush()>
<!--- job done! --->
6258 viewed | Your opinion... | Tjarko @ 12:58 cet
I needed a simple function to convert a query to an array of structures, www.cflib.org provided one but I found that a bit 'out of date', so I wrote a new one to implement in my standard function component.
<cffunction name="querytoarray" returntype="array" output="No">
<cfargument name="q" required="Yes" type="query">
<cfset var aTmp = arraynew(1)>
<cfif q.recordcount>
<cfloop query="q">
<cfset stTmp = structNew()>
<cfloop list="#lcase(q.columnlist)#" index="col">
<cfset stTmp[col] = q[col][currentRow]>
</cfloop>
<cfset arrayAppend(aTmp,stTmp)>
</cfloop>
<cfelse>
<cfset stTmp = structNew()>
<cfloop list="#lcase(q.columnlist)#" index="col">
<cfset stTmp[col] = "">
</cfloop>
<cfset arrayAppend(aTmp,stTmp)>
</cfif>
<cfreturn aTmp>
</cffunction>
<cfset aRecordset= querytoarray(qRecordset)>
<cfdump var="#aRecordset#">
The reason I need this conversion is because I want to be able to change the 'default' values of a specific query cell... and because you can't change a recordset... wait a minute.. I just tested this on my MX7.01 server and you CAN overwrite a query recordset like this.
<cfset qRecordset.column[1] = "different value">
<cfdump var="qRecordset">
Hmmmm interesting.. do any of you know if this also works on MX6.x??
21470 viewed | 7 opinion(s) | Tjarko @ 12:01 cet
Below is the official statement made by the MacroMedia coding standards commitee ;-)
http://livedocs.macromedia.com/wtg/public/coding_standards/contents.html
"Determine the maximum size (in bytes) of each row. Take that size and determine how many times that number would divide into 32k. That number is your blockFactor, but be aware that the max blockFactor is 100. So, if for example you were getting 200 bytes per row, you could easily fit over 100 rows into the 32k buffer that CF 'grabs' at one time.
If you know at runtime that you will have less then 100 rows returned, for example you're writing a query that either returns 0 or 1 rows, do not bother adding the blockFactor attribute."
Therefore I made this function, you can just give it a resultset and it will give back the most appropiate blockfactor setting for your <cfquery> statement.
<cffunction name="getblockfactor" returntype="numeric">
<cfargument name="qResult" required="Yes" type="query">
<cfset var blockfactor = 0>
<cfset var rowBytes = "">
<cfset var aBytes = arrayNew(1)>
<cfset var totalbytes = 32768> <!--- 32 * 1024 (32Kb) --->
<cfloop query="qResult">
<cfset rowBytes = 0>
<cfloop list="#qResult.columnlist#" index="column">
<cfset rowBytes = rowBytes + len(qResult[column][currentRow])>
</cfloop>
<cfset arrayAppend(aBytes,rowBytes)>
</cfloop>
<cfset blockfactor = round(totalbytes / arrayAvg(aBytes))>
<cfif blockfactor GT 100>
<cfset blockfactor = 100>
</cfif>
<cfreturn blockfactor>
</cffunction>
<cfquery datasource="dsnName" name="qGet">
SELECT *
FROM table
</cfquery>
<cfoutput>
#getblockfactor(qGet)#
</cfoutput>
5702 viewed | Your opinion... | Tjarko @ 13:57 cet
Because ColdFusion has it's birthday soon the Dutch company www.zappwerk.nl will provide a BBQ for all Dutch developers. Go and register yourself, see you there!!
http://www.cfgefeliciteerd.nl (dutch)
4250 viewed | Your opinion... | Tjarko @ 10:22 cet
Like most of the developers, I use a / on all my HTML tags and also on my CFML tags.. at lease most of them. This morning I called a custom tag that was installed at a client's server, where I work at the moment and the application grinded to a halt... what was the case?
I called the custom tag like this.
<cf_answer name="something" returnvar="qGet" />
Nothing wrong with it, except that i'm used to having a start and end processing in my custom tags.
<cfswitch expression="#ThisTag.ExecutionMode#">
<cfcase value="Start">
<!--- Do things at the start --->
</cfcase>
<cfcase value="End">
<!--- Do things at the end, mostly nothing --->
</cfcase>
</cfswitch>
You probably can guess what was wrong with the application this morning and yes you're right.. the custom tag didn't have this mechanism, where you can skip the end processing of the custom tag. The / at the end told ColdFusion to process the tag again... (I knew this... but didn't think about it)
Before you go rolling on the ground laughing... it's just a reminder to all (like me) that are used to there own method of programming, to sometimes think back to why you program the way you do....
4109 viewed | 1 opinion(s) | Tjarko @ 14:43 cet
Hmmm... didn't test it with a radio button or a multiple select but a checkbox unchecked does exist as a form variable in the FORM scope!!
That one I didn't see coming...
3929 viewed | Your opinion... | Tjarko @ 14:43 cet
I have no idea where I got this little piece of code but sometimes it's quite handy to use. Keep track of the recent sessions in your application.
<!--- Create an application variable with the session Java tracker --->
<cfif not isDefined("application.tracker")>
<cfset application.tracker = createObject("java", "coldfusion.runtime.SessionTracker")>
</cfif>
<!--- Get the session information --->
<cfset sessions = application.tracker.getSessionCollection(application.applicationName)>
<cfoutput>
#StructCount(sessions)# sessions in the last 20 minutes.
<!--- Looping over the different session keys --->
<cfloop collection="#sessions#" item="sessionkey">
key = #sessionkey#<br/>
<cfloop collection="#sessions[sessionkey]#" item="keys">
#keys# = #sessions[sessionkey][keys]#<br/>
</cfloop>
<hr/>
</cfloop>
</cfoutput>
If you want to know a bit better which people are still online you good update a certain session variable with the time on each page... Let's say the Application.cfm
<cfset session.lastTimeVisited = now()>
Now you can be a "bit" more certain which people are still online and which are already gone.
5985 viewed | 1 opinion(s) | Tjarko @ 10:15 cet
Really simple code to gather songs in an application variable with ColdFusion in combination with the great but still not updated :-( Luke's Info Sender plugin for winamp.
http://www.neuro-tech.net/archives/000034.html
Install the plugin and point the url to a page where the code will save the songs played.
<cfif IsDefined("URL.song") AND len(trim(URL.song))>
<cfif IsDefined("application.winamp")>
<cfset aWinamp = duplicate(application.winamp)>
<cfelse>
<cfset aWinamp = arrayNew(1)>
</cfif>
<cfset stSong = structnew()>
<cfset stSong.name = URL.song>
<cfset stSong.time = now()>
<!--- Append to Array --->
<cfset ArrayPrepend(aWinamp, stSong)>
<cfset application.winamp = aWinamp>
</cfif>
<!--- Show the list --->
<cfif isDefined("application.winamp") AND not ArrayIsEmpty(application.winamp)>
<cfif arrayLen(application.winamp) LT 50>
<cfset to = arrayLen(application.winamp)>
<cfelse>
<cfset to = 50>
</cfif>
<cfloop from="1" to="#to#" index="i">
#application.winamp[i].name# #timeformat(application.winamp[i].time,'HH:mm:ss')# cet #dateformat(application.winamp[i].time,'dd mmm yy')#<br/>
</cfloop>
<cfelse>
Not listening at the moment
</cfif>
Or just display the last played item in your list.
<cfoutput>
#application.winamp[1].name#
</cfoutput>
I use this little script on my dutch blog under the "now listening" http://www.ditadres.com/?m=now button, you can see the last songs that went thru my winamp player.
7177 viewed | 2 opinion(s) | Tjarko @ 10:30 cet
A friend of mine build Pivot (www.pivotlog.net) and has HUGE problems with spam robots that are flooding the comments in all of his installations of Pivot. Because the tool is so widely used it's an easy target to write bots that read the form and post commercial content into the comments.
We tried a couple of things but none of them work.
- encrypted session vars that need to be the same in the form as in the session scope
- referer handling
- useragent checking (most bots use the same agent as a browser so no luck there)
- cookie checking (most bots these days also accept those)
- dynamic formfield names (worked for 3 hours)
- etc etc...
Do any of you have an idea?? It can't be a flash form so don't come with that answer :-)
May our force be strong against the dark empire that is called SPAM!! or something like that.. I think we need a battle cry too....
4355 viewed | 4 opinion(s) | Tjarko @ 13:08 cet
You can decide for security reasons, that you don't want your files stored in a webroot directory from which everyone could download the file. In this case you store your files in a directory that can't be accessed by the internet, but you can read thru coldfusion with the <cfile> or <cfdirectory> tag.
The following happens.. the client want's some files available for downloading but they have to be secured by the normal cflogin (or your own) procedure you already have in you site. When logged in you can then server the file to the client's machine like this.
<cfheader name="Content-Disposition" value="attachment; filename=thefilename.txt">
<cfcontent type="text/plain" file="c:\myfiles\somedocument.txt">
With these 2 lines the user gets to download the file with it's original name... works like a charm!! This way the file will also be downloaded to the client's machine and not within the browser itself. If you do not give the file a name, all files that are downloaded will be called "download.cfm" and that's not what you want i expect.
11050 viewed | Your opinion... | Tjarko @ 11:18 cet
I'm a music fan.. a big one and like lot's of others my music is digital available thru internet.. for authorized friends only that is!
A couple of years ago I made a little script that dynamicly created M3U playlist files for winamp, or any other program that could play a m3u file. (my personal favorite is winamp however)
M3u example
-----------------------------------------------------
#EXTM3U
#EXTINF:1,03 The Libertines - Don't Be Shy.mp3
http://play.domain.com/libertines_dont_be_shy.mp3
-----------------------------------------------------
First of all I wrote a <cfdirectory> page that showed all the different albums (dirs) from a specified directory on my server and at that moment I can click on an album and it will load into winamp to play the files. Below is the second step in the process.
<cfif isDefined("URL.album")>
<cfif NOT fileExists("E:\music\playlists\#URL.album#.m3u")>
<cfdirectory action="LIST" directory="E:\music\#URLdecode(URL.album)#" name="album" filter="*.mp3" sort="name">
<cfset lf = chr(13)& chr(10)>
<cfset PlayList = "##EXTM3U" & lf>
<cfoutput query="album">
<cfset PlayList = PlayList & "##EXTINF:#currentrow#,#album.name##lf#http://play.domain.com/#URLencodedformat(URL.album)#/#URLEncodedformat(album.name)##lf#">
</cfoutput>
<cffile action="WRITE" file="E:\music\playlists\#URL.album#.m3u" output="#PlayList#" addnewline="Yes">
</cfif>
<!--- Play the file in winamp --->
<cflocation url="http://www.domain.com/music/#URLEncodedFormat(URL.album)#.m3u" addtoken="No">
<cfelse>
<cflocation url="http://www.domain.com/music" addtoken="No">
</cfif>
The domain http://play.domain.com is a READ ONLY, SECURE domain that points to the music on my server, that way I can play my music from any location i'm at.
Oh.. just to let you know.. it's not available on this server.
7065 viewed | 1 opinion(s) | Tjarko @ 10:02 cet
If you have a mapping in Coldfusion MX there isn't an easy way to get the absolute directory that is associated with the mapping. Now there is!!
Let's assume that the name of the mapping is "/coldfusion" and the path is "c:\inetpub\websites\coldfusion", you can get the directory with the following function.
<!--- Get Directory from mapping name --->
<cffunction name="getDirectoryFromMapping" access="public" returntype="string">
<cfargument name="mapping" default="" required="Yes" type="string">
<cfset var runtime = "">
<cfset var map = "">
<!--- Get mapping object from JAVA --->
<cfobject action="CREATE" type="JAVA" class="coldfusion.server.ServiceFactory" name="factory">
<cfset runtime = factory.getRuntimeService()>
<!--- Search for mapping value in structure --->
<cftry>
<cfreturn StructFind(runtime.getMappings(),"/#arguments.mapping#")>
<cfcatch>
<cfreturn "No such mapping defined in the system....">
</cfcatch>
</cftry>
</cffunction>
<cfoutput>
#getDirectoryFromMapping('coldfusion')#
</cfoutput>
7072 viewed | 3 opinion(s) | Tjarko @ 11:05 cet
I needed a simple script to display a random image from a directory where users uploaded images to my server. This is the easiest way to implement it.
<!--- Let's read the directory but only the jpg images. --->
<cfdirectory action="LIST" directory="#expandpath('/~images/')#" filter="*.jpg" name="qImg" />
<!--- Display the image --->
<img src="/~images/#qImg.name[randrange(1,qImg.recordcount)]#" width="760" height="200" alt="" />
You could make it an applicaton variable and update the variable when a new image is present in the directory for better performance, but.... this script is just to show you a really.. REALLY simple way to do this task :-)
7683 viewed | Your opinion... | Tjarko @ 1:13 cet
It really isn't a nice script at all, so if you have a better solution please show me!!
The use: #ColorCoding(contentString)#
<cfscript>
function ColorCoding(CodeStr)
{
var NavyStr = "tit|f|b|h|!|l|d|p";
var TableStr = "table|tr|td";
var ScriptStr = "cfscript|script";
var ImgStr = "img";
CodeStr = REReplace(CodeStr,' |#chr(9)#',' ','all');
CodeStr = REReplace(CodeStr,'<','<','all');
// CodeStr = REReplaceNoCase(CodeStr,"(<(#NavyStr#)[^>]*>|</(#NavyStr#)[^>]*>)+","<font color=navy>\1</font>","all");
// CodeStr = REReplaceNoCase(CodeStr,"(<(#ScriptStr#)[^>]*>|</(#ScriptStr#)[^>]*>)+","<font color=maroon>\1</font>","all");
// CodeStr = REReplaceNoCase(CodeStr,"(<(#ImgStr#)[^>]*>|</(#ImgStr#)[^>]*>)+","<font color=purple>\1</font>","all");
// CodeStr = REReplaceNoCase(CodeStr,"(<(#TableStr#)[^>]*>|</(#TableStr#)[^>]*>)+","<font color=teal>\1</font>","all");
CodeStr = REReplaceNoCase(CodeStr,"(<cf[^>]*>|</cf[^>]*>)+","<font color=red>\1</font>","all");
CodeStr = REReplace(CodeStr,'("[^"]*")+','<font color=blue>\1</font>','all');
CodeStr = REReplace(CodeStr,'#chr(10)#','<br>','all');
Return CodeStr;
}
</cfscript>
3663 viewed | 1 opinion(s) | Tjarko @ 22:40 cet
I was looking for a small function that would give me back the age in years and the resulting value in decimals. So I created the following function to do just that.
<cffunction name="getAge" access="public" hint="Function that will give back age in years" output="No">
<cfargument name="dateStr" required="Yes" type="string" hint="A valid European date value dd/mm/(yy)yy">
<cfset var age = "unknown">
<cfif compareNoCase(dateStr,"NULL")>
<cftry>
<!--- Replace list character to / --->
<cfset datestr = replace(dateStr,"-","/","all")>
<cfif LSisDate(datestr)>
<!--- Convert list to array --->
<cfset aDate = listToArray(datestr,"/")>
<!--- Create US date format --->
<cfset USdate = CreateDate(aDate[3],aDate[2],aDate[1])>
<!--- Create valid ODBC date --->
<cfset age = datediff("yyyy",USdate,now())>
<cfset currentbirthday = dateadd("yyyy",age,USdate)>
<cfset extraAge = datediff("m",currentbirthday,now())/12>
<cfset age = age + extraAge>
<cfelse>
<cfset age = "no valid date">
</cfif>
<cfcatch>
<cfset age = "unknown error">
</cfcatch>
</cftry>
</cfif>
<cfreturn age>
</cffunction>
3604 viewed | Your opinion... | Tjarko @ 16:59 cet
I needed the yesnoformat function for a project that I am working on but the output shouldn't be English but Dutch.. So I wrote this function.. feel free to send me an e-mail to add a language
<cffunction name="LSyesnoformat" returntype="string">
<cfargument name="bool" required="Yes">
<cfset var rStr = "Value is not of type boolean! ">
<cfif isBoolean(arguments.bool)>
<cfswitch expression="#GetLocale()#">
<cfcase value="Dutch (Standard)"> <cfset rStr = IIF(arguments.bool,DE("Ja"),DE("Nee"))>
</cfcase>
<cfcase value="German (Standard)">
<cfset rStr = IIF(arguments.bool,DE("Ja"),DE("Nein"))>
</cfcase>
<cfcase value="French (Standard)">
<cfset rStr = IIF(arguments.bool,DE("Oui"),DE("Non"))>
</cfcase>
<cfcase value="Portuguese (Standard)">
<cfset rStr = IIF(arguments.bool,DE("Sim"),DE("Não"))>
</cfcase>
<cfcase value="Spanish (Standard)">
<cfset rStr = IIF(arguments.bool,DE("Sí"),DE("No"))>
</cfcase>
<cfcase value="Italian (Standard)">
<cfset rStr = IIF(arguments.bool,DE("Si"),DE("No"))>
</cfcase>
<cfdefaultcase>
<cfset rStr = yesNoFormat(arguments.bool)>
</cfdefaultcase>
</cfswitch>
</cfif>
<cfreturn rStr>
</cffunction>
3776 viewed | 1 opinion(s) | Tjarko @ 0:00 cet
<cffunction name="addWorkDays" returntype="date">
<cfargument name="datestr" default="#now()#" type="date">
<cfargument name="days" default="" required="Yes" type="numeric">
<cfset var tmpDate = arguments.datestr>
<cfset var i = 0>
<cfloop condition="i LT arguments.days">
<cfset tmpDate = dateadd("d",1,tmpDate)>
<!--- Check if day is a day within the workweek --->
<cfif DayOfWeek(tmpDate) GTE 2 AND DayOfWeek(tmpDate) LTE 6>
<cfset i = i + 1>
</cfif>
</cfloop>
<!--- Return the appropiate date --->
<cfreturn tmpDate>
</cffunction>
<cfset newdate = addWorkDays(now(),25)>
5145 viewed | Your opinion... | Tjarko @ 0:00 cet
Place in your application.cfm the following tag
<cferror type="EXCEPTION" template="dsp_error.cfm">
dsp_error.cfm could be something like this... it is actually what I always use in my applications, like mximize.com.
<html>
<head>
<title>Error occured</title>
</head>
<body>
An error occured and is logged by the system...
</body>
</html>
<cfmail to="yourmail@yourdomain" from="website@yourdomain" subject="an error occured on #cgi.server_name#" type="HTML">
<cfdump var="#error#" label="Error message">
<cfdump var="#session#" label="Session scope">
<cfdump var="#application#" label="Application scope">
<cfdump var="#request#" label="Request scope">
<cfdump var="#form#" label="Form scope">
<cfdump var="#url#" label="URL scope">
<cfdump var="#cookie#" label="Cookie scope">
</cfmail>
Now you get an exact view on all the variables used at the moment of the error in your mailbox.
7503 viewed | 1 opinion(s) | Tjarko @ 13:32 cet
Let's assume you know the character.. in this case a tab, and you wan't to know the chr() value.
<cfoutput>
#Asc(" ")#
</cfoutput>
Output is 9, you can use this number to place tabs in your code like this.
<cfset row = value1 & chr(9) & value2>
The result in this case is a tab-delimited row of records.
7632 viewed | Your opinion... | Tjarko @ 0:00 cet
Just came across some articles that explained the following, if you use ColdFusion MX it's better to check for a variable in their own scope structure than checking the variable with isDefined(). Why you ask... this is why... An isDefined() checks all the scopes for a particular variable even when you say isDefined("session.var"). This will still look in other scopes than the session scope.
In MX all the variables are structures and you can check if a variable is in a particular scope with StructKeyExists(scope,"var")
When checking for a variable it is therefore better to use StructKeyExists() because ColdFusion will only look in the given scope for the variable.
NOTE: Do not use the structKeyExists() with CFC's because the URL scope does not exist in a CFC, when not using URL parameters in your CFC you are good to go :-)
6392 viewed | 2 opinion(s) | Tjarko @ 0:00 cet
Let's say you want to display images from your network to your website visitors but don't want to place the images on the webserver or make the images available thru a network share on your server. In our case it was an ArcIms server that generate images on the local server within the network but the system administrators didn't want to open the webport to the outside world. We came with the following solution.
With the Coldfusion server in the DMZ we could do a HTTP call to the ArcIms server with <CFHTTP URL="http://arcims/image.jpg" method="get">.
next we used a Coldfusion method that is not documented but returns the cfhttp.filecontent as a binary value
<cfdump var="#cfhttp.filecontent.toByteArray()#">
we than used the following code to display the image to the page
<cfcontent type="image/jpeg" reset="Yes">
<cfoutput>#toString(cfhttp.filecontent.toByteArray())#</cfoutput>
We now could display pictures form different locations that we couldn't view as internet visitors. Next simple thing we did to control where the images showed up on the website was using the coldfusion page that processed these image as the source of the image tag.
<img src="thecfpage.cfm" width="400">
6932 viewed | 1 opinion(s) | Tjarko @ 16:24 cet
Sometimes you are creating a loop that shouldn't break on an error, for instance a scheduled task. The thing is that you never can tell what will happen once the task is running and the only thing you want is that, even when an error occurs that task will finish it's work.
The thing to do in that kind of situation is error handling, and what you do with the trapping of an error is totally up to you!
<cfloop from="1" to="#somenumber#" index="i">
<cftry>
<cfquery>
UPDATE IN DATABASE
</cfquery>
<cfcatch type="Any">
Trap all errors here and do something with it, send a mail or write to a logfile.
</cfcatch>
</cftry>
</cfloop>
The trick is that you don't abort or break the loop in the above example! When you don't do this the loop
will continue looping over it's elements until it is finished.
3455 viewed | Your opinion... | Tjarko @ 10:16 cet
Basically you can use the GetTickCount() function within ColdFusion for this.
<!--- Begin the count --->
<cfset start = gettickcount()>
<cfloop from="1" to="1000" index="i">
<!--- nothing --->
</cfloop>
<!--- End the count --->
<cfset end = gettickcount()>
<!--- Total time processing --->
<cfset time = end - start>
<cfoutput>
#time# milliseconds
</cfoutput>
3641 viewed | Your opinion... | Tjarko @ 13:59 cet
You can get this result with the following regular expression
<cfsavecontent variable="str">
<HTML>
<body>
This is the text you want
</BODY>
</html>
</cfsavecontent>
<cfset lowerstr = REReplace(str,"(<[^>]*>+)","\L\1","all")>
<cfoutput>
#lowerstr#
</cfoutput>
5856 viewed | Your opinion... | Tjarko @ 10:20 cet
Let's assume we only know the name of the table and we want to know the column names and there values of every record. The following example is a way to quickly get an insight of the table and it's data.
<cfquery datasource="#application.dsn#" name="qRecordset" blockfactor="100">
SELECT *
FROM yourtable
</cfquery>
<cfoutput>
<!--- Vertical loop --->
<cfloop from="1" to="#qRecordset.recordcount#" index="i">
<!--- Horizontal loop without knowing the columns in your table --->
<cfloop list="#qRecordset.columnlist#" index="column">
#column# = #qRecordSet[column][i]#<br />
</cfloop>
<hr />
</cfloop>
</cfoutput>
4882 viewed | Your opinion... | Tjarko @ 0:00 cet
<cfscript>
function CheckAsc(pw){
i = 1;
notAllowed = "44,46,59,64,124";
while (i LTE len(pw)){
nr = asc(mid(pw,i,1));
WriteOutput(nr & "<br>");
if (nr LT 33 OR nr GT 126 OR listFind(notAllowed,nr)){
return false;
break;
}
i = i + 1;
}
return true;
}
</cfscript>
<cfoutput>
#CheckAsc("ci.rcle")#
</cfoutput>
3796 viewed | Your opinion... | Tjarko @ 16:56 cet
<cfset list1 = "1,2,3,4,5,7,9">
<cfset list2 = "7,8,9">
<cfscript>
/*
Returns the first element found in list1 compared to list2
*/
function ListInListFind(List1, List2)
{
/* Loop through the first list
* Stop when first element is found in second list, otherwise continue
* Nothing found... return 0
*/
for (i=1; i LTE ListLen(List1); i=i+1) {
if (ListFindNoCase(List2, ListGetAt(List1, i))){
// Return position of found element in list1
return i;
break;
}
}
return 0;
}
</cfscript>
<cfoutput>#ListInListFind(list1,list2)#</cfoutput>
8234 viewed | Your opinion... | Tjarko @ 0:00 cet
You can use the following undocumented functions
cfusion_decrypt(string,key)
cfusion_encrypt(string,key)
string is the value to be processed and key is the value that you use for de- and encrypting the string.
3993 viewed | Your opinion... | Tjarko @ 0:00 cet
I've had it!!! this is the @#$% time that i struggled with the encoding of MX but I think I know now why this is....
MX first release you need this as your character code in the application.cfm
<cfcontent type="text/html; charset=ISO-8859-1">
<cfset setEncoding("URL", "ISO-8859-1")>
<cfset setEncoding("FORM", "ISO-8859-1")>
IN MX 6.1 you need this, because apparently the above doesn't work then anymore....
<cfcontent type="text/html; charset=CP1252">
<cfset setEncoding("URL", "CP1252")>
<cfset setEncoding("FORM", "CP1252")>
I hope I am correct in this.. if not.. please let me know!!
3604 viewed | Your opinion... | Tjarko @ 0:00 cet
Did you ever come across the following situation? A user can insert his own text strings for javascript validation and inserts a quote or some other character that f*cks up your javascript code....
The solution is to use #JSStringFormat(user input variable)# in your javascript code. Below a really really simple example to give you the idea how it is used.
<cfset userinput = "Heee you're are mad for inserting a quote!!">
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
alert('<cfoutput>#JSStringFormat(variables.userinput)#</cfoutput>')
//-->
</SCRIPT>
6235 viewed | Your opinion... | Tjarko @ 0:00 cet
I always use the buildin newid() function for the default value of my ID columns in SQL tables.... as datatype I always have char(36).
Sometimes however you need the ID already on your CF page itself. This small statement creates a MS unique identifier.
<cfset ID = insert("-", CreateUUID(), 23)>
I use it as a function like this:
<!--- Function that will give back a SQL newid() UUID syntax: CreateSQLID() --->
<cffunction name="CreateSQLID" access="public" returntype="GUID" output="no">
<cfreturn insert("-", CreateUUID(), 23)>
</cffunction>
3987 viewed | Your opinion... | Tjarko @ 0:00 cet
The following function will check if a given value is indeed a valid MS SQL ID.
<!--- Function that will check if variable is a SQL newid() UUID syntax: IsSQLID(value)--->
<cffunction name="IsSQLID" access="public" returntype="boolean" output="no">
<cfargument name="uuid" required="Yes" default="" type="string" hint="A GUID value to be checked.">
<cfreturn REFindNoCase("^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}",uuid)>
</cffunction>
4232 viewed | Your opinion... | Tjarko @ 0:00 cet
Use a custom tag and place it around the code that needs whitespace stripping!!
<cf_stripwhitespaces>
--- your code here ---
</cf_stripwhitespaces>
Below is the code that the custom tag stripwhitespaces should have.
<cfsetting enablecfoutputonly="YES">
<cfswitch expression="#ThisTag.ExecutionMode#">
<!--- Make sure a closing tag exists in calling template --->
<cfcase value="Start">
<cfif NOT ThisTag.HasEndTag>
<cfabort showerror="<CF_StripWhiteSpace> end tag not found.">
</cfif>
</cfcase>
<!--- When the closing tag is encountered... --->
<!--- Strip multiple whitespace characters from the content --->
<cfcase value="End">
<cfset ThisTag.GeneratedContent=REReplace(ThisTag.GeneratedContent, "[[:space:]]{2,}","","ALL")>
</cfcase>
</cfswitch>
<!--- Enable all standard output ---->
<cfsetting enablecfoutputonly="NO">
3958 viewed | Your opinion... | Tjarko @ 11:50 cet
When you have a site that lives in a 'live' environment and you want to see the debugging you have to go to the administrator to turn it on. You could also leave it on and put the next bit of code in your application.cfm
<cfif isdefined("URL.debug") AND URL.debug>
<cfsetting showdebugoutput="Yes">
<cfelse>
<cfsetting showdebugoutput="No">
</cfif>
You can now display debug info by adding a URL variable to your request.. like this
http://www.yourdomain.com/?debug=true
I added the "TRUE" bit because than you have to set this value... little bit more secure :-)
4231 viewed | Your opinion... | Tjarko @ 11:46 cet
This is a tricky one.. but it works perfectly. Install CF like your used to.
Install MX as a standalone version (port 8500). Check if everything is running on port 80 for CF5 and on port 8500 for MX. Now do the following to make MX available for your IIS webserver.
start / run and copy paste this line in the command line:
c:\cfusionmx\runtime\jre\bin\java -cp c:\cfusionmx\runtime\lib -jar c:\cfusionmx\runtime\lib\wsconfig.jar -ws IIS -site "0" -map .cfm,.cfc,.cfml,.jsp -v
MAKE SURE IT'S ON ONE LINE... copy paste to notepad and see if it is.
If you MX installion is not on the C drive but somewhere else just change the path.
Go to your IIS management module..
right click on the default website and go to properties
Click on the tab "home directory"
Click on the button "configuration"
Look up the "cfm,cfc,cfml" extenstion and check if the DLL that executes those extensions is the following path. "C:\CFusionMX\runtime\lib\wsconfig\1\jrun.dll" If so.. this site will be processed by MX.
If you want a site to be processed by CF5 just edit the extenstion and change the executable to the following one. "C:\CFusion\bin\iscf.dll" This is the DLL for coldfusion 5.
NOTE: when you make a new site it will automatically be configured to run MX now... if you don't want that just change the default IIS setting.. rightclick on the server and edit the www service under properties to use the CF5 executable described above.
So.. resume.
if you want a MX site make sure that the extension "cfm,cfml,cfc" is processed by "C:\CFusionMX\runtime\lib\wsconfig\1\jrun.dll"
otherwise it should be processed by "C:\CFusion\bin\iscf.dll"
Now you can run both versions on the same machine and still use IIS as the webserver. And you can run websites on their own IP addresses now.. and not just on 1 IP address with port 8500.
Good luck and don't do this on a PRODUCTION server!!! or i'm not the one to blame if it goes wrong :-)
3930 viewed | Your opinion... | Tjarko @ 10:53 cet
Why Macromedia didn't fix this problem in their MX updaters is a mystery to my but the solution to the following problem is this.
If you have a server running more then 1 website on the same IP then the following can occur. When you go to the index.cfm of one site and after that go to another on the same server it could be that it will display the previous webpage.
Solution:
In the directory \\CFusionMX\runtime\servers\default\SERVER-INF you will find a file named jrun.xml
In this file you have to change the following setting.
<attribute name="cacheRealPath">true</attribute>
to
<attribute name="cacheRealPath">false</attribute>
Save the file and restart the Coldfusion service in your services panel.
Now you can host multi-homed websites on your server.
4974 viewed | Your opinion... | Tjarko @ 11:27 cet
Set a variable for the tab character...
<cfset tab = chr(9)>
Set a variable for the string...
<cfset Str = "">
Get the recordset...
<cfquery name="myQuery">
SELECT * FROM table
</cfquery>
Output the fields with a tab character between the records...
<cfloop query="myQuery">
<cfset Str = Str & myQuery.Field1 & tab & myQuery.Field2 & tab & myQuery.Field3>
</cfloop>
Show Result...
<cfoutput>
<pre>
#Str#
</pre>
</cfoutput>
You can even write the result als a tab-delimited txt file at this point
<cffile action="write" output="#Str#" destination="c:\myFile.txt" addnewline="yes">
9660 viewed | 1 opinion(s) | Tjarko @ 16:37 cet
<cfset variables.Lf = chr(10)>
<cfset variables.CrLf = Chr(13) & Chr(10)>
<cfset Str = "This piece of text" & variables.LF & "had a linefeed or a " & variables.CrLf & "carriage return here">
<cfoutput>
<pre>
#Str#
</pre>
</cfoutput>
18721 viewed | 1 opinion(s) | Tjarko @ 16:30 cet
<cfmail from="Tjarko <tjarko@somedomain.com>" to="List Members <members@mylist.com>" subject="List Mailing">
Your e-mail here
</cfmail>
5682 viewed | 2 opinion(s) | Tjarko @ 16:08 cet
With the following code you get a directory view of the directory and all sub-dirs of the current directory. Name the file recursive.cfm otherwise it won't work
Only show directory tree:
<cfparam name="attributes.currentDir" default="#GetDirectoryFromPath(GetTemplatePath())#">
<cfdirectory directory="#attributes.currentDir#" action="list" name="getDir" sort="type">
<cfoutput query="getDir">
<cfif not compareNoCase(type,"dir")>
#name#<br>
<blockquote>
<cfmodule template="recursive.cfm" currentDir="#attributes.currentDir##name#\">
</blockquote>
</cfif>
</cfoutput>
Show directory and files:
<cfparam name="attributes.currentDir" default="#GetDirectoryFromPath(GetTemplatePath())#">
<cfdirectory directory="#attributes.currentDir#" action="list" name="getDir" sort="type">
<cfoutput query="getDir">
<cfif not compareNoCase(type,"dir")>
<strong>#name#</strong><br>
<blockquote>
<cfmodule template="recursive.cfm" currentDir="#attributes.currentDir##name#\">
</blockquote>
<cfelse>
#name#<br>
</cfif>
</cfoutput>
9576 viewed | Your opinion... | Tjarko @ 0:00 cet
If you do not specify the scope of the variable, according to the docs, CF will search for it in the following order (this is called the order of precedence):
Local variables, created using cfset and cfquery
CGI
File
URL
Form
Cookie
Client
Other scopes always need to be scoped:
Server
Application
Session
Request
Attributes
Error
3701 viewed | Your opinion... | Tjarko @ 15:18 cet
Use cftransaction. It's designed to ensure that either all database transactions in a block occur or none at all. The syntax is
<cftransaction>
<cfquery...>
INSERT...
</cfquery>
<cfquery...>
UPDATE...
</cfquery>
</cftransaction>
3210 viewed | Your opinion... | Tjarko @ 15:11 cet
You can query another query like this.
<cfquery datasource="#dsn#" name="FirstQuery">
SELECT *
FROM tablename
</cfquery>
<cfquery DBtype="Query" name="SecondQuery">
SELECT *
FROM FirstQuery
</cfquery>
3168 viewed | Your opinion... | Tjarko @ 15:10 cet
<cfdirectory directory="c:\winnt\" name="FileCount">
<cfoutput>
#FileCount.RecordCount#
</cfoutput>
3391 viewed | Your opinion... | Tjarko @ 15:07 cet
On the receiving page.. thus the page you are posting to you can get the fieldnames in the following matter.
<cfoutput>
#form.fieldnames#
</cfoutput>
Get the values with every formfield submitted
<cfloop list="#form.fieldnames#" index="formfield">
#formfield# = #form[formfield]#
</cfloop>
3123 viewed | Your opinion... | Tjarko @ 15:00 cet
<cfquery datasource="#DSN#" name="gettable">
SELECT TOP 1 *
FROM table
</cfquery>
<cfloop list="#gettable.ColumnList#" index="column">
#column#<br>
</cfloop>
3164 viewed | Your opinion... | Tjarko @ 14:55 cet
Session variables are stored in a structure, so you can use StructDelete
<cfset variables.Result = StructDelete(session, "YourSessionVarName")>
11538 viewed | 3 opinion(s) | Tjarko @ 14:50 cet
If you are using ColdFusion 5 Server or later, use
<cfdump var="#YourVariable#">
3113 viewed | Your opinion... | Tjarko @ 14:47 cet
You can compare values in several ways in which the first example is the preferred method.
<cfif not compareNoCase(var,"value")>
equal
<cfelse>
not equal
</cfif>
or
<cfif var eq "value">
equal
<cfelse>
not equal
</cfif>
or case-sensitive
<cfif not compare(var,"value")>
equal
<cfelse>
not equal
</cfif>
5085 viewed | Your opinion... | Tjarko @ 12:09 cet
You can display the current time in the following matter.
<cfoutput>
#timeformat(now(),'HH:mm:ss')#
</cfoutput>
HH = 24 hour clock
hh = 12 hour clock
10118 viewed | 1 opinion(s) | Tjarko @ 12:04 cet
<cfset str = "I would really want the first 5 words from this string but i don't know how...">
<cfset maxwords = 5>
<cfoutput>
#REReplace(str,"^(#RepeatString('[^ ]* ',maxwords)#).*","\1")#
</cfoutput>
returns:
"I would really want the"
5263 viewed | Your opinion... | Tjarko @ 14:53 cet
You can get the absolute root of your website with the following code.
<cfset abs_root = "#REPLACENOCASE(CGI.PATH_TRANSLATED,REPLACE(CGI.PATH_INFO,'/','\','all'),'')#">
returns: c:\inetpub\wwwroot\
5466 viewed | 3 opinion(s) | Tjarko @ 14:49 cet
By using the DateFormat() function, we can tell ColdFusion that we want to see a date:
<cfoutput>#DateFormat(Now())#</cfoutput>
returns 24-Jun-02
Continuing onward, we can customize the date format even more by specifying a mask in the DateFormat() function.
<cfoutput>#DateFormat(Now(),"mm/dd/yy")#</cfoutput>
returns 06/24/02
<cfoutput>#DateFormat(Now(),"ddd, mmm d, yyyy")#</cfoutput>
returns Thu, Jun 24, 2002
<cfoutput>#DateFormat(Now(),"dddd, mmmm d, yyyy")#</cfoutput>
returns Thursday, June 24, 2002
<cfset setLocale("Dutch (Standard)")>
<cfoutput>#DateFormat(Now(),"dddd, mmmm d, yyyy")#</cfoutput>
returns Dinsdag, Juni 24, 2002
4153 viewed | Your opinion... | Tjarko @ 9:46 cet
Use the Now() function to obtain the current date and time from the server.
<cfoutput>#Now()#</cfoutput>
returns the date in the following format: {ts '2002-011-14 10:29:54'}
5468 viewed | Your opinion... | Tjarko @ 9:37 cet
As an example, the following code alternates between white and a light gray. If (CurrentRow MOD 2) is 0 (i.e. the row number is an even number), it uses the first color value, otherwise (odd number) it uses the second color value.
<table>
<cfoutput query="myQuery">
<tr bgcolor="###Iif(((CurrentRow MOD 2) is 0),de('cccccc'),de('ffffff'))#">
<td>#Field1#</td>
<td>#Field2#</td>
</tr>
</cfoutput>
</table>
3706 viewed | 1 opinion(s) | Tjarko @ 9:31 cet
You can override the timeout value with a new attribute of <cfsetting> within MX.
<cfsetting requesttimeout="600">
This will tell the CFMX server that the page may run for 600 seconds (10min)
In pre MX versions you could add a URL variable while calling the page that
did the same.
somepage.cfm?requesttimeout=600
NOTE: This only overrides the CF timeout, not the webserver timeout if there is any.
21451 viewed | Your opinion... | Tjarko @ 9:24 cet
You can "escape" the pound sign by doubling it. For example:
<cfoutput><font color="##FFFFFF">#myVariable#</font></cfoutput>
Alternately, consider moving the CFOUTPUT tags closer to the variable, like this:
<font color="#FFFFFF"><cfoutput>#myVariable#</cfoutput></font>
10686 viewed | 2 opinion(s) | Tjarko @ 9:22 cet
<cfloop from="1" to="10" index="i">
<cfset "request.var_#i#" = i>
</cfloop>
<cfdump var="#request#">
11152 viewed | 4 opinion(s) | Tjarko @ 0:00 cet
You can get this result with the following regular expression
<cfsavecontent variable="str">
<html>
<body>
This is the text you want
</body>
</html>
</cfsavecontent>
<cfset textstr = REReplace(str,'<[^>]*>','','all')>
<cfoutput>
#textstr#
</cfoutput>
25288 viewed | 7 opinion(s) | Tjarko @ 18:23 cet