In functional programming a map function is a way to create an array by passing each element of the array into a function. Mapping functions are very commonly used in languages like Ruby, Python and JavaScript. ColdFusion acts more like JavaScript in this respect where a Map is not a native function, however it is easy to implement.
Before I get into the code, lets take a look at how the map function works. The method signature for map looks like this: public Array function map(Array arr, function fn). The map function takes and array and a function as parameters, and returns an array. Each element in the array argument is passed into the function and the result is added to the result.
Without further adu, lets take a look a the code:
Running this code would produce this result:
Now this pattern can be applied anywhere you find yourself looping through an array and applying the same logic to each member of the array.
Showing posts with label Zeus. Show all posts
Showing posts with label Zeus. Show all posts
Monday, February 20, 2012
Friday, February 17, 2012
Changing the webroot of the ColdFusion 10 Beta (Zeus) Built In Web Server
If you run the ColdFusion built in web server on your local machine and want to keep your current webroot while playing with the Zeus beta here's how to change the web root:
- Open coldfusion_install_location/cfusion/runtime/conf/server.xml
- Scroll down to the end of the document where you see the line:
<!-- Uncomment the line below to change the default web root or to add virtual directory
Make sure to replace <cf_home> with the absolute path to ColdFusion Home-->
- Copy the last comment in the group of comments at the end, right before the line. The line you want toc copy looks like (do not copy the beginning :
<Context path="/" docBase="<cf_home>\wwwroot" WorkDir="<cf_home>\runtime\conf\Catalina\localhost\tmp" ></Context>
- Change the docBase attribute to your the ABSOLUTE path of the directory where you want your web root to be. In my case it was /Applications/coldfusion9/wwwroot if you are on Windows this will start with a drive letter like c:\... or d:\...
- Add aliases attributes to both the CFIDE directory AND the WEB-INF directory. This step is extremely important, without it ColdFusion WILL NOT run. To do this add a new attribute to the
node called aliases. Inside that attribute add the following text /CFIDE=/absolute_path_to_coldfusion_install_location/cfusion/wwwroot/CFIDE,/WEB-INF=/absolute_path_to_coldfusion_install_location/cfusion/wwwroot/WEB-INF Again, if you are on Windows this will start with a drive letter like c:\ or d:\. - This is what it looks like on my system (OSX):
<Context path="/" docBase="/Applications/coldfusion9/wwwroot" WorkDir="/Applications/coldfusion10/cfusion/runtime/conf/Catalina/localhost/tmp" aliases="/CFIDE=/Applications/coldfusion10/cfusion/wwwroot/CFIDE,/WEB-INF=/Applications/coldfusion10/cfusion/wwwroot/WEB-INF"></Context>
- Restart ColdFusion10 and be happy.
Labels:
ColdFusion,
Zeus
Subscribe to:
Posts (Atom)
