On Firefox's Ubiquity and Introducing the Ubiquity Coldfusion Search Command

Well it doesn't happen often, but today it has happened again, I was blown away by another Firefox extension, and even less frequently I'm blown away to a new level, well today is another one of those days, welcome Ubiquity. I recommend you read Aza Raskin's post, because it is well worth it. But my short summary of the Ubiquity extension is that you can easy make command's for firefox with javascript, and furthermore, it's extremely easy to share these commands, and send updates.

I've been playing with it for about 2 hours now, since I read Aza's post, and I have already have got my first command published, here it is:

  • coldfusion: Searches the Coldfusion 8 LiveDocs for a term.

An example command would be:

coldfusion continue

Which will show you some Coldfusion 8 LiveDocs results for "continue". Enjoy!

Important BlogCFC 301 redirects.

I put the following code after the first line of code of my blogCFC's application.cfm (and the comments), for a application.cfc converted site, this should go in the onRequestStart method:

<!--- START: IMPORTANT 301 REDIRECTS --->
<cfif (cgi.server_name eq "www.erikvold.com")>
<cffunction name="cf301Redirect" access="public" returntype="void">
<cfargument name="urlString" type="string" required="yes" />

<!--- 301 redirect the user to the provided url --->
<cfheader statuscode="301" statustext="Moved permanently" />
<cfheader name="Location" value="#arguments.urlString#" />
</cffunction>

   <!--- START: Create redirect string --->
   <cfset request.currentURL = "http://erikvold.com" />

<cfif cgi.script_name eq cgi.path_info>
<cfif len(trim(cgi.query_string)) gt 0>
<cfset request.currentURL = request.currentURL & "#cgi.SCRIPT_NAME#?#cgi.query_string#" />
<cfelse>
<cfset request.currentURL = request.currentURL & "#cgi.SCRIPT_NAME#" />
</cfif>
<cfelse>
<cfif len(trim(cgi.query_string)) gt 0>
<cfset request.currentURL = request.currentURL & "#cgi.SCRIPT_NAME##cgi.PATH_INFO#?#cgi.query_string#" />
<cfelse>
<cfset request.currentURL = request.currentURL & "#cgi.SCRIPT_NAME##cgi.PATH_INFO#" />
</cfif>
</cfif>
<!--- END: Create redirect string --->

<!--- redirect the user --->
   <cfset cf301Redirect( request.currentURL ) />
</cfif>
<!--- END: IMPORTANT 301 REDIRECTS --->

Duplicate content is bad, mmmm K..

So to avoid it, redirect your www.domain.com to domain.com, or I'm sure anyone can alter this quickly to do the reverse.

I'd love to see any https alterations, or I'll probably do my own eventually too..

Reflections on Coldfusion/Javascript and the switch statement vs if...else statement

So, I was reading a recent discussion on the difference between the switch statement and the if...else statement, on the CF-Talk Mailing List, and I thought I'd write about just how cool switch statements really are.

First I want to point out a couple of clear advantages of the switch statement over the well known if...else statement:

  • We have a single expression that is only evaluated once.
  • We can run multiple segments of code for a given value, which handy for clean code reuse.

Now let's consider the downside of a switch statement:

  • The switch statement handles a subset of problems that the if-else statement can handle, albeit more efficiently in many cases where they overlap. I like to think of the switch statement as a logic factoring solution which is available to me for simple types of if...else statements.
  • Cannot use variables in the case statement (unless your using Javascript!)

Here's an example of a Coldfusion if...else statement that can be simplified with a switch statement:

<cfscript>
function cleanTeeth(meal){
if(meal eq "brunch"){
useToothPick();
}
else if(meal eq "breakfast"){
useMouthWash();
floss();
useToothBrush();
}
else if(meal eq "lunch"){
useToothBrush();
}
else if(meal eq "dinner"){
floss();
useToothBrush();
}
}
</cfscript>

Now here is the simplified switch statement version:

<cfscript>
function cleanTeeth(meal){
switch(meal){
case "brunch":
useToothPick();
break;
case "breakfast":
useMouthWash();
case "dinner":
floss();
case "lunch":
useToothBrush();
}
}
</cfscript>

So in this example, not only is the switch statement version reusing code, making it less lines, but it should run faster, especially if you eat a lot.

Now, the thread I read on Cf-Talk began with someone asking why one cannot use a variable in a Coldfusion case statement, and the short answer to this was that Java won't let you do this in a switch statement either. Java will allow you to use constants in a case statement, as was pointed out in the thread, but since constants do not exist in Coldfusion, they cannot be used in a Coldfusion case statement. I suppose this functionality could be implemented into the Coldfusion switch statement, but that would mean that Coldfusion switch statements would simply be converted to Java if..else statement, and lose the performance gained by being a Java switch statement.

But anyhow, the point I wanted to make was that in Javascript using a variable in the case statement is possible! so when you Coldfusion/Java programmers are writing some Javascript next time, heads up.

Simple BlogCFC Blog Roll pod for MySQL

I was looking for a BlogCFC Blog Roll pod today and could not find one that suited my needs, so here is the one I built for my MySQL db (note the MySQL script can easily be converted for MSSQL or other db types).

This is the Blog Roll MySQL CREAT TABLE script:

-- -----------------------------------------------------
-- Table `tblblogpod_blogroll`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `tblblogpod_blogroll` (
`id` INT UNSIGNED NOT NULL AUTO_INCREMENT ,
`href` VARCHAR(255) NOT NULL DEFAULT 'http://' ,
`title` VARCHAR(255) NOT NULL ,
`text` VARCHAR(255) NOT NULL ,
`rel` VARCHAR(45) NOT NULL DEFAULT 'external nofollow' ,
`target` VARCHAR(15) NOT NULL DEFAULT '_blank' ,
PRIMARY KEY (`id`) )
ENGINE = MyISAM;

This is the Blog Roll Pod Code:

<cfsetting enablecfoutputonly='true'>
<cfprocessingdirective pageencoding='utf-8'>
<!---
Name : Blogroll for BlogCFC & MySQL
Author : Erik Vergobbi Vold
--->

<cfquery name="getBlogRoll" datasource="#application.blog.getProperty('dsn')#" username="#application.blog.getProperty('username')#" password="#application.blog.getProperty('password')#">
SELECT text, href, title, rel, target
FROM tblblogpod_blogroll
ORDER BY text
</cfquery>


<cfmodule template="../../tags/podlayout.cfm" title="Blog Roll">

<cfloop query="getBlogRoll">

<cfoutput><a #iif( len(trim(title)) gt 0, de('title="'&title&'"'), de(''))# #iif( len(trim(target)) gt 0, de('target="'&target&'"'),de(''))# #iif( len(trim(rel)) gt 0, de('rel="'&rel&'"'), de('
'))# href="#href#">#text#</a><br /></cfoutput>
</cfloop>

</cfmodule>

<cfsetting enablecfoutputonly='false'/>

If anyone else decides to use this for MSSQL, or some other db type, please post the SQL script in a comment, thank you.

© Erik Vold 2007-2012. Contact Erik Vold. Top ^