How to use the CFEclipse Scribble Pad as a fast and easy ColdFusion sandbox

Like most developers I know, I'm always checking functions, testing little changes and trying to find just the right syntax for certain bits and blocks of code. Every project usually ends up with a 'test.cfm' file, which gets written and overwritten with all sorts of little snippets, queries, and other scribbly things, then deleted. To use the test file, I open it like any file in my editor, make changes, then load that page's local url in the browser, refresh, repeat... not bad, it works... but I just discovered something much better!

Thanks to Mark Esher's MX Unit blog post about the CFEclipse Scribble Pad , I've now got a one-click (or one key, F8) instant sandbox to scribble whatever I like, across all projects in my Eclipse workspace. Launching the CFEclipse scribble now (F8) causes 2 things to happen automatically: my 'scribble.cfm' file (stored in a _temp project in my workspace) opens for editing, and the Eclipse browser view (which I seldom use otherwise but is perfect for viewing little bits, cfdumps and snippets) pops up, showing me the rendered output. Very nice.

It isn't just saving the clicks, but saving the thought process. While coding, the distraction of stopping, making a temp file, going to that file in the browser.. every step takes my mind further off of the super-intensive outrageously-important totally-impressive thing I was doing when I decided I needed to scribble in the first place.

Setting it up was easy - just follow the directions : http://blog.mxunit.org/2009/04/timesavers-cfeclipse-scribble-pad.html . This is another perfect example of the powerful, practical tools and timesavers that hide behind a previously-unnoticed menu option or toolbar icon - and though one of the simplest, I have no doubt this will be among my most-used commands when working in Eclipse!

 

Show open workspace name in Eclipse title bar

In Eclipse, I can switch worskpaces by going to File > Switch Workspace ... but it doesn't give any indication of which workspace I have open at the time.... until now!

The -showLocation parameter causes Eclipse to show the current workspace name in the title bar of the application window (as well as the perspective name for the open perspective).

To add this to your Eclipse configuration (in Windows) is very easy:
Just right-click the shortcut you use to open Eclipse, and select 'properties'.
Then, add "-showLocation" (without the quotes) to the end of the "Target" line.

My shortcut target was: C:\ECLIPSE35\eclipse\eclipse.exe 3.5
Now it looks like this: C:\ECLIPSE35\eclipse\eclipse.exe 3.5 -showLocation

View XML directly in Firefox without the annoying 'add to reader' screen

This is one of those little things that has bugged me for quite some time, but not quite enough to do anything about... until now... 

Whenever I try to view an xml file, whether it be a sitemap.xml file from one of my website projects, a data export file, or an rss feed, Firefox shows me a screen with two options, "add to google reader" or "add to google homepage" ... usually I want neither, I just want to see my xml!

The fix was actually super simple... but, lest I forget at some point ( most likely not too far in the future) how I managed to banish this little annoyance, I'll post it here:

1) In FF, go to Tools > Options in the top menu
2) Select the Applications tab
3) Scroll down to "Web Feed" (how annoying ... not 'xml', not 'rss', but 'web feed'? really? )
4) Change the Web Feed 'action' to "Preview in Firefox" (mine said "Use Google" before changing)
5) Click the 'ok' button and go to any .xml file url to see all the wonderful XML , sans reader-prompt annoyance !

 

Verify remote images exist - prevent missing images with CFHTTP

I am creating a photo gallery where the images actually reside on a third-party service. To prevent 'blank' or missing images from showing up in my html gallery markup, I needed a way to verify the remote image actually exists before including it into the dynamic markup.

This seems to work quite nicely:



<cfoutput query="myImageQuery">

<cfset imgURL = "http://remotesite.com/images/#imageFilename#">
<!--- check for the image via cfhttp:
Note:'head' method gets only headers, which is all we need (thanks @ScottP) --->

<cfhttp url="#imgURL#" method="head">    
<!--- isolate the 'mimeType' value from the cfhttp results --->
<cfset myStatus = cfhttp.mimeType>
<!--- if the mimeType is jpg (jpeg), include the image in our output --->
<cfif myStatus eq "image/jpeg">
<img src="#imgURL#" alt="#imageTitle#">
</cfif>

</cfoutput>

Add alternate pricing option to Cartweaver

A Cartweaver user asked how he can add alternate pricing to his Cartweaver ecommerce site. He was understandably concerned about the need to edit the database, and how much code editing might be involved. But if you take a systematic approach, it is pretty straightforward.

The first part of setting up any alternate pricing system is to get that info into your database and admin, so you can work with it. In this case, since the basic goal is to duplicate the existing 'price' system, that is exactly what we are going to do.

more...

Marking current menu link with jQuery for CartWeaver categories

Working on a heavily-modified Cartweaver Coldfusion E-Commerce shopping cart site, I have created a database-driven navigation menu containing links to each category. When a user clicks a link, the products in that category are displayed, and the menu link for that category is highlighted via a special 'currentLink' css class.

Now of course I could use CF to add ' class="currentLink" ' to the current category's menu option, but I am not doing this particular menu that way. Besides, it is just as easy with jQuery!



<cfif cgi.script_name contains 'results.cfm' AND isDefined('url.category') and url.category gt 0>
<cfsavecontent variable="highlight">
<script type="text/javascript">
$(document).ready(function(){
$('.sideNav li a').removeClass('currentLink');
$('.sideNav li a[href=results.cfm?category=<cfoutput>#url.category#</cfoutput>]').addClass('currentLink');
//end jQuery
});
</script>
</cfsavecontent>
<cfhtmlhead text="#highlight#">
</cfif>

Simple enough - if we are on the 'results' page, and a category is defined in the url, remove the 'currentLink' class from all existing menu items, find the one where the 'href' attribute matches the current pagename and category, and add the class back to that link. Done.

The use of cfsavecontent and cfhtmlhead means I can put this right below the code that calls in my custom nav tag, for easy fine-tuning right where i need it (rather than in an external scripts file).

Quick , easy, and done in a flash with jQuery!

Redirect secure 'https' requests using getPageContext() and isSecure()

Working on a site using a shared ssl, where only 2 specific pages of the site are required to operate under the https:// SSL prefix, I needed a quick way to check whether a page request for either of those pages was using the 'https' prefix - if not, redirect, adding the 's'. Likewise, all other pages, we want to make sure they are not using the 's' and redirect without it.

I found this blog post, which got me started: http://www.chapter31.com/2007/07/21/detecting-and-redirecting-http-to-https/

Using the fun and interesting CF goodies
getPageContext() and isSecure()

<!--- REDIRECTION TO SSL / non-SSL --->
<cfset secureRequest = getPageContext().getRequest() />
<!--- for these pages, redirect to secure (https) page  --->
<cfif cgi.SCRIPT_NAME contains 'payment.cfm' OR cgi.SCRIPT_NAME contains 'payment_response.cfm'>
<cfif NOT secureRequest.isSecure()>
<cflocation url="https://#secureRequest.getServerName()##secureRequest.getRequestURI()#?#secureRequest.getQueryString()#" addtoken="false" />
</cfif>
<cfelse>
<!--- for all other pages, redirect to non-secure (http) page --->
<cfif secureRequest.isSecure()>
<cflocation url="http://#secureRequest.getServerName()##secureRequest.getRequestURI()#?#secureRequest.getQueryString()#" addtoken="false" />
</cfif>
</cfif>

Quick and simple.

Live HTTP Headers Firefox Extension

As part of my url-redirection efforts related to the launch of the new company site, I've been looking more closely at 301 redirection using ColdFusion ( see this post about CF 301 with CFlocation - it really is that simple! )

But, being somewhat skeptical that it could really, truly be that simple, I still wanted to verify that the redirection was going through as '301' status in my web browser.

On the advice of a friend, I downloaded the quick easy FireFox extension called "Live HTTP Headers" http://livehttpheaders.mozdev.org/

Within a few seconds, I had my proof. I did a quick google search that I knew would turn up my old site, clicked "Tools > Live Http Headers" in Firefox, and clicked on the first result for 'www.mredesign.com'.

Sure enough I was looking at the new site, www.gowestweb.com , and in the little Live Http popup, I had my 301 proof.

Here's part of the detailed output:

http://www.mredesign.com/

GET / HTTP/1.1 Host: www.mredesign.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://www.google.com/search?q=utah+web+designer&btnG=Search&hl=en&client=firefox-a

HTTP/1.x 301 Moved Permanently Connection: close Date: Wed, 12 Aug 2009 15:44:48 GMT Server: Microsoft-IIS/6.0 X-Powered-By: ASP.NET Location: http://www.gowestwebdesign.com/index.cfm Content-Type: text/html; charset=UTF-8 ---------------------------------------------------------- http://www.gowestwebdesign.com/index.cfm

GET /index.cfm HTTP/1.1 Host: www.gowestwebdesign.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: en-us,en;q=0.5 Accept-Encoding: gzip,deflate Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7 Keep-Alive: 300 Connection: keep-alive Referer: http://www.google.com/search?q=utah+web+designer&btnG=Search&hl=en&client=firefox-a

I am a happy (and safely redirected) camper. Very nice tool, works just like it should... and free!

301 "Permanent" URL Redirection with Coldfusion 8 and cflocation

When moving domains, or forwarding the traffic from one site to another, the usual and preferred method is a "301" or "permanent status" redirection, which, simply put, means "the page is gone and it is not coming back. Please look here from now on --> "

As Pete Frietag quickly explains in this blog post : http://www.petefreitag.com/item/648.cfm , 301 redirection with ColdFusion is as simple as could be as of CF8.

<cflocation url="http://www.newsite.com" statuscode="301" addtoken="false">

That's it.... just plop that in your old page, set the url, there's yer 301 .

Of course, this only works in cases where the old domain is still hosted on a live server, i.e. moving a directory within an existing site. For full-blown root domain redirection, see your friendly neighborhood domain registrar or server control panel.

TwitterFeed and Tweet.js - feed your blog to Twitter, and your Twitter feed to any page

Two fun, free tools for blog/Twitter syndication combo:

1) www.twitterfeed.com : enter any Blog Rss feed url and twitterfeed will automatically post your blog entries to your twitter account

2) tweet.js : light, fast jQuery powered Twitter feed display - easy to configure options and show your Twitter posts on any page you choose

See both in action in the sidebar, here: www.gowestweb.com

Anything I post on this blog gets added to my 'gowestweb' twitter feed, which is shown on the GoWest site using tweet.js

Use Gmail for mailto email web links

On my main pc, I can click 'send link' in Firefox and Outlook opens up, I choose a recipient and send the url as an email. On my laptop, I use gmail... and often email links to myself for things to follow up on later, from the main machine. I hadn't bothered to look it up but have thought for a while how nice it would be if I could do the same with Gmail, setting it as the default client for mailto links from the browser... sure 'nuff... this blog post explains in very simple terms how to do it: http://ffextensionguru.wordpress.com/2008/09/24/gmail-as-default-for-mailto/

More Entries

blogcfc 5.9.1.002 by raymond camden
contact michael evangelista