Pretty self explanatory:
/**
* mergeListToArray
* When provided a list and an array, we convert the list to an array and merge them.
* @created 11/07/2011
* @author Ryan Mueller
* @param {Array} a Array to merge list to {required}
* @param {String} l List to merge with array {required}
* @param {String} delim Delimiters to use default = ','
* @return {Array}
*/
public Array function mergeListToArray(required array a,required string l,required string delim=','){
var tmpArr = ListToArray(trim(arguments.l),delim);
var newArr = arguments.a;
if(IsArray(newArr) && IsArray(tmpArr)){
// loop over current array and append to new array
for(i=1; i LTE ArrayLen(tmpArr); i=(i+1)){
ArrayAppend(newArr,tmpArr[i]);
}//end loop
}//end isarray
return newArr;
};
Today I’m working on decreasing execution time on a script that does a couple DB querys and cfdirectory lists. After some preliminary testing my gut perception has proven true; the exorbinate execution time is due to cfdirectory.
So I set out to find a faster way of getting file information from directories and sure enough taking things back to Java is the way to go. See my benchmark code below and the results. I’m sure you’ll agree.
// UNC path to look in
curDir = '\\my\unc\path';
// ftime will hold the execution time
// fio is our java.io.File object
ftime = gettickcount();
fio = createObject('java','java.io.File');
mylist = fio.init(trim(curDir)).list();
ftime = gettickcount() - ftime;
I run the exact same thing in cfdirectory (tumblr strips cfml tags from posts or i”d post that here too). The results in my case show: files: 3409, ftime: 31, dtime: 17608.
That’s 3409 files. Java returns a list of names in 31ms while cfdirectory does the same in 17.5 seconds.
Look below for a little function I wrote to convert an array to a query. I had to write this to allow for my use of java.io.File.list() rather than cfdirectory due to speed limitations of the latter. More on that with benchmarks later here.
/*
* arrayToQuery
* Allows us to convert an array into a single column query.
* @author Ryan Mueller @CreativeNotice
* @created 10/27/2011
* @param {Array} arr Array to be converted {required}
* @param {String} colname Name for query column {required} default=col1
*/
public Query function arrayToQuery(required array arr,required string colname='col1'){
var qry = queryNew(arguments.colname);
for(i=1;i <= ArrayLen(arguments.arr);i=(i+1)){
queryAddRow(qry);
querySetCell(qry,arguments.colname,arr[i]);
}
return qry;
}
When you enable gzip, or deflate, compression on your server one side effect is your existing cfhttp requests will show “Connection Failure” even though you get an http 200 response. This is because Coldfusion doesn’t know how to decompress the response. Get get arround this you need to tell the server to send an uncompressed response. Use this tag to do so.
<cfhttpparam type=”header” name=”Accept-Encoding” Value=”no-compression”>
I love dark themes and really wisth CFEclipse installed with one standard. Found this great post from Craig Kaminsky on easily installing pre-made theme files. Check it out.
Guess what? It doesn’t exist. You are so foo bar! The work around is to use:
include "mycfsettinginclude.cfm";
In that file just add one line, your cfsetting tag.
It’s hacktastic but it works. Oh, and don’t forget to bitch to Adobe about this oversight. sheesh!
Google just released a new tool for reviewing your site DOM security. Read more and download the Chrome extension after the jump.
(Source: code.google.com)
I was surprised to find that you have to be careful when ordering your filters in DirectoryList(). E.g. “*.ppt|*.pptx” will not show both ppt and pptx files, while “*.pptx|*.ppt” will.
Can’t tell you why, but just be aware of it.
When working with cfdirectory or DirectoryList you can pass in multiple filters like this “*.png|*.jpg”. Pretty simple and the pipe is easy to remember.
When using cffileupload though, you have to separate your filters using a comma. e.g. “.png,.jpg”
This sucks if you’re trying to store a single filter and use it in two places. You’ll have to ReReplace() and store only one style of list. Just be sure to stay consistent.
You can pass a structure to your methods using this:
myFunc(argumentCollection=myStruct);