<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Rob O&#039;Brien &#187; ColdFusion</title>
	<atom:link href="http://blog.robobrien.com/category/development/coldfusion/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.robobrien.com</link>
	<description>ColdFusion. eCommerce. Marketing. Ramblings.</description>
	<lastBuildDate>Fri, 10 Jun 2011 20:56:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Creating a URL Scope in Javascript</title>
		<link>http://blog.robobrien.com/creating-a-url-scope-in-javascript/</link>
		<comments>http://blog.robobrien.com/creating-a-url-scope-in-javascript/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 20:13:09 +0000</pubDate>
		<dc:creator>Rob  O&#39;Brien</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.robobrien.com/?p=343</guid>
		<description><![CDATA[A Little Background I am involved in a project with a major airline, which has allowed me to devote the majority of my coding effort to Front-End (HTML/CSS/JS) development. This position has really allowed me to hone my Javascript skills and it's been a lot of fun to dive into best practices &#8212; I'm a [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.robobrien.com%2Fcreating-a-url-scope-in-javascript%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.robobrien.com%2Fcreating-a-url-scope-in-javascript%2F&amp;source=RobOBrien&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<h1>A Little Background</h1>
<p>I am involved in a project with a major airline, which has allowed me to devote the majority of my coding effort to Front-End (HTML/CSS/JS) development. This position has really allowed me to hone my Javascript skills and it's been a lot of fun to dive into best practices &#151; I'm a nerd and I love it.</p>
<p>However, as a ColdFusion developer, I've missed some of the functionality that CF has built-in. There's a great project out there for CF developers called <a href="http://bit.ly/f5GsMm" target="_blank" rel="nofollow">CFJS</a>, which mimics CF functionality in JS. You should really check out, but this project doesn't include something very useful: The URL scope. </p>
<p><span id="more-343"></span></p>
<h1>The Problem</h1>
<p>What's the best way to access URL parameters in Javascript? </p>
<p>CF has the URL scope, which is something always took for granted. But JS doesn't have this concept, so what can we do to solve this?</p>
<h1>The Solution</h1>
<p>In order to mimic the URL scope concept from CF, I created a tiny little function in Javascript to parse a URL and provide us with a URL scope. </p>
<p><i>* Note: This solution is definitely not limited to CF developers. I think it's very useful for all JS developers.</i></p>
<p>Do a Google search for "<a href="http://bit.ly/efNYqW" target="_blank" rel="nofollow">javascript url query</a>" and you'll most likely find a function like this:</p>
<div class="CodeBlock"><pre class="javascript">&nbsp;
<span style="color: #003366; font-weight: bold;">function</span> gup<span style="color: #66cc66;">&#40;</span><span style="color: #000066;">name</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
    <span style="color: #000066;">name</span> = <span style="color: #000066;">name</span>.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066FF;">/<span style="color: #66cc66;">&#91;</span>\<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>/</span>, <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\[</span>&quot;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">replace</span><span style="color: #66cc66;">&#40;</span><span style="color: #0066FF;">/<span style="color: #66cc66;">&#91;</span>\<span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span>/</span>, <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\]</span>&quot;</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #003366; font-weight: bold;">var</span> regexS = <span style="color: #3366CC;">&quot;[<span style="color: #000099; font-weight: bold;">\\</span>?&amp;]&quot;</span> + <span style="color: #000066;">name</span> + <span style="color: #3366CC;">&quot;=([^&amp;#]*)&quot;</span>;
    <span style="color: #003366; font-weight: bold;">var</span> regex = <span style="color: #003366; font-weight: bold;">new</span> RegExp<span style="color: #66cc66;">&#40;</span>regexS<span style="color: #66cc66;">&#41;</span>;
    <span style="color: #003366; font-weight: bold;">var</span> results = regex.<span style="color: #006600;">exec</span><span style="color: #66cc66;">&#40;</span>window.<span style="color: #006600;">location</span>.<span style="color: #006600;">href</span><span style="color: #66cc66;">&#41;</span>;
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>results == <span style="color: #003366; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #3366CC;">&quot;&quot;</span>;
    <span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">return</span> results<span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #66cc66;">&#93;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre></div>
<p>So, for example, if you have this URL:</p>
<p>http://blog.robobrien.com/?bob=123&frank=321&tom=213#top</p>
<p>You would get the value of "frank" like this:</p>
<div class="CodeBlock"><pre class="javascript">&nbsp;
<span style="color: #009900; font-style: italic;">/* Get value */</span>
<span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span>gup<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'frank'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;
<span style="color: #009900; font-style: italic;">/* Test for existence */</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span>gup<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'frank'</span><span style="color: #66cc66;">&#41;</span> != <span style="color: #3366CC;">''</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'Frank is alive! '</span> + gup<span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'frank'</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre></div>
<p>It's popular. It works. It's dandy. But, can we make it better? I don't like that it re-parses the URL every time we call "gup()", I don't like that we have to test for an empty string to determine a parameter's existence (what if it exists, but is blank?), and I don't like that it uses RegExp (who can read that?!)</p>
<p>Here's the solution I created and have used in multiple projects:</p>
<div class="CodeBlock"><pre class="javascript">&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>location<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #003366; font-weight: bold;">var</span> url = window.<span style="color: #006600;">url</span> = <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>,
		query = location.<span style="color: #006600;">search</span>.<span style="color: #006600;">substr</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #66cc66;">&#41;</span>,
		arrParams = <span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>,
		param = <span style="color: #3366CC;">''</span>;
		len = <span style="color: #CC0000;">0</span>,
		i = <span style="color: #CC0000;">0</span>;
	url._location = location;
&nbsp;
	arrParams = query.<span style="color: #006600;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;&amp;&quot;</span><span style="color: #66cc66;">&#41;</span>;
	len = arrParams.<span style="color: #006600;">length</span>
	<span style="color: #000066; font-weight: bold;">for</span> <span style="color: #66cc66;">&#40;</span>i=<span style="color: #CC0000;">0</span>; i&lt;len; i++<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
		param = arrParams<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;=&quot;</span><span style="color: #66cc66;">&#41;</span>;
		url<span style="color: #66cc66;">&#91;</span>param<span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span> = unescape<span style="color: #66cc66;">&#40;</span>param<span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span>;
	<span style="color: #66cc66;">&#125;</span>
<span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>document.<span style="color: #006600;">location</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre></div>
<p>Bam! We're done. Errr... wait, what?</p>
<p>Rather than just saying, "Here's a function. Use it!" Let's dig a little deeper...</p>
<p>First, I want to tackle the structure of the function. It may look a little odd at first, but it makes our lives better. This is an anonymous, self-executing function. That means it does not have a name assigned to it and it will execute itself as soon as it's loaded. There are two reasons I do this. </p>
<ol>
<li>I only need to run the function once (which is also a performance boost over gup), so there's no need to name it and add a variable to the global namespace.
<li>It helps with minification.
</ol>
<p>Next, let's talk about the "var" declaration. This ensures that all of our variables are local to the function. This means they're not available outside of the function and, more importantly, we don't have to worry about outside variables conflicting with our local variables. This will also help with minification.</p>
<p>Finally, the meat of our function: Parsing the URL. Every major browser supports the Javascript's Location Object. It contains information about the current URL for your page. So, we pass "document.location" into our function and start tearing it apart. </p>
<p>The first thing we do is save the Location Object to a new variable, "url._location". This is done for no other reason than convenience. Since all of our parsed data will live in the "window.url" object, let's make the rest of it available here, too. </p>
<p>Then, we split the query string into pieces (an array) and loop over them to create dynamically named name-value pairs within the "url" object. By doing this, we make the URL params into native JS variables for easy access. That's all there is to it.</p>
<p>So, take our earlier example URL:</p>
<p>http://blog.robobrien.com/?bob=123&frank=321&tom=213#top</p>
<p>After using our new function, we can reference the URL variables more elegantly:</p>
<div class="CodeBlock"><pre class="javascript">&nbsp;
<span style="color: #009900; font-style: italic;">/* Get value */</span>
<span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span>url.<span style="color: #006600;">frank</span><span style="color: #66cc66;">&#41;</span>; 
&nbsp;
<span style="color: #009900; font-style: italic;">/* Test for existence */</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'frank'</span> <span style="color: #000066; font-weight: bold;">in</span> url<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span>
	<span style="color: #000066;">alert</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">'Frank is alive! '</span> + url.<span style="color: #006600;">frank</span><span style="color: #66cc66;">&#41;</span>;
<span style="color: #66cc66;">&#125;</span>
&nbsp;</pre></div>
<p>If you use a development tool like Firebug (you are, right?), then you can go to your "Script" tab and on the right side, in the "Watch" tab, type in "url" and explore the new object we've created.</p>
<p>Here's a screenshot:</p>
<p><img src="http://blog.robobrien.com/wp-content/uploads/2010/12/URLScope.PNG"></p>
<h1>On Minification</h1>
<p>Minification is a monster all its own. I've mentioned it a few times in this article, so I want to address it quickly, but I won't go into detail.</p>
<p>First, what is minification? You would have to be under a rock or brand new to JS if you haven't heard of it. It's a way to make your code smaller, but still retain its functionality. It's an important concept in website performance. Read its <a href="http://bit.ly/hxNM1l" target="_blank" rel="nofollow">Wikipedia</a> article for more info.</p>
<p>I write all of my JS in a way that will (hopefully) maximize the benefits of minifcation. Not only will you boost your site's performance, but the process of writing minifiable (that can't be a real word...?) code will help you write better, more solid code. </p>
<p>I use Google's online <a href="http://bit.ly/dYAZRk" target="_blank" rel="nofollow">Closure Compiler</a> to minify my code. I definitely minify all of my code before using it on a production website, but I also minify it as I develop, too. This way, I can see the effects of minification and tweak my code to squeeze more bytes out of my scripts.</p>
<p>Our new function, for example, minifies down to this:</p>
<div class="CodeBlock"><pre class="javascript">&nbsp;
<span style="color: #66cc66;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span>c<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span><span style="color: #003366; font-weight: bold;">var</span> d=window.<span style="color: #006600;">url</span>=<span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>,e=c.<span style="color: #006600;">search</span>.<span style="color: #006600;">substr</span><span style="color: #66cc66;">&#40;</span><span style="color: #CC0000;">1</span><span style="color: #66cc66;">&#41;</span>,a=<span style="color: #66cc66;">&#91;</span><span style="color: #66cc66;">&#93;</span>,b=<span style="color: #3366CC;">&quot;&quot;</span>;i=len=<span style="color: #CC0000;">0</span>;d._location=c;a=e.<span style="color: #006600;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;&amp;&quot;</span><span style="color: #66cc66;">&#41;</span>;len=a.<span style="color: #006600;">length</span>;for<span style="color: #66cc66;">&#40;</span>i=<span style="color: #CC0000;">0</span>;i&lt;len;i++<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#123;</span>b=a<span style="color: #66cc66;">&#91;</span>i<span style="color: #66cc66;">&#93;</span>.<span style="color: #006600;">split</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;=&quot;</span><span style="color: #66cc66;">&#41;</span>;d<span style="color: #66cc66;">&#91;</span>b<span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#93;</span>=unescape<span style="color: #66cc66;">&#40;</span>b<span style="color: #66cc66;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #66cc66;">&#93;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#125;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#40;</span>document.<span style="color: #006600;">location</span><span style="color: #66cc66;">&#41;</span>;
&nbsp;</pre></div>
<p>The original code is 325 bytes and is now 196 bytes. That's nearly a 40% savings. Granted, it may not seem like much at this small scale, but it will definitely add up over the life of a project and a lot more JS.</p>
<p>Hopefully that gets you off on the right foot. I look forward to your comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robobrien.com/creating-a-url-scope-in-javascript/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>New Site: TweetPhrases</title>
		<link>http://blog.robobrien.com/new-site-tweet-phrases/</link>
		<comments>http://blog.robobrien.com/new-site-tweet-phrases/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 20:39:52 +0000</pubDate>
		<dc:creator>Rob  O&#39;Brien</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Twitter]]></category>

		<guid isPermaLink="false">http://blog.robobrien.com/?p=205</guid>
		<description><![CDATA[Social Media Recently, I've been working on a few projects that involve Twitter. Integration, promotion, brand building, etc. I've also become involved in a local Social Media Club to keep the pulse of the online community and stay on top of the latest trends. It's really given me a chance to use Twitter and, more [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.robobrien.com%2Fnew-site-tweet-phrases%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.robobrien.com%2Fnew-site-tweet-phrases%2F&amp;source=RobOBrien&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<h1>Social Media</h1>
<p>Recently, I've been working on a few projects that involve Twitter. Integration, promotion, brand building, etc. I've also become involved in a local Social Media Club to keep the pulse of the online community and stay on top of the latest trends. It's really given me a chance to use Twitter and, more importantly, watch how other people use Twitter. It's led me to a new project that I'd like to share with you...</p>
<h1>A little back-story...</h1>
<p>What's been really interesting to me, personally, is how I react to what other people are willing to throw out onto the web without much thought or hesitation. It's not always a good thing, but neither is it always a bad thing. It actually makes for some really interesting reading. Sometimes, I'll find something interesting and decide to create a connection. Other times, a random person will say something to nonsensical or irrelevant that I'll unfollow them on the spot. It's the ebb and flow of social interaction. It's how all people function in real life.</p>
<p>But what always piqued my curiosity was how common phrases are used throughout our society on a macro level. Not just online, although Twitter gives us a great way to instantly view them. They've manifested themselves in Twitter hash tags, but I think they should be a little more organic than that in order to open up the social interaction. Even at the loss of subject-specific focus. So, I started searching Twitter for a few common phrases and really liked what I found. They were intriguing. Emotionally charged. And yes, sometimes complete crap. All-in-all, very interesting. So, I launched a website to share those phrases (and more)  with the world.</p>
<h1>TweetPhrases.com</h1>
<p>So, the whole point of this article is to launch my site, yea? The new site is <a href="http://tweetphrases.com/">TweetPhrases.com</a>. It's simple. It's straightforward. It's an ever evolving, real time look at what people are saying on Twitter. Limited only, of course, by the use of a selected phrase. The presentation of the tweets is what I really love. It's bold and in your face. Boom!</p>
<p>Check it out. Let me know what you think. If there are other phrases I should consider, don't be afraid to suggest them. I'm viewing this as a social experiment, so I want it to be very organic.</p>
<h1>Geek Love</h1>
<p>I have to give a little love to <a href="http://www.adobe.com/products/coldfusion/" target="_blank" rel="nofollow">ColdFusion</a>, the language used to create TweetPhrases. I am, after all, a ColdFusion developer and I like to promote it whenever I get the chance. It's a great language that allowed me to pop up this site very quickly.</p>
<p>Finally, I would be completely remiss if I didn't acknowledge great inspiration from another website, <a href="http://twistori.com/" target="_blank" rel="nofollow">Twistori</a>. When I came up with my concept, I quickly realized there was something similar out there already. They have a great site and I want to thank them for my inspiration.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.robobrien.com/new-site-tweet-phrases/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Compound Assignment Operators in ColdFusion</title>
		<link>http://blog.robobrien.com/compound-assignment-operators-in-coldfusion/</link>
		<comments>http://blog.robobrien.com/compound-assignment-operators-in-coldfusion/#comments</comments>
		<pubDate>Sun, 09 Aug 2009 15:45:20 +0000</pubDate>
		<dc:creator>Rob  O&#39;Brien</dc:creator>
				<category><![CDATA[ColdFusion]]></category>

		<guid isPermaLink="false">http://blog.robobrien.com/?p=131</guid>
		<description><![CDATA[As the ColdFusion community gears up for the release of ColdFusion 9, I'd like to take a step back for a moment to reflect on a great addition to CF 8 that probably gets overlooked quite a bit, since it's not a feature that would draw a lot of attention. Enter: Compound Assignment Operators! oooOOoooo... [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.robobrien.com%2Fcompound-assignment-operators-in-coldfusion%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.robobrien.com%2Fcompound-assignment-operators-in-coldfusion%2F&amp;source=RobOBrien&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>As the ColdFusion community gears up for the release of <a href="http://labs.adobe.com/technologies/coldfusion9/" target="_blank">ColdFusion 9</a>, I'd like to take a step back for a moment to reflect on a great addition to CF 8 that probably gets overlooked quite a bit, since it's not a feature that would draw a lot of attention. </p>
<h1>Enter: Compound Assignment Operators!</h1>
<p>oooOOoooo... sexy, right?</p>
<p>A little history... Back in the day when I was cutting my teeth on C programming, I was able to manipulate variables with a few shorthand strokes of the keyboard. It was easy; it was elegant. To accomplish the same tasks in CF, I needed to be redundant in my typing. I hated it.</p>
<p>Then, as I was preparing a new write-up in my <a href="http://blog.robobrien.com/tag/udf/">UDF Series</a>, I realized that I used a compound operator in the function. I started to explain what it was all about and how/why to modify the function if you're still using releases prior to CF8. But, I also realized that I'm long-winded. That means that my explanation turned into a full-blown rant, worthy of its own post. So, here we are.</p>
<h1>Examples</h1>
<p>Let's dig right into some examples to help understand where we were before compound operators. </p>
<p>Here's an example of incrementing a value in CF7 (using cfscript):</p>
<div class="CodeBlock"><pre class="c">&nbsp;
myValue = myValue + <span style="color: #cc66cc;">5</span>;
&nbsp;</pre></div>
<p>...or like this (using tags):</p>
<div class="CodeBlock"><pre class="cfm">&nbsp;
<span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> myValue <span style="color: #0000FF">=</span> myValue + <span style="color: #FF0000;">5</span>&gt;</span>
&nbsp;</pre></div>
<p>To accomplish the same task in C (and most other languages):</p>
<div class="CodeBlock"><pre class="c">&nbsp;
myValue += <span style="color: #cc66cc;">5</span>;
&nbsp;</pre></div>
<p>The difference should be pretty obvious. The C style is clean, simple and elegant. CF7 is redundant.</p>
<p>Now, I'll admit that my code isn't always the cleanest or most elegant. But, it really bummed me out that I was required to type the variable name twice in ColdFusion. It may not seem like a big deal, but it all adds up over time when you consider all of the code that you output in a day... a month... a career.</p>
<p>Then comes CF8 and the world (or maybe just me) rejoices!</p>
<h1>How it Works</h1>
<p>Using a compound operator is so simple that it may not be immediately clear what's happening. In this example, we're using the compound operator "+="  to perform two concurrent actions on <i>myValue</i>; both the + and the =. It's nicely explained by Adobe this way: <i>"The variable on the right is used as both an element in the expression and the result variable. Thus, the expression a += b is equivalent to a = a +b."</i> [<a href="http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Expressions_03.html" target="_blank">source</a>]</p>
<p>Now that we've learned a new trick, we can use it in CF8+ like this:</p>
<div class="CodeBlock"><pre class="cfm">&nbsp;
<span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> myValue +<span style="color: #0000FF">=</span> <span style="color: #FF0000;">5</span>&gt;</span>
&nbsp;</pre></div>
<p>Ahhh... that's reeeeal nice!</p>
<p>Note that I did use the compound operator in a tag. I've seen 2 other blog posts that explicitly state that you can use these operators <i>only</i> in &lt;cfscript&gt;. I'm not sure if they're outdated or just incorrect, but you can definitely use compound operators within tags. Of course, use within &lt;cfscript&gt; works as well.</p>
<h1>Other Operators</h1>
<p>In addition to, well, addition... you can also subtract (-=), multiply (*=), and divide (/=). You can also use it for modulus (%=) and concatenation of strings (&=). There's also incrementing & decrementing by 1 (++ and --). That's pretty spiffy.</p>
<p>You should check out the <a href="http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=Expressions_03.html" target="_blank">Adobe LiveDocs</a> for a full explanation.</p>
<h1>Bottom Line</h1>
<p>The addition of Compound Operators brings CF inline with more traditional syntax of other languages. I was glad to discover it in CF8 and I'm hoping to spread the word to anyone who hasn't discovered this little gem.</p>
<h1>Has this solution saved you time?</h1>
<p>I'm a firm believer in sharing knowledge for the sake of helping someone else. No strings attached. However, we all have bills to pay and hosting to maintain. If you feel like this post has saved you even an hour of development time, would you consider donating that hour to me?</p>
<div style="text-align: center; margin-bottom: 30px;">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input name="cmd" type="hidden" value="_s-xclick" />
<input name="hosted_button_id" type="hidden" value="7224945" />
<input alt="PayPal - The safer, easier way to pay online!" name="submit" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" type="image" />
<img src="https://www.paypal.com/en_US/i/scr/pixel.gif" border="0" alt="" width="1" height="1" /><br />
</form>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.robobrien.com/compound-assignment-operators-in-coldfusion/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>UDF Series: LastDayOfMonth()</title>
		<link>http://blog.robobrien.com/udf-series-lastdayofmonth/</link>
		<comments>http://blog.robobrien.com/udf-series-lastdayofmonth/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 17:49:53 +0000</pubDate>
		<dc:creator>Rob  O&#39;Brien</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[UDF]]></category>

		<guid isPermaLink="false">http://blog.robobrien.com/?p=106</guid>
		<description><![CDATA[Starting today and continuing sporadically, I will release some of my UDF library to the public. None of it is ultimately earth-shattering nor are all of them unique (CFLib.org is a great collection), but I realized that I do have some decent functions or variations of existing functions that could be helpful to other developers. [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.robobrien.com%2Fudf-series-lastdayofmonth%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.robobrien.com%2Fudf-series-lastdayofmonth%2F&amp;source=RobOBrien&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Starting today and continuing sporadically, I will release some of my UDF library to the public. None of it is ultimately earth-shattering nor are all of them unique (<a href="http://cflib.org/" target="_blank">CFLib.org</a> is a great collection), but I realized that I do have some decent functions or variations of existing functions that could be helpful to other developers.</p>
<p>To start things off, here's a very simple function that will return the last day of any given month. It's easy, straightforward and very useful. I'm surprised that it's not directly included in CF.</p>
<div class="CodeBlock"><pre class="cfm">&nbsp;
<span style="color: #333333;"><span style="color: #990000;">&lt;cffunction</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">&quot;LastDayOfMonth&quot;</span> <span style="color: #0000FF">access</span>=<span style="color: #009900;">&quot;public&quot;</span> returntype=<span style="color: #009900;">&quot;date&quot;</span><span style="color: #990000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #990000;">&lt;cfargument</span> <span style="color: #0000FF;">name</span>=<span style="color: #009900;">&quot;Date&quot;</span> <span style="color: #0000FF;">type</span>=<span style="color: #009900;">&quot;date&quot;</span> <span style="color: #0000FF">required</span>=<span style="color: #009900;">&quot;yes&quot;</span><span style="color: #990000;">&gt;</span></span>
	<span style="color: #333333;"><span style="color: #990000;">&lt;cfreturn</span> <span style="color: #0000FF;">CreateDate</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">year</span><span style="color: #0000FF;">&#40;</span>Arguments.Date<span style="color: #0000FF;">&#41;</span>,<span style="color: #0000FF;">month</span><span style="color: #0000FF;">&#40;</span>Arguments.Date<span style="color: #0000FF;">&#41;</span>,<span style="color: #0000FF;">DaysInMonth</span><span style="color: #0000FF;">&#40;</span>Arguments.Date<span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span><span style="color: #990000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #990000;">&lt;/cffunction&gt;</span></span>
&nbsp;</pre></div>
<p>In order to use it, just pass in any valid date value:</p>
<div class="CodeBlock"><pre class="cfm">&nbsp;
<span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> LastDay <span style="color: #0000FF">=</span> LastDayOfMonth<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">now</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #0000FF;">&#41;</span><span style="color: #990000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> LastDay <span style="color: #0000FF">=</span> LastDayOfMonth<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;3/17/2009&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #990000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> LastDay <span style="color: #0000FF">=</span> LastDayOfMonth<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;March 17, 2009&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #990000;">&gt;</span></span>
&nbsp;</pre></div>
<p>And you'll get a nice and tidy date value back:</p>
<div class="CodeBlock"><pre class="cfm">&nbsp;
{ts '2009-03-31 00:00:00'}
&nbsp;</pre></div>
<p>That's all there is to it. Like I said, nothing earth-shattering. Hopefully just helpful knowledge.</p>
<h1>Has this solution saved you time?</h1>
<p>I'm a firm believer in sharing knowledge for the sake of helping someone else. No strings attached. However, we all have bills to pay and hosting to maintain. If you feel like this post has saved you even an hour of development time, would you consider donating that hour to me?</p>
<div style="text-align: center; margin-bottom: 30px;">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input name="cmd" type="hidden" value="_s-xclick" />
<input name="hosted_button_id" type="hidden" value="7224945" />
<input alt="PayPal - The safer, easier way to pay online!" name="submit" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" type="image" />
<img src="https://www.paypal.com/en_US/i/scr/pixel.gif" border="0" alt="" width="1" height="1" /><br />
</form>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.robobrien.com/udf-series-lastdayofmonth/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating Twitter and OAuth with ColdFusion</title>
		<link>http://blog.robobrien.com/integrating-twitter-and-oauth-with-coldfusion/</link>
		<comments>http://blog.robobrien.com/integrating-twitter-and-oauth-with-coldfusion/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 22:07:18 +0000</pubDate>
		<dc:creator>Rob  O&#39;Brien</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Twitter]]></category>
		<category><![CDATA[OAuth]]></category>
		<category><![CDATA[Twitter4J]]></category>

		<guid isPermaLink="false">http://blog.robobrien.com/?p=7</guid>
		<description><![CDATA[Update: This article was written in 2009 and Twitter4J has significantly changed since that time. Several visitors have said that the instructions here do not reflect the most recent method names in Twitter4J. It seems that the newest version -- 2.2.x -- is incompatible with 2.1.x. You can view the official version logs for more [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.robobrien.com%2Fintegrating-twitter-and-oauth-with-coldfusion%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.robobrien.com%2Fintegrating-twitter-and-oauth-with-coldfusion%2F&amp;source=RobOBrien&amp;style=normal&amp;service=bit.ly&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<div id="update" style="border: 1px solid red;background-color: pink;padding: 12px;margin-bottom: 10px;width: 540px;">
<strong>Update:</strong> This article was written in 2009 and Twitter4J has significantly changed since that time. Several visitors have said that the instructions here do not reflect the most recent method names in Twitter4J. It seems that the newest version -- 2.2.x -- is incompatible with 2.1.x. You can view the <a href="http://twitter4j.org/en/versions.html" target="_blank">official version logs</a> for more info.
<div style="margin-top: 10px;">I hope to find time to update this article in the near future. Until then, I believe the <strong>process</strong> described in the article is still valid.</div>
</div>
<h1>Adventures of Twitter Integration</h1>
<p>So, it turns out that the timing of my new blog couldn't be better. I actually have something valuable to share!</p>
<p>Recently, I was tasked with integrating Twitter into a website that I work on (<a href="http://www.rinktime.com/" target="_blank">RinkTime.com</a>). I initially thought it would be a piece of cake because there's always another developer out there who has shared code for a similar concept. Imagine my surprise (and ultimately, frustration) when there wasn't any example or even good documentation to learn from.</p>
<p>Well, I finally figured it out and now I'd like to share my knowledge with the ColdFusion community.</p>
<p><span id="more-7"></span></p>
<h1>The Goal</h1>
<p>My goal was to integrate Twitter using ColdFusion and the <a href="http://oauth.net/">OAuth</a> protocol. Twitter has said that they want to switch over to OAuth in the future, so I want to develop my app in a way that won't be obsolete 6 months or a year down the road. Plus, I won't have to deal with the security of users' login credentials.</p>
<p>My first stop was the <a href="http://apiwiki.twitter.com/Libraries#Coldfusion" target="_blank">Twitter API wiki</a>, which has a couple ColdFusion libraries for the Twitter API, but neither takes advantage of OAuth. I bet they're both great solutions, but the lack of OAuth was a deal breaker for me.</p>
<p>Then I found <a href="http://yusuke.homeip.net/twitter4j/en/index.html" target="_blank">Twitter4J</a> by <a href="http://twitter.com/yusukeyamamoto" target="_blank">Yusuke Yamamoto</a>. It's a Java solution with OAuth support. Score!</p>
<h1>The Authentication Process</h1>
<p>This is where I had the most trouble. I just couldn't seem to get a straight answer on the step-by-step details for the authentication process. It's actually pretty straightforward -- if it's laid out nicely. Luckily, that's exactly what I've done here:</p>
<ol>
<li>Within the application, generate a Request Token and a Request Secret.</li>
<li>Using Twitter's authorization URL, you send the user to Twitter's website so that the user can Allow or Deny access to your application.</li>
<li>Presuming the user allows access, they are then redirected back to your application based upon the Callback URL you specify when registering with Twitter.</li>
<li>Once the user is back on your site, you have to swap out the Request Tokens for Access Tokens. This is the magic step where you finally gain access to the user's Twitter account.</li>
<li>Store the Access Tokens for future use however you'd like -- I store them in a database. They never expire, although they can be rejected in the future if the user chooses, so make sure you do your error checking.</li>
<li>Each time you want to access the user's account, you pull out the Access Tokens and go to town.</li>
</ol>
<p>Of course, there's a lot more that goes on behind-the-scenes, but for the scope of this write-up, that's all we really need to know.</p>
<h1>The Solution</h1>
<ol>
<li>Register your application with Twitter <a href="http://twitter.com/oauth_clients/">here</a> and keep the Consumer Key &amp; Secret values handy.</li>
<li>Download <a href="http://yusuke.homeip.net/twitter4j/en/index.html">Twitter4J</a></li>
<li> Install the JAR file in ColdFusion. You'll want to place it in an existing Class Path (like "C:\ColdFusion8\lib\") or you can set up a new Class Path in "CF Admin &gt; Server Settings &gt; Java and JVM". Then restart CF.</li>
<li>Create the Java object in your application with the Twitter values from Step 1:
<div class="CodeBlock"><pre class="cfm">&nbsp;
<span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> Twitter <span style="color: #0000FF">=</span> <span style="color: #0000FF;">createObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;java&quot;</span>, <span style="color: #009900;">&quot;twitter4j.Twitter&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #990000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> Twitter.setOAuthConsumer<span style="color: #0000FF;">&#40;</span>TwitterConsumerKey,TwitterConsumerSecret<span style="color: #0000FF;">&#41;</span><span style="color: #990000;">&gt;</span></span>
&nbsp;</pre></div>
</li>
<li>Now we start the authentication process, which is where things get fun. First, we generate our Request tokens to send to Twitter. We have to save the Request Token and Request Secret values for later use when the user is transferred back to the application. I've chosen to do so in Session variables, but this can be accomplished however you'd prefer.
<div class="CodeBlock"><pre class="cfm">&nbsp;
<span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> RequestToken <span style="color: #0000FF">=</span> Twitter.getOAuthRequestToken<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #990000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> Session.oAuthRequestToken <span style="color: #0000FF">=</span> RequestToken.<span style="color: #0000FF;">getToken</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #990000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> Session.oAuthRequestTokenSecret <span style="color: #0000FF">=</span> RequestToken.getTokenSecret<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span><span style="color: #990000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #990000;">&lt;cflocation</span> url=<span style="color: #009900;">&quot;#RequestToken.getAuthorizationURL()#&quot;</span> addtoken=<span style="color: #009900;">&quot;No&quot;</span><span style="color: #990000;">&gt;</span></span>
&nbsp;</pre></div>
</li>
<li>At this point, the user is on Twitter's site and have the opportunity to Allow or Deny access.</li>
<li>After Allowing access, the user is transferred back to your site and you exchange the Request Tokens for Access Tokens:
<div class="CodeBlock"><pre class="cfm">&nbsp;
<span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> AccessToken <span style="color: #0000FF">=</span> Twitter.getOAuthAccessToken<span style="color: #0000FF;">&#40;</span>Session.oAuthRequestToken,Session.oAuthRequestTokenSecret<span style="color: #0000FF;">&#41;</span><span style="color: #990000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #808080; font-style: italic; background-color:#FFFF99;">&lt;!--- Store the Access Tokens, via: AccessToken.getToken() and AccessToken.getTokenSecret() ---&gt;</span></span>
&nbsp;</pre></div>
</li>
<li>Now, with Access Tokens in hand, you have full access to the account.
<p style="margin-top: 10px;"><em>Update: The Authorization process (4-7 above) is only required once per user in order to obtain the user's unique Access Tokens. Only Step 9 needs to be executed each time you want to access the account.</em></p>
</li>
<li>Finally, to use your new powers, you only have to instantiate the Twitter object,  load up a users Access Tokens, and then have fun with all of the methods Twitter4J offers.
<div class="CodeBlock"><pre class="cfm">&nbsp;
<span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> Twitter <span style="color: #0000FF">=</span> <span style="color: #0000FF;">createObject</span><span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;java&quot;</span>, <span style="color: #009900;">&quot;twitter4j.Twitter&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #990000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> Twitter.setOAuthConsumer<span style="color: #0000FF;">&#40;</span>TwitterConsumerKey,TwitterConsumerSecret<span style="color: #0000FF;">&#41;</span><span style="color: #990000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> Twitter.setOAuthAccessToken<span style="color: #0000FF;">&#40;</span>StoredAccessToken,StoredAccessSecret<span style="color: #0000FF;">&#41;</span><span style="color: #990000;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #990000;">&lt;cfset</span> Twitter.updateStatus<span style="color: #0000FF;">&#40;</span><span style="color: #009900;">&quot;My first custom Twitter update! Thanks @RobOBrien!&quot;</span><span style="color: #0000FF;">&#41;</span><span style="color: #990000;">&gt;</span></span>
&nbsp;</pre></div>
</li>
</ol>
<p>Obviously, this only scratches the surface of what you can do with Twitter4J and how you implement the authorization process. What I've explained is a bare bones solution. I've actually wrapped it up in some CFCs and integrated it into my larger application, but that's up to your own situation and techniques.</p>
<p>I hope that this will help prevent the frustration that I had to endure to get this working. If you have any questions, let me know, but I can't promise any true support on this. I'm just sharing the knowledge.</p>
<p>Many thanks to Yusuke for all the work he's put into this library.</p>
<p>Have fun!</p>
<h1>Has this solution saved you time?</h1>
<p>I'm a firm believer in sharing knowledge for the sake of helping someone else. No strings attached. However, we all have bills to pay and hosting to maintain. If you feel like this post has saved you even an hour of development time, would you consider donating that hour to me?</p>
<div style="text-align: center; margin-bottom: 30px;">
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input name="cmd" type="hidden" value="_s-xclick" />
<input name="hosted_button_id" type="hidden" value="7224945" />
<input alt="PayPal - The safer, easier way to pay online!" name="submit" src="https://www.paypal.com/en_US/i/btn/btn_donateCC_LG.gif" type="image" />
<img src="https://www.paypal.com/en_US/i/scr/pixel.gif" border="0" alt="" width="1" height="1" /><br />
</form>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.robobrien.com/integrating-twitter-and-oauth-with-coldfusion/feed/</wfw:commentRss>
		<slash:comments>55</slash:comments>
		</item>
	</channel>
</rss>

