Regular Expressions, Reverend Jim Ignatowski and You

Posted: July 30th, 2010 | Author: Christopher Vigliotti | Filed under: Code Sample, Regular Expressions | 4 Comments »

Regular Expressions

I use regular expressions just often enough to have to totally re-learn them every time I need to use them. After a round of Google searches, reading over a few good regex sites (here’s one) and a bit of head scratching and code tinkering I end up with the code I need.

In this particular case I needed append a variable with punctuation in cases where the variable ended in an alphanumeric character. Regex to the rescue!

1
2
3
4
5
6
7
<cfset variables.question = "what does the yellow light mean" />
<cfif ReFindNoCase("[a-zA-Z0-9]$", variables.question )>
     <cfset variables.question = variables.question & "?" />
</cfif>
<cfoutput> 
     #variables.question #
</cfoutput>

Reverend Jim Ignatowski

This has nothing to do with regular expressions, but it’s a classic moment from Taxi.

You

The next time you need some regex help you may want to check out http://www.regular-expressions.info. If you have any good regex tips or sites leave them in the comments below. As usual, spammers will be shot on site.


CFDOCUMENTITEM, Why Hast Thou Forsaken Me

Posted: February 26th, 2010 | Author: Christopher Vigliotti | Filed under: Code Sample, ColdFusion | 2 Comments »

I’m working on generating PDF reports in ColdFusion 8 using the quick and easy cfdocument tag, and discovered that I cannot open and close tables using cfdocumentitem headers and footers. Here’s what I would have liked to do…

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<cfdocument attributecollection="#cfdocAttributes#">
	<cfdocumentitem type="header">
		<table border="5">
		<tr>
			<th>ID</th>
			<th>Name</th>
		</tr>
	</cfdocumentitem>
	<cfdocumentitem type="footer">
		</table>
	</cfdocumentitem>
	<cfoutput query="qPeople">
		<tr>
			<td>#ID#</td>
			<td>#Name#</td>
		</tr>
	</cfoutput>
</cfdocument>

Apparently there is a work-around for this if one is using Open BlueDragon. If anyone out there has a ColdFusion 8 solution that they’d care to share I would appreciate it…and apparently so would fellow CF developer Renu Deshpande.


CFTEXTAREA or FCKEditor?

Posted: May 15th, 2009 | Author: Christopher Vigliotti | Filed under: Code Sample, ColdFusion, JavaScript | 2 Comments »

If you want to add a rich text editor to your forms in ColdFusion 8 it’s as easy as CFTEXTAREA richtext=”true”…

Read the rest of this entry »


Environment-Specific Application Scope Variables

Posted: May 15th, 2009 | Author: Christopher Vigliotti | Filed under: Code Sample, ColdFusion | 2 Comments »

If you don’t know what an Application.cfc file is or how to use it I suggest that you start with this
excellent Application.cfc Tutorial & Reference over at Ben Nadel’s blog.

There are number of approaches for managing environment-specific variables for your applications. One is to store them into an external XML file. I would imagine that there is an increased processor overhead associated with this path (it may be marginal), and there is the extra code of parsing the XML data to get your variables. One approach that’s worked well for me is to define the variables for each of my applications environments in a function in my Application.cfc files. This function detects which environment it’s being run in and sets the variables accordingly. Peep this out…

Read the rest of this entry »


Code Comments For The (Team) Playa

Posted: May 15th, 2009 | Author: Christopher Vigliotti | Filed under: Code Sample, ColdFusion | No Comments »

Word up, dawgs? Consider the following code…

Read the rest of this entry »


Writing and Calling Stored Procedures

Posted: May 12th, 2009 | Author: Christopher Vigliotti | Filed under: Code Sample, ColdFusion, SQL | No Comments »

In my previous post we built a Cheesy Database using simple SQL Scripts. Now I want to build on that by coding a stored procedure. Stored procedures are a ColdFusion developer’s best friend. You can use stored procedures to store some/most/all of your SQL logic. This is a great way to organize your code (stored procedures are generally faster than inline queries), optimize your application’s performance and help to protect your system from SQL Injection.

Writing a basic Stored Procedure is not a difficult task. First lets take a look at our inline query…

Read the rest of this entry »


Creating A Cheesy Database

Posted: May 12th, 2009 | Author: Christopher Vigliotti | Filed under: Code Sample, SQL | No Comments »

After reviewing my previous posts I thought that it would be helpful if all of my examples (1) worked and (2) worked together. So without further adieu, here are a few SQL scripts to get a basic database up and running. Once you’ve run these scripts you will be able to run the scripts found at my previous post on SQL Joins.

First we’ll create the database…

Read the rest of this entry »


SQL Joins

Posted: May 8th, 2009 | Author: Christopher Vigliotti | Filed under: Code Sample, SQL | 4 Comments »

Having spent most of my career working in environments where SQL development and ColdFusion development are handled by separate people or teams. The end result is that my SQL skills are not as evolved as my ColdFusion skills.

At my current job I am the one who writes the SQL for the small and medium-sized ColdFusion & SQL Server-based systems that I develop. Up until the other day I used implicit inner joins and over-used subqueries to get the data that I wanted from a database. My code worked, but it was ugly.

Read the rest of this entry »


Code Formatting

Posted: May 8th, 2009 | Author: Christopher Vigliotti | Filed under: Code Sample, ColdFusion, WordPress | No Comments »

I’m checking out WP-Syntax, a WordPress plugin that makes short work of sharing code samples…

1
2
3
4
5
6
7
8
9
10
11
<cfscript>
   variables.cheeses = StructNew();
   variables.cheeses.Gouda = CreateObject("component", "Cheese").init(
      datasource="cheesyDB",
      name="Gouda"
      );
</cfscript>
 
<cfoutput>
   #variables.cheeses.Gouda.getDescription()#
</cfoutput>

If anyone has any tips for modding WP-Syntax or an alternative solution feel free to drop me a comment.


Shell

Posted: May 8th, 2009 | Author: Christopher Vigliotti | Filed under: Code Sample, ColdFusion, MVC, O-O | No Comments »

My first pet project is “Shell”, a simple O-O ColdFusion Sample Application. I’ve spent about 90 minutes on it at this point (translation: it’s not done), so consider it more of a “sketch” at this point.

Shell – Version 0.0.0.1b (pardon the hokey over-use of the shell metaphor in the code).