forgetfoo

Blog.

How I Got Started in CF

How I Got Started In ColdFusion
In high-school, I took a class in QBasic. And it was awesome - super awesome!! The moment I turned a line of code into a visual screen element, I was hooked. I knew from that very moment that computer programming was what I wanted to do with the rest of my life. And, when I started applying for colleges shortly thereafter, I made sure to declared my major as "Computer Science".

In these applications, I always applied to the Liberal Arts colleges - my mom wanted me to have a well-rounded education. But, due to a system glitch (ironic!), I was eventually accepted to the School of Engineering at Tufts University. At first, I tried to switch back to Liberal Arts; but, when I found out that engineers didn't have to take a foreign language requirement... "Sorry mom, they said I couldn't switch schools." Six additional engineering credits was well worth the complete absence of verb conjugation exercises.

In college, I was introduced to classic computer programming languages like C, C++, Java, Lisp, and SQL. I also started getting into web programming with languages like [classic] ASP and PHP. For a few semesters, I even acted as a Teaching Assistant in the web development classes. I really loved that I could create widely available content on the web. But, ASP and PHP never felt good. They got the job done; but, they never made things easy.

Then, I got an internship at Koko Interactive (a.k.a. Kokopelli New Media) here in NYC. I spent my first summer learning all about HTML, JavaScript, Photoshop, ImageReady, and Flash. And, when I wasn't reading HTMLGoodies.com, I was the in-house Quality Assurance (QA) guy.

As it turns out, I'm pretty good at breaking other people's code. I would get sent a link for testing and would return shortly with several pages of changes that needed to be made. Needless to say, I was quite the popular guy. One day, I delivered a list of edits to a frustrated programmer who told me to, "stop giving me lists and just fix the problems yourself!"

And so, they started teaching me ColdFusion.

ColdFusion 4.5, I believe.

As my first learning project in ColdFusion, I created a small web application that would allow me to aggregate a collection of quotes that I had collected about Love and Relationships. Yes - I have always and will always be a hopeless romantic.

When I showed this application to one of the managers, she jokingly said, "You don't actually believe in all this crap, do you?" Of course I do - it's Love. But, that's neither here nor there.

What's important is that when I started using ColdFusion, it was like the whole world suddenly made sense. It was like getting high-fived simultaneously by Chuck Norris and Arnold Schwarzenegger - sure you may dream about such an experience, but you always know deep down inside that it's just a dream.

But, with ColdFusion, it was happening! Here was this language that was insanely powerful and, at the very same time, insanely easy to use. Unlike any of the other programming languages that I've tried, ColdFusion just made "sense;" it was the "right" solution in all the ways that things like ASP and PHP were wrong.

That was something like 9 years ago and I haven't looked back. Since then, my love for ColdFusion has continued to grow. With each new release of the language, it continues to become even more powerful, even more efficient, and even more invaluable. With ColdFusion 10 on the horizon, it is a mature language. And, as it continues to adapt to the changing web world, I have no doubt that it will continue to hit the sweet spot of need - the perfect mixture of power and ease-of-use.

bit of a long post, i know, but i couldn't quite figure out where to cut it off... so i ended up just re-posting almost the entire thing... and why would i do that, you might be wondering?

simple – as one of a few that uses CF, or at least it sure as hell seems that way these days, i found it rather interesting to read about it through the eyes of somebody else... brought back quite a few memories for me, as well.

ColdFusion 8 Rules

9 ways ColdFusion 8 will rule web development
Ben Forta and Adobe are getting into full swing with ColdFusion 8 Scorpio Pre-Release tour. Last night Ben gave us in Seattle a taste of things to come. Here is why it will kick the tar balls out of everything else on the market.ColdFusion 8
  1. Built in AJAX widgets. Create AJAX windows, auto complete forms, calendar popups, grids, WYSIWYG editors, and much more. All using simple ColdFusion based tags and generating industry standard solutions such as Prototype and Yahoo User Interface Javascript.
  2. Native JSON support. ColdFusion components now know if they are called by a web browser and will return JSON formated data automatically. You can also create JSON packets directly or consume them and turn them into native ColdFusion objects.
  3. .NET (and Java!) integration. Pull in .NET objects and use them like native ColdFusion objects. Combine .NET and Java on the same page if you like. Easily the best web based middleware solution.
  4. Microsoft Exchange integration. Love it or hate it, most organizations use Exchange religiously. Now you can read and update email, calendars, tasks and much more. No change to the Exchange server is required.
  5. Flash based presentation builder. Combine HTML, Audio, Flash Movies, Images, and CFCharts to create spiffy flash based presentations on the fly. Just wrap your existing pages in CFPRESENTATION and you are on your way.
  6. Full PDF integration. Create, combine, update, and interact with PDF files using CFPDF and CFPDFFORM tags.
  7. Native image manipulation functions. Blur, sharpen, draw, rotate, stream to browser, and much much more. This finally brings ColdFusion's image support in line with PHP and other frameworks while keeping it so simple that even I could use it.
  8. Across the board enhancements. Improvements in security, speed, Flash Forms, Report Builder, and more.
  9. Administration API. Now you can access, audit, and snapshot all the information the server knows about itself. No longer is ColdFusion a black box. Audit long running processes, most frequently run queries, and bottle necks. SnapShot the server before making your change or doing a reset so that you can analyze potential problems later.
Admittedly I am a ColdFusion fan boy, but I know that it isn't for everyone. Still, ColdFusion is easily the BMW (both in price and in raw engineered quality) of the web application languages out there. With ColdFusion 8 it now becomes possible to build and integrate a vast amount of functionality with only a few lines of code. Imagine letting users quickly create their own presentation by uploading photos and editing slides using a WYSIWYG editor. Then, when they are all done, they can view and share it on the web via Flash or push it to a PDF file. ColdFusion 8 lets you wrap up all this up into a tight package using heavily documented yet extremely simple tags. No scripting required!

man, i hope like hell my buddy ron can get a copy of CF8 and install it on the webserver here... cuz i sure as hell wouldn't mind playing around with it when it rolls out!

(hat tip: donrico)

HowLongSince(dateIn)

i've noticed on quite a few sites how they leave something like "12 hours, 54 minutes ago..." as the datestamp on things like comments and posts, and was wondering how to go about doing in in CF... so i asked my buddy ron if he'd seen or done anything like that already, since he's a CF guru, and here's some code he threw my way... already threw it up over at NippleByte to try it out.
<cfscript>
function howLongSince(dateIn) {
  timeSince = "";
  currDate = now();
  // Calculate years
  years = dateDiff ("yyyy", dateIn, currDate);
  if (years gt 0) { 
    timeSince = years & " years";
    dateIn = dateAdd ("yyyy", years, dateIn);
}

  // Calculate months
  months = dateDiff ("m", dateIn, currDate);
  if (months gt 0) {
    timeSince = timeSince & IIF(timeSince is not "", DE (", "), DE ("")) 
                & months & " month" & IIF(months gt 1,DE("s"),DE(""));
    dateIn = dateAdd ("m", months, dateIn);
  }
</cfscript>

seems to work pretty good, though i dont know if i have to drill down all the way to the Seconds of a timestamp... seems a little excessive, but i might add that to the funtion... at the moment, i have it getting the Year, Month, Day, Hour, and Minute of the datestamp... had me looking around for it, so i figured somebody might find it usefoo out there.

Random Captcha CFC

i was playing around with creating my own little random text image, much as you see on blogs and sites these days to help weed out the spam factor... got a basic one working, and then ended up over at the Wikipedia page for Captcha and downloaded this opensource Captcha CFC, which works alot better than my own.

Captcha!

only thing that seemed to missing from the example code was generating a random text string (unless i missed something), so here's some server-side scripting that i used:

//select a random alphanumeric character
function generateRandomChar()
{	
    c = "";
    while (c is "") {
		c = chr(randRange(48,122));
		if (asc(c) ge 48 and asc(c) le 57) break;
		if (asc(c) ge 65 and asc(c) le 90) break;
		if (asc(c) ge 97 and asc(c) le 122) break;
		c = "";
    }
    return c;
}

//generate random string with passed in length param
function generateRandomString(strLen)
{
    str = "";
    for (i=0;i lt strLen; i=i+1) {
		str = str & generateRandomChar();
    }
    return str;
}

figure somebody might find it usefoo... havent posted any code snips in awhile.

(hat tip: ron)

IIS Rewrite Help

okay, i started to play around with this ISAPI_Rewrite that my buddy ron installed on the new webserver for this new "mini-babe-digg" style website i started to play around with, and i'm having a great time [sarcasm] try'n to wrap my polish head around these URL rewriting expressions... this is what i have so far, but it's not working and was hoping some of ya might have some insight 'n help a foO brutha out:
RewriteRule /([^/?]+)(?:/([^/?]+))?/? /index.cfm\?inc=$1(?2&p=$2)(?3&p2=$3)(?4&p3=$4) [I,L]
RewriteRule ([^?]*/)(\?.*) $1index.cfm$2 [I,L]

basically want to take a URL and be able to have some kinda way to pass in multiple url params... where something like "/index.cfm?inc=whatever&p=001&p2=002&p3=003" would be transformed to "/whatever/002/003/004/" .........nahmean?

be even better if i could make it so the URL param's wasn't hardcoded, but i havent quite figured out how the hell that's done.... *scratches head*

Post Link Form - Tags Input

i got the basic Registration form done, as well as the Login... now i started on the Post Link form, and was wondering what the best, or at least the common practise, way to go about the "tags" input... seems that alot of sites simply use a single input field with a comma delimited list, so that's what i went with:

form input for tags (comma delimited list)

guess i'm just curious if this is the best approach, from a users perspective... is it intuitive enough? would it be better to have seperate input elements for each tag, and maybe add some code to dynamically add more input's as you "add" the tag to the form? just type'n out loud as i think about it.... hmmm.

CF_FLVPlayer

seems like one of the things i still get alot of emails about are the flash vids i post around here... so for those running with CF, here's a nice little custom tag that you can include in your pages that will automatically write the appropriate code to include the flash video player and load the FLV of your choosing into it -- CF_FLVPLayer
<cf_FLVPlayer width="468" height="264" 
serverName="localhost"
fallbackServerName="localhost"
skinName="clearSkin_1"
appName="FLVPlayer"
streamName="<![CDATA[content_low, 50, content_mid, 150, content]]>"
isLive="false" bufferTime="2">

as i've said before, i typically use Sorenson Squeeze to "rip" video clips to FLV format, and then upload them to a directory on the webserver... afterwards, i pipe in the name of the vid file into a javascript function that simply writes the flash vid player code to the page, loading the video file of my choice... really is pretty easy, though it does tend to take me a few minutes and a few steps to do it.... on the flipside, i enjoy posting lil vid clips that catch my eye... heh.

p.s. i need to get a copy of 4.3....

CF on Wheels

doesnt seem like CF has gotten much luv around here in awhile, so here's something i found pretty damn kewl awhile back and forgot about until the other day... you've all heard about Ruby on Rails, and the noise it's made in development circles, so is it really all that surprising that some engineer'n CF guru's came up with ColdFusion on Wheels? Wink

ColdFusion on Wheels

speaking of kewl, here's something that emil hit me with, which is pretty spiffy -- esp. if you look into the code'age... Canvas in IE (demo)

speaking of code'age, here's one that i saw over at the Daily WTF and for some reason kinda stuck... figured some of ya might get a kick outta it, too... heh.

Nathan: Steve, you know how ++ will increment, right?
Steve: Right ....
Nathan: Okay, so how do you increment by 11?

interesting, in a geeky sorta way, to read through the comments.

CF: PDA Sniffer

i'm pretty sure that i've blogged or posted this code before, but i might be wrong... anywho, i just got pinged with two quick emails asking for some code'age, so i figure i might as well just go ahead and post it in case anybody else is curious... it's not complicated or overly fancy, but it works. course, i use ColdFusion around here, but logic is logic, no matter what language or platform you're running with Wink

CF Code: Sniff Mobil Agents

<!--- Catch Mobile/PDA's and redirect --->
<cfset httpCatchWords = "PDA,PalmOS,PalmSource,
	Blackberry,Nokia,Windows CE,Symbian,Smartphone,
	ReqwirelessWeb,SonyEricsson,WhatsUp" />
<cfloop list="#httpCatchWords#" index="cw">
  <cfif FindNoCase(cw,cgi.http_user_agent)>
    <cfset isMobile = 1 />
    <cfbreak />
  </cfif>
</cfloop>

<cfif isMobile>
  <cflocation url = "/pda/" addtoken="no" />
  <cfabort />
</cfif>

as mentioned in the previous post, if you have any agents (keywords) that you think i'm missing from the list being looked for in the http_user_agent string, lemme know and i'll add it to the list... these are just the ones i knew of off the top of my head back when i added this to my main template here... if it see's one of these words in the agent string, it'll automatically redirect to the PDA version of my site.

CF:Template Code

i've been asked about the CF code i use in my main template here at least twice in the last day, so i figure i'll go ahead and just post it... in case anybody else out there finds it of interest. basically, you set a param with the default page to include into your main template, and then you can pass in new pages to be included via the URL paramater.

ColdFusion Code:

<cfparam name="inc" default="blog" />

<cfset dir = GetDirectoryFromPath(GetCurrentTemplatePath()) />
<cfsetting enablecfoutputonly="yes">
  <cfif Len(inc) LT 1 OR CompareNoCase(inc, "index.cfm") EQ 0 
      OR FileExists("#dir##inc#.cfm") IS "false">
    <cfset inc="blog" />
  </cfif>
<cfsetting enablecfoutputonly="no">
<cfinclude template="#inc#.cfm" />

as usual, there's probably a dozen different ways to go about it, but this is pretty much the way i've been doing it for the last couple years on most of my sites.

RSS Function()

i got an email from a buddy asking if i'd share some CF code for parse'n an RSS feed... i've blogged and posted some code before, but being the lazy punk that i am, i simply copy/pasted some of my code into a quick reply email... figured i'd go ahead and post another blog with it, in case there's anybody else looking for a quick CF function() to use... here's the UDF function that i use to parse/display the feeds shown in the FooNews "ajax" tab above:
<!--- Function: getRSS_Feed() --->
<cffunction name="getRSS_Feed" returntype="string">
  <!--- Pass in RSS Feed to parse, default is yahoo top stories --->
  <cfargument name="feed" type="string" 
                default="yahoo_topstories" required="false" />
  <!--- Pass in Count param, how many to display back --->
  <cfargument name="count" type="numeric" default="5" required="false" />
  <!--- This variable is for this function's use only --->
  <cfset var feedContent = "" />	
  <cfset var rssfeedfile = "" />
  <cfsavecontent variable="feedContent">		
    <cfset xmlFeed = "./xml/" & arguments.feed & ".xml" />
    <cfset RSSFeedPath = ExpandPath(xmlFeed) />
    <cffile action="read" file="#RSSFeedPath#" variable="rssfeedfile" />		
    <cfset myXMLDoc = XMLParse(rssfeedfile) />
    <cfset myItems = XMLSearch(myXMLDoc, "/rss/channel/item") />
    <cfset loopLen = arrayLen(myItems) />
    <cfoutput>
    <ul>		
      <cfloop from="1" to="#count#" index="i">
      <li>
        <a href="#myItems[i].link.xmltext#" 
          title="#myItems[i].title.xmltext#">#myItems[i].title.xmltext#
        </a></li>
      </cfloop>		
    </ul>	
    </cfoutput>		
  </cfsavecontent>	
  <cfreturn feedContent />	
</cffunction>

the default feed i use is the Yahoo! Topstories feed, but if i want to pass in another local RSS feed that get's pulled and saved to the webserver every hour, i simply pass in the name of the XML file, like this:

<cfset getRSS_Digg = getRSS_Feed('digg') />
<cfoutput>#getRSS_Digg#</cfoutput>

which would pull in the digg.xml file into the function, parse it, and spit it out in a ul/li format.

if you happen to be looking for something like this, well, i hope it helps Wink

Update: Related Posts

last week i had the misfortune of Homesite taking a nose dive right when i was saving the backend UDF library of queries that i have running alot of the query functions around here... and i've had to slowly figure out which ones i had, so i could re-code them out... i've managed to do most of them, i think, though i know i still have a few out there that i've missed — which really sucks, since alot of time has gone into them over the last year or so. *sigh*

anyfoo, i just added another backend query function, getBlogByCategory(), that takes two arguements... the blog CategoryID and the number of posts to return, so i can call on the function from any page with something like this:

<cfset blogByCat = getBlogByCategory(#val(query.category_id)#,5) />

which would return the latest 5 blog posts per the category i pass into it.

been quite awhile since i've actually touched or added anything to my homegrown FooBlog code, so that's kewl... now you'll see the latest few blog entries listed under the post/permalink you're viewing over in the sidebar area... not a big deal, but i thought it's a nice little addition and probably something i should've added a long time ago Wink

the sudden impulse came a lil bit ago when i hit some blog, and they had the last 10 blog entries listed over on the right... which i thought was kinda odd, since i'm on the blog and it already has all of them displayed on the page... so why would i need the extra links pointing to what i have right in front of my eyeballs? which got me to thinking, so i hoped over into Homesite...

update: i also added a "Flickr" tab to the top nav.....

GTalk and CF7

now this is pretty damn kewl, and something i hadn't even thought about... taking advantage of the new Gateways in ColdFusion 7 to connect and interact with Google Talk — how effin badass would that be? Big Smile

Google-Talk and the ColdFusion MX 7 XMPP IM Gateway

Since Google's new Instant Messaging network and IM client, "Google-Talk" is based on the Jabber/XMPP IM protocol standard, as has been noted by some already in the ColdFusion community, you can indeed use the Jabber/XMPP IM Gateway included with Macromedia ColdFusion MX 7 to connect to the Google-Talk IM Service network. And as Google says on their Google-Talk Developer page, Google wants to "...encourage the developer community to create new and innovative applications that leverage our service."

The Jabber/XMPP protocol standard has been reviewed and formalized by the IETF and W3C and that's one of the reasons we picked the XMPP IM protocol to include with ColdFusion MX 7.

One of the things that's particularly interesting about Google-Talk using an IM standard protocol is that for the first time, a major IM network is potentially accessible to application developers (depending on Google's final user agreement with the Google-Talk network of course).

All kinds of interesting applications can be created using IM "bots" that can represent Enterprise entities such as ERP systems, etc, and the fact that a ColdFusion CFC can "know" when you're online (presence) can really make things interesting. An application can automatically IM the support rep that's currently online, for example, increasing the chances of a faster response. A PO system "bot" might send an IM to a manager or VP asking for approval for a PO, since it saw he/she was currently online, or escalate to someone who IS online if a PO request is getting stale needs immediate attention.

Another super-cool idea is to use the "status" of an online entity/buddy/bot to communicate real-time data that's constantly changing. In the case of this type of data, you only care about the latest possible value (stock price, for example). Using the IM Gateway Helper "setStattus()" function allows you to set a custom status message for a bot that buddies can see. This can be a great way to keep buddies (or subscribers to the "bot") instantly up to date. They'll see the highly visible message or data just by glancing at the "bot" in their buddy list. This saves potentially oodles of email update status messages, where all you'd care about is the last one anyway.

(hat tip: chris)