<?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>ShinyLight Development &#187; Languages</title>
	<atom:link href="http://www.shinylight.com/category/languages/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.shinylight.com</link>
	<description>Web Development and Other Goodness in the World of a Software Engineer.</description>
	<lastBuildDate>Mon, 07 Jun 2010 03:02:19 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Tag a Revision using Subclipse</title>
		<link>http://www.shinylight.com/2010/05/20/tag-a-revision-using-subclipse/</link>
		<comments>http://www.shinylight.com/2010/05/20/tag-a-revision-using-subclipse/#comments</comments>
		<pubDate>Thu, 20 May 2010 01:25:09 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Languages]]></category>

		<guid isPermaLink="false">http://www.shinylight.com/?p=973</guid>
		<description><![CDATA[Tagging a revision is a simple task if you&#8217;re using the subclipse plugin for Eclipse. For this example, we&#8217;re going to tag the trunk in our repository. This also assumes that your repository uses the traditional &#8220;3 directory setup&#8221; of branches, tags, and trunk. 
1. Make sure you have a SVN View tab in Eclipse. [...]]]></description>
			<content:encoded><![CDATA[<p>Tagging a revision is a simple task if you&#8217;re using the subclipse plugin for Eclipse. For this example, we&#8217;re going to tag the trunk in our repository. This also assumes that your repository uses the traditional &#8220;3 directory setup&#8221; of branches, tags, and trunk. </p>
<p>1. Make sure you have a SVN View tab in Eclipse. </p>
<p><img src="http://www.shinylight.com/wp-content/uploads/2010/05/0.png" /></p>
<p>To do this, go to:<br />
Window > Show View > Other > SVN > SVN Repositories</p>
<p>2. Under &#8220;WebSites&#8221; (in the following screenshot), right click on the trunk, and select &#8220;Branch/Tag&#8230;&#8221;:</p>
<p><img src="http://www.shinylight.com/wp-content/uploads/2010/05/11.png"  /></p>
<p>3. Make sure you use the appropriate tag version that adheres to your versioning needs. Also, make sure it&#8217;s under the &#8220;tags&#8221; folder: svn://WebSites/Project-2/tags/</p>
<p><img src="http://www.shinylight.com/wp-content/uploads/2010/05/21.png" /></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://www.shinylight.com/2010/05/20/tag-a-revision-using-subclipse/&amp;submitHeadline=Tag+a+Revision+using+Subclipse&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.shinylight.com/2010/05/20/tag-a-revision-using-subclipse/&amp;title=Tag+a+Revision+using+Subclipse" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.shinylight.com/2010/05/20/tag-a-revision-using-subclipse/&amp;title=Tag+a+Revision+using+Subclipse" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://www.shinylight.com/2010/05/20/tag-a-revision-using-subclipse/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.shinylight.com/2010/05/20/tag-a-revision-using-subclipse/&amp;title=Tag+a+Revision+using+Subclipse" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://www.shinylight.com/2010/05/20/tag-a-revision-using-subclipse/&amp;bm_description=Tag+a+Revision+using+Subclipse" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://www.shinylight.com/2010/05/20/tag-a-revision-using-subclipse/&amp;T=Tag+a+Revision+using+Subclipse" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.shinylight.com/2010/05/20/tag-a-revision-using-subclipse/&amp;title=Tag+a+Revision+using+Subclipse" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.shinylight.com/2010/05/20/tag-a-revision-using-subclipse/&amp;title=Tag+a+Revision+using+Subclipse" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.shinylight.com/2010/05/20/tag-a-revision-using-subclipse/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://www.shinylight.com/2010/05/20/tag-a-revision-using-subclipse/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Tag+a+Revision+using+Subclipse+@+http://www.shinylight.com/2010/05/20/tag-a-revision-using-subclipse/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.shinylight.com/2010/05/20/tag-a-revision-using-subclipse/&amp;t=Tag+a+Revision+using+Subclipse" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shinylight.com/2010/05/20/tag-a-revision-using-subclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing the Strategy Pattern in ColdFusion</title>
		<link>http://www.shinylight.com/2010/05/02/implementing-strategy-pattern-coldfusion/</link>
		<comments>http://www.shinylight.com/2010/05/02/implementing-strategy-pattern-coldfusion/#comments</comments>
		<pubDate>Sun, 02 May 2010 03:27:18 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://www.shinylight.com/?p=949</guid>
		<description><![CDATA[In spirit of the amazing book Head First Design Patterns, I wanted to put together a ColdFusion example that depicts the Strategy pattern. Essentially, the Strategy Pattern lets you group related algorithms together so that an object is able to select which algorithm to run at runtime. 
So let&#8217;s say for example you had a [...]]]></description>
			<content:encoded><![CDATA[<p>In spirit of the amazing book <a href="http://www.amazon.com/gp/product/0596007124/">Head First Design Patterns</a>, I wanted to put together a ColdFusion example that depicts the Strategy pattern. Essentially, the Strategy Pattern lets you group related algorithms together so that an object is able to select which algorithm to run at runtime. </p>
<p>So let&#8217;s say for example you had a parent class that has two properties and two methods. You now create a subclass that inherits the parent class, meaning that it will gobble up all the properties and methods (whether you like it or not) from the parent class. You can&#8217;t choose, for example, what methods you subclass needs, even if some methods don&#8217;t make sense for your subclass. It&#8217;s an all-or-nothing solution. Yes, you can override, but what if there were 10 methods to override? Also, what if you had to create other types of subclasses &#8211; you&#8217;ll have to override those as well. Things can get a little sloppy at the end. That&#8217;s where the strategy pattern comes in.</p>
<p>With this pattern, you first think about related methods and algorithms. (One method can have various algorithms; different implementations for doing the same thing.) For this blog post&#8217;s example, we&#8217;ll think of different ways a SuperHero can punch. To keep things simple, let&#8217;s give him two ways (two different algorithms for punching) he can punch. He can punch normally, or he can punch you, which freezes you as well. Let&#8217;s UML this to make things clearer.</p>
<p>First what the lines mean:</p>
<div align="center"><img src="/wp-content/uploads/2010/04/Lines.png"></div>
<p> <br/></p>
<p>Here&#8217;s the UML diagram for our SuperHero scenerio:</p>
<div align="center"><img src="/wp-content/uploads/2010/04/punchonly.png"></div>
<p> <br/></p>
<p>From the diagram, you can see that the SuperHero abstract class is able to choose a punch set of algorithms (a strategy). We also see that Punch and PunchFreeze are implementation classes (classes that serve to implement an interface). Both of them have a punch() method that return void (nothing) &#8211; in this example, they&#8217;ll do stuff, and not return anything. </p>
<p>To make things a little more interesting, and to follow closer the example in the Strategy Pattern chapter of the book, we&#8217;re going to also create a subclass called Freezer that inherits the SuperHero class. Also, we&#8217;ll create another strategy for kicking. Here&#8217;s what the UML for that looks like: </p>
<div align="center"><img src="/wp-content/uploads/2010/04/full.png"></div>
<p> <br/></p>
<p>Here&#8217;s the CF code:</p>
<p><strong>SuperHero.cfc</strong></p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfcomponent</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!--- This is our abstract class. Responsibility to implement is delegated to ---&gt;</span>
<span style="color: #808080; font-style: italic;">&lt;!--- classes that implement interfaces. ---&gt;</span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;init&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;SuperHero&quot;</span><span style="color: #0000FF;">&gt;</span></span>  
  <span style="color: #808080; font-style: italic;">&lt;!--- Some other init code goes here.  ---&gt;</span>  
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;name&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span><span style="color: #0000FF;">&gt;</span></span>  
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;gender&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span><span style="color: #0000FF;">&gt;</span></span>  
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> this.<span style="color: #0000FF;">name</span> <span style="color: #0000FF;">=</span> arguments.<span style="color: #0000FF;">name</span> <span style="color: #0000FF;">/&gt;</span></span>  
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> this.gender <span style="color: #0000FF;">=</span> arguments.gender <span style="color: #0000FF;">/&gt;</span></span>  
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> this <span style="color: #0000FF;">/&gt;</span></span>  
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;setPunchAlgorithm&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #808080; font-style: italic;">&lt;!--- The next two lines are key. It's where you set the implementation ---&gt;</span>
  <span style="color: #808080; font-style: italic;">&lt;!--- of punch from an object that's being passed in. ---&gt;</span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;PunchAlgorithm&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;IPunchAlgorithm&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>  
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> this.punchAction <span style="color: #0000FF;">=</span> PunchAlgorithm.punch <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;setKickAlgorithm&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;KickAlgorithm&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;IKickAlgorithm&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>  
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> this.kickAction <span style="color: #0000FF;">=</span> KickAlgorithm.kick <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!--- This function will be overridden.  ---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;energyProject&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;SuperHero&quot;</span> <span style="color: #0000FF;">&gt;</span></span>  
  You have been pointed at by a weak flash light.  
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> this <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfcomponent</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p><strong>IPunchAlgorithm.cfc</strong></p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span>cfinterface<span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;punch&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span>cfinterface<span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p><strong>Punch.cfc</strong></p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfcomponent</span> implements<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;IPunchAlgorithm&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;punch&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span><span style="color: #0000FF;">&gt;</span></span>
  You have been punched normally. Ouch.
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfcomponent</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p><strong>PunchFreeze.cfc</strong></p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfcomponent</span> implements<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;IPunchAlgorithm&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;punch&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span><span style="color: #0000FF;">&gt;</span></span>
  You have been punched and are now frozen, stuck. Good luck thawing!
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfcomponent</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p><strong>IKickAlgorithm.cfc</strong></p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span>cfinterface<span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;kick&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span>cfinterface<span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p><strong>Kick.cfc</strong></p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfcomponent</span> implements<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;IKickAlgorithm&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;kick&quot;</span> <span style="color: #0000FF;">access</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;public&quot;</span><span style="color: #0000FF;">&gt;</span></span>
  You have been kicked in the gut. Yummy.
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfcomponent</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p><strong>Freezer.cfc</strong></p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfcomponent</span> extends<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;SuperHero&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!--- We are overriding the energyProject from Freezer's parent class.  ---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;energyProject&quot;</span><span style="color: #0000FF;">&gt;</span></span>
  You have been snowed on. 
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span>  
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfcomponent</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Now let&#8217;s actually use these the pattern: </p>
<p><strong>run.cfm</strong></p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!--- Create context object.  ---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> IceMan <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">CreateObject</span><span style="color: #0000FF;">&#40;</span> <span style="color: #009900;">&quot;component&quot;</span>, <span style="color: #009900;">&quot;SuperHero&quot;</span> <span style="color: #0000FF;">&#41;</span>.init<span style="color: #0000FF;">&#40;</span> <span style="color: #0000FF;">Name</span> <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;Iceman&quot;</span>, Gender <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;Male&quot;</span> <span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!--- Create a strategy #1 for punching.  ---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> PunchStrategy_1 <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">CreateObject</span><span style="color: #0000FF;">&#40;</span> <span style="color: #009900;">&quot;component&quot;</span>, <span style="color: #009900;">&quot;Punch&quot;</span> <span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!--- Create a different strategy for punching.  ---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> PunchStrategy_2 <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">CreateObject</span><span style="color: #0000FF;">&#40;</span> <span style="color: #009900;">&quot;component&quot;</span>, <span style="color: #009900;">&quot;PunchFreeze&quot;</span> <span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!--- Tell the IceMan object that you'll be using the Punch Strategy #2, NOT #1.  ---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> IceMan.setPunchAlgorithm<span style="color: #0000FF;">&#40;</span> PunchStrategy_2 <span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!--- Now let's create a kicking strategy... ---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> KickStrategy <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">CreateObject</span><span style="color: #0000FF;">&#40;</span> <span style="color: #009900;">&quot;component&quot;</span>, <span style="color: #009900;">&quot;Kick&quot;</span> <span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!--- ... and now let's tell the IceMan object that you'll be using the Kick Strategy.  ---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> IceMan.setKickAlgorithm<span style="color: #0000FF;">&#40;</span> KickStrategy <span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!--- Now let's see some action!  ---&gt;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!--- Punch, using the strategy chosen! ---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> IceMan.punchAction<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!--- Punch, using the strategy chosen! ---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> IceMan.kickAction<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!--- Let's create another SuperHero object. ---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> Frosty <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">CreateObject</span><span style="color: #0000FF;">&#40;</span> <span style="color: #009900;">&quot;component&quot;</span>, <span style="color: #009900;">&quot;SuperHero&quot;</span> <span style="color: #0000FF;">&#41;</span>.init<span style="color: #0000FF;">&#40;</span> <span style="color: #0000FF;">Name</span> <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;Frosty the Snowman&quot;</span>, Gender <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;Unknown&quot;</span> <span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!--- Let's inspect the objects ---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">p</span><span style="color: #0000FF;">&gt;</span></span>Notice that both objects have different number of methods - only the methods they need. <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">p</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfdump</span> <span style="color: #000000; font-weight: bold;">var</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#IceMan#&quot;</span> <span style="color: #0000FF;">/&gt;</span></span><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">hr</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfdump</span> <span style="color: #000000; font-weight: bold;">var</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#Frosty#&quot;</span> <span style="color: #0000FF;">/&gt;</span></span><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">hr</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;">&lt;!--- Let's create another SuperHero object. ---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> Frostman <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">CreateObject</span><span style="color: #0000FF;">&#40;</span> <span style="color: #009900;">&quot;component&quot;</span>, <span style="color: #009900;">&quot;Freezer&quot;</span> <span style="color: #0000FF;">&#41;</span>.init<span style="color: #0000FF;">&#40;</span> <span style="color: #0000FF;">Name</span> <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;Calvin Hobbes&quot;</span>, Gender <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;Male&quot;</span> <span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> Frostman.energyProject<span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span></pre></div></div>

<p>You can <a href="/wp-content/uploads/2010/04/strategy-pattern-cf.zip"><strong>download all the CF code</strong></a> here with the original Visio diagram source.</p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://www.shinylight.com/2010/05/02/implementing-strategy-pattern-coldfusion/&amp;submitHeadline=Implementing+the+Strategy+Pattern+in+ColdFusion&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.shinylight.com/2010/05/02/implementing-strategy-pattern-coldfusion/&amp;title=Implementing+the+Strategy+Pattern+in+ColdFusion" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.shinylight.com/2010/05/02/implementing-strategy-pattern-coldfusion/&amp;title=Implementing+the+Strategy+Pattern+in+ColdFusion" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://www.shinylight.com/2010/05/02/implementing-strategy-pattern-coldfusion/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.shinylight.com/2010/05/02/implementing-strategy-pattern-coldfusion/&amp;title=Implementing+the+Strategy+Pattern+in+ColdFusion" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://www.shinylight.com/2010/05/02/implementing-strategy-pattern-coldfusion/&amp;bm_description=Implementing+the+Strategy+Pattern+in+ColdFusion" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://www.shinylight.com/2010/05/02/implementing-strategy-pattern-coldfusion/&amp;T=Implementing+the+Strategy+Pattern+in+ColdFusion" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.shinylight.com/2010/05/02/implementing-strategy-pattern-coldfusion/&amp;title=Implementing+the+Strategy+Pattern+in+ColdFusion" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.shinylight.com/2010/05/02/implementing-strategy-pattern-coldfusion/&amp;title=Implementing+the+Strategy+Pattern+in+ColdFusion" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.shinylight.com/2010/05/02/implementing-strategy-pattern-coldfusion/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://www.shinylight.com/2010/05/02/implementing-strategy-pattern-coldfusion/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Implementing+the+Strategy+Pattern+in+ColdFusion+@+http://www.shinylight.com/2010/05/02/implementing-strategy-pattern-coldfusion/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.shinylight.com/2010/05/02/implementing-strategy-pattern-coldfusion/&amp;t=Implementing+the+Strategy+Pattern+in+ColdFusion" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shinylight.com/2010/05/02/implementing-strategy-pattern-coldfusion/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TSQL Functions Inspired By ColdFusion&#8217;s Lists Functions</title>
		<link>http://www.shinylight.com/2010/04/27/tsql-functions-inspired-by-coldfusions-lists-functions/</link>
		<comments>http://www.shinylight.com/2010/04/27/tsql-functions-inspired-by-coldfusions-lists-functions/#comments</comments>
		<pubDate>Tue, 27 Apr 2010 00:08:43 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.shinylight.com/?p=944</guid>
		<description><![CDATA[In my last project, there was a bit of data scrubbing on the database side (SQL Server 2008) that I decided to create a few UDF&#8217;s that function similar to ColdFusion&#8217;s Lists function. The one that varies a little bit is ListLen(), since I needed to take into account empty tokens. The ChopIf() was inspired [...]]]></description>
			<content:encoded><![CDATA[<p>In my last project, there was a bit of data scrubbing on the database side (SQL Server 2008) that I decided to create a few UDF&#8217;s that function similar to ColdFusion&#8217;s Lists function. The one that varies a little bit is ListLen(), since I needed to take into account empty tokens. The ChopIf() was inspired by Perl&#8217;s chop() function. These UDFs should be SQL Server 2005-compatible. </p>
<p>I should say though, that some of these functions depend on each other. ListLen(), GetToken(), and ChopIf() are independent.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
</pre></td><td class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">------------------------------------------------------------------</span>
<span style="color: #008080;">-- Functions similarly like ColdFusion ListSort() function,</span>
<span style="color: #008080;">-- except it currently only sorts strings. </span>
<span style="color: #008080;">--</span>
<span style="color: #008080;">-- Example 1:</span>
<span style="color: #008080;">--    dbo.ListSort( 'dan is so mega awesome that he rules all the time', 'ASC', ' ' )</span>
<span style="color: #008080;">--</span>
<span style="color: #008080;">-- Returns: </span>
<span style="color: #008080;">--    all awesome dan he is mega rules so that the time</span>
<span style="color: #008080;">--</span>
<span style="color: #008080;">-- Example 2:</span>
<span style="color: #008080;">--    dbo.ListSort( 'dan is so mega awesome that he rules all the time', 'DESC', ' ' )</span>
<span style="color: #008080;">--</span>
<span style="color: #008080;">-- Returns: </span>
<span style="color: #008080;">--    time the that so rules mega is he dan awesome all</span>
<span style="color: #008080;">------------------------------------------------------------------</span>
&nbsp;
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">FUNCTION</span> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>ListSort<span style="color: #808080;">&#93;</span>
<span style="color: #808080;">&#40;</span>
  @string    <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span>,  
  @sort_type <span style="color: #0000FF;">CHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">3</span><span style="color: #808080;">&#41;</span>       <span style="color: #808080;">=</span> <span style="color: #FF0000;">'ASC'</span>,
  @delimiter <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">','</span>
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">RETURNS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">500</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">AS</span>
&nbsp;
<span style="color: #0000FF;">BEGIN</span>
&nbsp;
  <span style="color: #0000FF;">DECLARE</span> @position <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">INT</span>
  <span style="color: #0000FF;">DECLARE</span> @token <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span>
  <span style="color: #0000FF;">DECLARE</span> @counter   <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">INT</span>
  <span style="color: #0000FF;">DECLARE</span> @sortedList <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">500</span><span style="color: #808080;">&#41;</span>
&nbsp;
  <span style="color: #0000FF;">DECLARE</span> @sortTempTable <span style="color: #0000FF;">TABLE</span> <span style="color: #808080;">&#40;</span> token <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">500</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">&#41;</span>
  <span style="color: #0000FF;">DECLARE</span> @sortedTable   <span style="color: #0000FF;">TABLE</span> <span style="color: #808080;">&#40;</span> token <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">500</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">&#41;</span>  
&nbsp;
  <span style="color: #0000FF;">SELECT</span> @string   <span style="color: #808080;">=</span> @string <span style="color: #808080;">+</span> @delimiter,
         @counter  <span style="color: #808080;">=</span> <span style="color: #000;">1</span>,
         @position <span style="color: #808080;">=</span> <span style="color: #000;">0</span>,
         @token    <span style="color: #808080;">=</span> <span style="color: #FF0000;">''</span>
&nbsp;
  <span style="color: #0000FF;">WHILE</span> <span style="color: #808080;">&#40;</span> <span style="color: #FF00FF;">PATINDEX</span><span style="color: #808080;">&#40;</span> <span style="color: #FF0000;">'%'</span> <span style="color: #808080;">+</span> @delimiter <span style="color: #808080;">+</span> <span style="color: #FF0000;">'%'</span> , @string <span style="color: #808080;">&#41;</span> <span style="color: #808080;">&lt;&gt;</span> <span style="color: #000;">0</span> <span style="color: #808080;">&#41;</span> 
  <span style="color: #0000FF;">BEGIN</span>
    <span style="color: #0000FF;">SELECT</span> @position <span style="color: #808080;">=</span> <span style="color: #FF00FF;">PATINDEX</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'%'</span> <span style="color: #808080;">+</span> @delimiter <span style="color: #808080;">+</span> <span style="color: #FF0000;">'%'</span> , @string <span style="color: #808080;">&#41;</span>,
           @token    <span style="color: #808080;">=</span> <span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span> @string, @position <span style="color: #808080;">-</span> <span style="color: #000;">1</span> <span style="color: #808080;">&#41;</span>,
           @string   <span style="color: #808080;">=</span> <span style="color: #FF00FF;">STUFF</span><span style="color: #808080;">&#40;</span> @string, <span style="color: #000;">1</span>, @position, <span style="color: #808080;">NULL</span> <span style="color: #808080;">&#41;</span>,
           @counter  <span style="color: #808080;">=</span> @counter <span style="color: #808080;">+</span> <span style="color: #000;">1</span>
&nbsp;
    <span style="color: #0000FF;">INSERT</span> @sortTempTable<span style="color: #808080;">&#40;</span> token <span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">VALUES</span><span style="color: #808080;">&#40;</span> @token <span style="color: #808080;">&#41;</span>     
  <span style="color: #0000FF;">END</span>
&nbsp;
  <span style="color: #0000FF;">SET</span> @sortedList <span style="color: #808080;">=</span> <span style="color: #FF0000;">''</span>
&nbsp;
  <span style="color: #008080;">-- Let's sort the table and put it into @sortedTable</span>
  <span style="color: #008080;">-- Because of nature of Rank(), we can't set @sortedList in this statement.</span>
  <span style="color: #008080;">-- Have to separate it into another select clause.</span>
  <span style="color: #0000FF;">INSERT</span> <span style="color: #0000FF;">INTO</span> @sortedTable
    <span style="color: #0000FF;">SELECT</span> <span style="color: #FF00FF;">LTRIM</span><span style="color: #808080;">&#40;</span> token <span style="color: #808080;">&#41;</span>
    <span style="color: #0000FF;">FROM</span>   @sortTempTable
    <span style="color: #0000FF;">ORDER</span>  <span style="color: #0000FF;">BY</span> <span style="color: #0000FF;">CASE</span> <span style="color: #0000FF;">WHEN</span> @sort_type <span style="color: #808080;">=</span> <span style="color: #FF0000;">'ASC'</span>  <span style="color: #0000FF;">THEN</span> <span style="color: #808080;">&#40;</span> RANK<span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">OVER</span> <span style="color: #808080;">&#40;</span> <span style="color: #0000FF;">ORDER</span> <span style="color: #0000FF;">BY</span> <span style="color: #FF00FF;">LTRIM</span><span style="color: #808080;">&#40;</span>token<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">ASC</span> <span style="color: #808080;">&#41;</span> <span style="color: #808080;">&#41;</span>
                   <span style="color: #0000FF;">WHEN</span> @sort_type <span style="color: #808080;">=</span> <span style="color: #FF0000;">'DESC'</span> <span style="color: #0000FF;">THEN</span> <span style="color: #808080;">&#40;</span> RANK<span style="color: #808080;">&#40;</span><span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">OVER</span> <span style="color: #808080;">&#40;</span> <span style="color: #0000FF;">ORDER</span> <span style="color: #0000FF;">BY</span> <span style="color: #FF00FF;">LTRIM</span><span style="color: #808080;">&#40;</span>token<span style="color: #808080;">&#41;</span> <span style="color: #0000FF;">DESC</span> <span style="color: #808080;">&#41;</span> <span style="color: #808080;">&#41;</span>
              <span style="color: #0000FF;">END</span>  
&nbsp;
  <span style="color: #0000FF;">SELECT</span> @sortedList <span style="color: #808080;">=</span> @sortedList <span style="color: #808080;">+</span> token <span style="color: #808080;">+</span> @delimiter
  <span style="color: #0000FF;">FROM</span>   @sortedTable
&nbsp;
  <span style="color: #0000FF;">RETURN</span> dbo.<span style="color: #202020;">ChopIf</span><span style="color: #808080;">&#40;</span> @sortedList, @delimiter <span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">END</span>
GO</pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
</pre></td><td class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">------------------------------------------------------------------</span>
<span style="color: #008080;">-- Functions sort of like ColdFusion's ListLen() method, but it</span>
<span style="color: #008080;">-- takes into account empty tokens. </span>
<span style="color: #008080;">--</span>
<span style="color: #008080;">-- Example 1:</span>
<span style="color: #008080;">--    dbo.ListLen( 'Dan is cool', ' ' )</span>
<span style="color: #008080;">--</span>
<span style="color: #008080;">-- Returns: </span>
<span style="color: #008080;">--    3</span>
<span style="color: #008080;">-- </span>
<span style="color: #008080;">-- Example 2:</span>
<span style="color: #008080;">--    dbo.ListLen( 'dan,,very,,,,awesome,', ',' )</span>
<span style="color: #008080;">--</span>
<span style="color: #008080;">-- Returns: </span>
<span style="color: #008080;">--    8</span>
<span style="color: #008080;">------------------------------------------------------------------</span>
&nbsp;
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">FUNCTION</span> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>ListLen<span style="color: #808080;">&#93;</span>
<span style="color: #808080;">&#40;</span>
  @string <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span>,
  @delimiter <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">','</span>
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">RETURNS</span> <span style="color: #0000FF;">INT</span>
<span style="color: #0000FF;">AS</span>
<span style="color: #0000FF;">BEGIN</span>
&nbsp;
  <span style="color: #0000FF;">DECLARE</span> @loopCount <span style="color: #0000FF;">INT</span>, 
          @tokenCount <span style="color: #0000FF;">INT</span>
&nbsp;
  <span style="color: #0000FF;">SELECT</span> @loopCount <span style="color: #808080;">=</span> <span style="color: #000;">0</span>, 
         @tokenCount <span style="color: #808080;">=</span> <span style="color: #000;">0</span>
&nbsp;
  <span style="color: #008080;">-- If it's an empty string, the list length is 0</span>
  <span style="color: #0000FF;">IF</span> DATALENGTH<span style="color: #808080;">&#40;</span> @string <span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #000;">0</span>
    <span style="color: #0000FF;">BEGIN</span>
      <span style="color: #0000FF;">SET</span> @tokenCount <span style="color: #808080;">=</span> <span style="color: #000;">0</span>
    <span style="color: #0000FF;">END</span>
  <span style="color: #0000FF;">ELSE</span>
    <span style="color: #0000FF;">BEGIN</span>
      <span style="color: #008080;">-- Count tokens, including empty ones like dan,,very,,,,awesome,</span>
      <span style="color: #0000FF;">SET</span> @tokenCount <span style="color: #808080;">=</span> @tokenCount <span style="color: #808080;">+</span> <span style="color: #000;">1</span>
      <span style="color: #0000FF;">WHILE</span> <span style="color: #808080;">&#40;</span> @loopCount <span style="color: #808080;">&lt;</span> DATALENGTH<span style="color: #808080;">&#40;</span> @string <span style="color: #808080;">&#41;</span> <span style="color: #808080;">&#41;</span>
      <span style="color: #0000FF;">BEGIN</span>
        <span style="color: #0000FF;">IF</span> <span style="color: #FF00FF;">SUBSTRING</span><span style="color: #808080;">&#40;</span> @string, @loopCount, DATALENGTH<span style="color: #808080;">&#40;</span> @delimiter <span style="color: #808080;">&#41;</span> <span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> @delimiter
          <span style="color: #0000FF;">BEGIN</span>
            <span style="color: #0000FF;">SET</span> @tokenCount <span style="color: #808080;">=</span> @tokenCount <span style="color: #808080;">+</span> <span style="color: #000;">1</span>
          <span style="color: #0000FF;">END</span>
        <span style="color: #0000FF;">SET</span> @loopCount <span style="color: #808080;">=</span> @loopCount <span style="color: #808080;">+</span> <span style="color: #000;">1</span>
      <span style="color: #0000FF;">END</span>
    <span style="color: #0000FF;">END</span>
&nbsp;
  <span style="color: #008080;">-- Handle extra count from space being delimiter</span>
  <span style="color: #0000FF;">IF</span> @delimiter <span style="color: #808080;">=</span> <span style="color: #FF0000;">' '</span>
    <span style="color: #0000FF;">SET</span> @tokenCount <span style="color: #808080;">=</span> @tokenCount <span style="color: #808080;">-</span> <span style="color: #000;">1</span>
&nbsp;
  <span style="color: #008080;">-- If there's no token to the right of the last delimiter, then count that</span>
  <span style="color: #008080;">-- as an empty token.</span>
  <span style="color: #0000FF;">IF</span> <span style="color: #808080;">&#40;</span> <span style="color: #0000FF;">RIGHT</span><span style="color: #808080;">&#40;</span> @string, <span style="color: #000;">1</span> <span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> @delimiter <span style="color: #808080;">&#41;</span> 
  <span style="color: #0000FF;">BEGIN</span>
    <span style="color: #0000FF;">SET</span> @tokenCount <span style="color: #808080;">=</span> @tokenCount <span style="color: #808080;">+</span> <span style="color: #000;">1</span>
  <span style="color: #0000FF;">END</span>
&nbsp;
  <span style="color: #0000FF;">RETURN</span> @tokenCount
&nbsp;
<span style="color: #0000FF;">END</span>
GO</pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
</pre></td><td class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">------------------------------------------------------------------</span>
<span style="color: #008080;">-- Functions like ColdFusion's ListLast()</span>
<span style="color: #008080;">-- Gets token value that's been separated by a delimiter.</span>
<span style="color: #008080;">--</span>
<span style="color: #008080;">-- Example:</span>
<span style="color: #008080;">--    dbo.ListLast( 'Dan is cool', ' ' )</span>
<span style="color: #008080;">--</span>
<span style="color: #008080;">-- Returns: </span>
<span style="color: #008080;">--    cool</span>
<span style="color: #008080;">------------------------------------------------------------------</span>
&nbsp;
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">FUNCTION</span> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>ListLast<span style="color: #808080;">&#93;</span>
<span style="color: #808080;">&#40;</span>
  @string <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span>,
  @delimiter <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">','</span>
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">RETURNS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">AS</span>
<span style="color: #0000FF;">BEGIN</span>
&nbsp;
  <span style="color: #0000FF;">RETURN</span> dbo.<span style="color: #202020;">ListGetAt</span><span style="color: #808080;">&#40;</span> @string, dbo.<span style="color: #202020;">ListLen</span><span style="color: #808080;">&#40;</span> @string, @delimiter <span style="color: #808080;">&#41;</span> , @delimiter  <span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">END</span>
GO</pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">------------------------------------------------------------------</span>
<span style="color: #008080;">-- Wrapper for GetToken() Function</span>
<span style="color: #008080;">-- Gets token value that's been separated by a delimiter.</span>
<span style="color: #008080;">--</span>
<span style="color: #008080;">-- Example:</span>
<span style="color: #008080;">--    dbo.ListGetAt( 'Dan is cool', 2, ' ' )</span>
<span style="color: #008080;">--</span>
<span style="color: #008080;">-- Returns: </span>
<span style="color: #008080;">--    is</span>
<span style="color: #008080;">------------------------------------------------------------------</span>
&nbsp;
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">FUNCTION</span> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>ListGetAt<span style="color: #808080;">&#93;</span>
<span style="color: #808080;">&#40;</span>
  @string <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span>,
  @token <span style="color: #0000FF;">INT</span>,
  @delimiter <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">RETURNS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">AS</span>
<span style="color: #0000FF;">BEGIN</span>
  <span style="color: #0000FF;">RETURN</span> dbo.<span style="color: #202020;">GetToken</span><span style="color: #808080;">&#40;</span> @string, @token, @delimiter <span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">END</span>
GO</pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
</pre></td><td class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">------------------------------------------------------------------</span>
<span style="color: #008080;">-- Returns the first item in a tokenized list.</span>
<span style="color: #008080;">--</span>
<span style="color: #008080;">-- Example:</span>
<span style="color: #008080;">--    dbo.ListFirst( 'Dan is cool', ' ' )</span>
<span style="color: #008080;">--</span>
<span style="color: #008080;">-- Returns: </span>
<span style="color: #008080;">--    Dan</span>
<span style="color: #008080;">------------------------------------------------------------------</span>
&nbsp;
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">FUNCTION</span> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>ListFirst<span style="color: #808080;">&#93;</span>
<span style="color: #808080;">&#40;</span>
  @string <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span>,
  @delimiter <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> <span style="color: #FF0000;">','</span>
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">RETURNS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">AS</span>
<span style="color: #0000FF;">BEGIN</span>
&nbsp;
  <span style="color: #0000FF;">RETURN</span> dbo.<span style="color: #202020;">ListGetAt</span><span style="color: #808080;">&#40;</span> @string, <span style="color: #000;">1</span>, @delimiter <span style="color: #808080;">&#41;</span>
&nbsp;
<span style="color: #0000FF;">END</span>
GO</pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
</pre></td><td class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">------------------------------------------------------------------</span>
<span style="color: #008080;">-- Functions similarly like ColdFusion GetToken() Function.</span>
<span style="color: #008080;">-- Gets token value that's been separated by a delimiter.</span>
<span style="color: #008080;">--</span>
<span style="color: #008080;">-- Example:</span>
<span style="color: #008080;">--    dbo.GetToken( 'Dan is cool', 2, ' ' )</span>
<span style="color: #008080;">--</span>
<span style="color: #008080;">-- Returns: </span>
<span style="color: #008080;">--    is</span>
<span style="color: #008080;">------------------------------------------------------------------</span>
&nbsp;
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">FUNCTION</span> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>GetToken<span style="color: #808080;">&#93;</span>
<span style="color: #808080;">&#40;</span>
  @string <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span>,
  @tokenPosition <span style="color: #0000FF;">INT</span>,
  @delimiter <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">RETURNS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">AS</span>
<span style="color: #0000FF;">BEGIN</span>
&nbsp;
  <span style="color: #0000FF;">DECLARE</span> @position <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">INT</span>
  <span style="color: #0000FF;">DECLARE</span> @token <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">VARCHAR</span> <span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span>
  <span style="color: #0000FF;">DECLARE</span> @counter <span style="color: #0000FF;">AS</span> <span style="color: #0000FF;">INT</span>
&nbsp;
  <span style="color: #0000FF;">SELECT</span> @string <span style="color: #808080;">=</span> @string <span style="color: #808080;">+</span> @delimiter,
         @counter <span style="color: #808080;">=</span> <span style="color: #000;">1</span>,
         @position <span style="color: #808080;">=</span> <span style="color: #000;">0</span>,
         @token <span style="color: #808080;">=</span> <span style="color: #FF0000;">''</span>
&nbsp;
  <span style="color: #0000FF;">WHILE</span> <span style="color: #808080;">&#40;</span> <span style="color: #FF00FF;">PATINDEX</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'%'</span> <span style="color: #808080;">+</span> @delimiter <span style="color: #808080;">+</span> <span style="color: #FF0000;">'%'</span> , @string <span style="color: #808080;">&#41;</span> <span style="color: #808080;">&lt;&gt;</span> <span style="color: #000;">0</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">AND</span> <span style="color: #808080;">&#40;</span> @tokenPosition <span style="color: #808080;">+</span> <span style="color: #000;">1</span> <span style="color: #808080;">&lt;&gt;</span> @counter <span style="color: #808080;">&#41;</span>
  <span style="color: #0000FF;">BEGIN</span>
    <span style="color: #0000FF;">SELECT</span> @position <span style="color: #808080;">=</span> <span style="color: #FF00FF;">PATINDEX</span><span style="color: #808080;">&#40;</span><span style="color: #FF0000;">'%'</span> <span style="color: #808080;">+</span> @delimiter <span style="color: #808080;">+</span> <span style="color: #FF0000;">'%'</span> , @string<span style="color: #808080;">&#41;</span>,
           @token    <span style="color: #808080;">=</span> <span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span>@string, @position<span style="color: #808080;">-</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span>,
           @string   <span style="color: #808080;">=</span> <span style="color: #FF00FF;">STUFF</span><span style="color: #808080;">&#40;</span>@string, <span style="color: #000;">1</span>, @position, null<span style="color: #808080;">&#41;</span>,
           @counter  <span style="color: #808080;">=</span> @counter <span style="color: #808080;">+</span> <span style="color: #000;">1</span>
  <span style="color: #0000FF;">END</span>
&nbsp;
  <span style="color: #0000FF;">RETURN</span> @token
<span style="color: #0000FF;">END</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">------------------------------------------------------------------</span>
<span style="color: #008080;">-- Chops the last character if it's @chopped</span>
<span style="color: #008080;">--</span>
<span style="color: #008080;">-- Example:</span>
<span style="color: #008080;">--    dbo.ChopIf( 'Dan is cool!', '!' )</span>
<span style="color: #008080;">--</span>
<span style="color: #008080;">-- Returns: </span>
<span style="color: #008080;">--    Dan is cool</span>
<span style="color: #008080;">------------------------------------------------------------------</span>
&nbsp;
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">FUNCTION</span> <span style="color: #808080;">&#91;</span>dbo<span style="color: #808080;">&#93;</span>.<span style="color: #808080;">&#91;</span>ChopIf<span style="color: #808080;">&#93;</span>
<span style="color: #808080;">&#40;</span>
  @string <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span>,
  @chopped <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span>
<span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">RETURNS</span> <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">2000</span><span style="color: #808080;">&#41;</span>
<span style="color: #0000FF;">AS</span>
<span style="color: #0000FF;">BEGIN</span>
&nbsp;
  <span style="color: #0000FF;">IF</span> <span style="color: #808080;">&#40;</span> <span style="color: #0000FF;">RIGHT</span><span style="color: #808080;">&#40;</span> @string, DATALENGTH<span style="color: #808080;">&#40;</span>@chopped<span style="color: #808080;">&#41;</span> <span style="color: #808080;">&#41;</span> <span style="color: #808080;">=</span> @chopped <span style="color: #808080;">&#41;</span>
  <span style="color: #0000FF;">BEGIN</span>
    <span style="color: #0000FF;">SET</span> @string <span style="color: #808080;">=</span> <span style="color: #0000FF;">LEFT</span><span style="color: #808080;">&#40;</span> @string, DATALENGTH<span style="color: #808080;">&#40;</span> @string <span style="color: #808080;">&#41;</span> <span style="color: #808080;">-</span> DATALENGTH<span style="color: #808080;">&#40;</span> @chopped <span style="color: #808080;">&#41;</span> <span style="color: #808080;">&#41;</span> 
  <span style="color: #0000FF;">END</span> 
&nbsp;
  <span style="color: #0000FF;">RETURN</span> @string
&nbsp;
<span style="color: #0000FF;">END</span>
GO</pre></td></tr></table></div>

<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://www.shinylight.com/2010/04/27/tsql-functions-inspired-by-coldfusions-lists-functions/&amp;submitHeadline=TSQL+Functions+Inspired+By+ColdFusion%26%238217%3Bs+Lists+Functions&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.shinylight.com/2010/04/27/tsql-functions-inspired-by-coldfusions-lists-functions/&amp;title=TSQL+Functions+Inspired+By+ColdFusion%26%238217%3Bs+Lists+Functions" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.shinylight.com/2010/04/27/tsql-functions-inspired-by-coldfusions-lists-functions/&amp;title=TSQL+Functions+Inspired+By+ColdFusion%26%238217%3Bs+Lists+Functions" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://www.shinylight.com/2010/04/27/tsql-functions-inspired-by-coldfusions-lists-functions/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.shinylight.com/2010/04/27/tsql-functions-inspired-by-coldfusions-lists-functions/&amp;title=TSQL+Functions+Inspired+By+ColdFusion%26%238217%3Bs+Lists+Functions" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://www.shinylight.com/2010/04/27/tsql-functions-inspired-by-coldfusions-lists-functions/&amp;bm_description=TSQL+Functions+Inspired+By+ColdFusion%26%238217%3Bs+Lists+Functions" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://www.shinylight.com/2010/04/27/tsql-functions-inspired-by-coldfusions-lists-functions/&amp;T=TSQL+Functions+Inspired+By+ColdFusion%26%238217%3Bs+Lists+Functions" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.shinylight.com/2010/04/27/tsql-functions-inspired-by-coldfusions-lists-functions/&amp;title=TSQL+Functions+Inspired+By+ColdFusion%26%238217%3Bs+Lists+Functions" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.shinylight.com/2010/04/27/tsql-functions-inspired-by-coldfusions-lists-functions/&amp;title=TSQL+Functions+Inspired+By+ColdFusion%26%238217%3Bs+Lists+Functions" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.shinylight.com/2010/04/27/tsql-functions-inspired-by-coldfusions-lists-functions/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://www.shinylight.com/2010/04/27/tsql-functions-inspired-by-coldfusions-lists-functions/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+TSQL+Functions+Inspired+By+ColdFusion%26%238217%3Bs+Lists+Functions+@+http://www.shinylight.com/2010/04/27/tsql-functions-inspired-by-coldfusions-lists-functions/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.shinylight.com/2010/04/27/tsql-functions-inspired-by-coldfusions-lists-functions/&amp;t=TSQL+Functions+Inspired+By+ColdFusion%26%238217%3Bs+Lists+Functions" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shinylight.com/2010/04/27/tsql-functions-inspired-by-coldfusions-lists-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generate Junk Files</title>
		<link>http://www.shinylight.com/2010/04/24/generate-junk-files/</link>
		<comments>http://www.shinylight.com/2010/04/24/generate-junk-files/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 05:00:27 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.shinylight.com/?p=942</guid>
		<description><![CDATA[The other day I was testing benchmarks for a delete script. I needed to create files with various file sizes. More specific, 1,000,000 files with 5K per file. A while ago I found this great snippet on StackOverflow to generate a junk random string:

junk =  &#40;&#40;&#34;%%0%dX&#34; % &#40;junk_len * 2&#41;&#41; % random.getrandbits&#40;junk_len * 8&#41;&#41;.decode&#40;&#34;hex&#34;&#41;

I&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I was testing benchmarks for a delete script. I needed to create files with various file sizes. More specific, 1,000,000 files with 5K per file. A while ago I found this great snippet on <a href="http://stackoverflow.com/questions/785058/random-strings-in-python-2-6-is-this-ok">StackOverflow to generate a junk random string</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;">junk =  <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%%0%dX&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>junk_len <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">%</span> <span style="color: #dc143c;">random</span>.<span style="color: black;">getrandbits</span><span style="color: black;">&#40;</span>junk_len <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">decode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;hex&quot;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>I&#8217;ve wrapped that around to make a utility function and snippet:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>, <span style="color: #dc143c;">random</span>, <span style="color: #dc143c;">sys</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># This tool takes 3 parameters</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;">#   testing &lt;directory to put files in&gt; &lt;how many files&gt; &lt;size of each file in bytes&gt;</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;"># Example:</span>
<span style="color: #808080; font-style: italic;">#</span>
<span style="color: #808080; font-style: italic;">#   testing dan 100 500</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> createLocalDirectory<span style="color: black;">&#40;</span> directoryName <span style="color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>.<span style="color: black;">exists</span><span style="color: black;">&#40;</span> directoryName <span style="color: black;">&#41;</span>:
    <span style="color: #dc143c;">os</span>.<span style="color: black;">makedirs</span><span style="color: black;">&#40;</span> directoryName <span style="color: black;">&#41;</span>
&nbsp;
folderName      = <span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
how_many_files  = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">2</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
junk_len        = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span><span style="color: #dc143c;">sys</span>.<span style="color: black;">argv</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">3</span><span style="color: black;">&#93;</span><span style="color: black;">&#41;</span>
&nbsp;
&nbsp;
createLocalDirectory<span style="color: black;">&#40;</span> folderName <span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> <span style="color: #008000;">range</span><span style="color: black;">&#40;</span> <span style="color: #ff4500;">0</span>, how_many_files <span style="color: black;">&#41;</span>:  
  junk =  <span style="color: black;">&#40;</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%%0%dX&quot;</span> <span style="color: #66cc66;">%</span> <span style="color: black;">&#40;</span>junk_len <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">2</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span> <span style="color: #66cc66;">%</span> <span style="color: #dc143c;">random</span>.<span style="color: black;">getrandbits</span><span style="color: black;">&#40;</span>junk_len <span style="color: #66cc66;">*</span> <span style="color: #ff4500;">8</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>.<span style="color: black;">decode</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;hex&quot;</span><span style="color: black;">&#41;</span>
  path = folderName + <span style="color: #483d8b;">&quot;/&quot;</span> + <span style="color: #008000;">str</span><span style="color: black;">&#40;</span>i<span style="color: black;">&#41;</span> + <span style="color: #483d8b;">&quot;.txt&quot;</span>
  f = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span> path, <span style="color: #483d8b;">'w'</span> <span style="color: black;">&#41;</span>
  f.<span style="color: black;">write</span><span style="color: black;">&#40;</span> junk <span style="color: black;">&#41;</span>
  <span style="color: #ff7700;font-weight:bold;">print</span> f
  f.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://www.shinylight.com/2010/04/24/generate-junk-files/&amp;submitHeadline=Generate+Junk+Files&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.shinylight.com/2010/04/24/generate-junk-files/&amp;title=Generate+Junk+Files" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.shinylight.com/2010/04/24/generate-junk-files/&amp;title=Generate+Junk+Files" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://www.shinylight.com/2010/04/24/generate-junk-files/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.shinylight.com/2010/04/24/generate-junk-files/&amp;title=Generate+Junk+Files" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://www.shinylight.com/2010/04/24/generate-junk-files/&amp;bm_description=Generate+Junk+Files" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://www.shinylight.com/2010/04/24/generate-junk-files/&amp;T=Generate+Junk+Files" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.shinylight.com/2010/04/24/generate-junk-files/&amp;title=Generate+Junk+Files" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.shinylight.com/2010/04/24/generate-junk-files/&amp;title=Generate+Junk+Files" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.shinylight.com/2010/04/24/generate-junk-files/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://www.shinylight.com/2010/04/24/generate-junk-files/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Generate+Junk+Files+@+http://www.shinylight.com/2010/04/24/generate-junk-files/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.shinylight.com/2010/04/24/generate-junk-files/&amp;t=Generate+Junk+Files" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shinylight.com/2010/04/24/generate-junk-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Search In One File from Keywords in Another File</title>
		<link>http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/</link>
		<comments>http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/#comments</comments>
		<pubDate>Sat, 24 Apr 2010 04:49:00 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Languages]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.shinylight.com/?p=939</guid>
		<description><![CDATA[I needed to see if this list of email addresses were found in a logs file. So I had one file with a list of email addresses. Another file is a list emails sent. I needed to make sure that the emails were sent. Here&#8217;s a quick Python script I put together that does this:

import [...]]]></description>
			<content:encoded><![CDATA[<p>I needed to see if this list of email addresses were found in a logs file. So I had one file with a list of email addresses. Another file is a list emails sent. I needed to make sure that the emails were sent. Here&#8217;s a quick Python script I put together that does this:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> searchInLogFile<span style="color: black;">&#40;</span> FILE, query <span style="color: black;">&#41;</span>:  
  FILE.<span style="color: black;">seek</span><span style="color: black;">&#40;</span> <span style="color: #ff4500;">0</span>, <span style="color: #ff4500;">0</span> <span style="color: black;">&#41;</span>  
  <span style="color: #ff7700;font-weight:bold;">for</span> line <span style="color: #ff7700;font-weight:bold;">in</span> LogFile:
    logLine = line.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>,<span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>,<span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">rstrip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">lstrip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span> query, logLine, <span style="color: #dc143c;">re</span>.<span style="color: black;">IGNORECASE</span> | <span style="color: #dc143c;">re</span>.<span style="color: black;">MULTILINE</span> <span style="color: black;">&#41;</span>:
      <span style="color: #ff7700;font-weight:bold;">return</span> <span style="color: #008000;">True</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># This file has a list (\r\n delimited) email addresses.</span>
EmailListFile = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;email-list-internal.txt&quot;</span>, <span style="color: #483d8b;">&quot;r&quot;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># This is the log file which we'll use to see if email addresses are in here.</span>
LogFile = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;POST20100201.log&quot;</span>, <span style="color: #483d8b;">&quot;r&quot;</span> <span style="color: black;">&#41;</span>
&nbsp;
EmailFound = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
EmailNotFound = <span style="color: black;">&#91;</span><span style="color: black;">&#93;</span>
breakTime = <span style="color: #ff4500;">0</span>
<span style="color: #808080; font-style: italic;"># 0 = does the whole list</span>
EmailsToSearchFor = <span style="color: #ff4500;">0</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> emailLine <span style="color: #ff7700;font-weight:bold;">in</span> EmailListFile:
  <span style="color: #dc143c;">email</span> = emailLine.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>,<span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">replace</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\r</span>&quot;</span>,<span style="color: #483d8b;">&quot;&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">rstrip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">lstrip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span> searchInLogFile<span style="color: black;">&#40;</span> LogFile, <span style="color: #dc143c;">email</span> <span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">email</span>, <span style="color: #483d8b;">&quot;was found&quot;</span>
    EmailFound.<span style="color: black;">append</span><span style="color: black;">&#40;</span> <span style="color: #dc143c;">email</span> <span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">else</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #dc143c;">email</span>, <span style="color: #483d8b;">&quot;not found&quot;</span>
    EmailNotFound.<span style="color: black;">append</span><span style="color: black;">&#40;</span> <span style="color: #dc143c;">email</span> <span style="color: black;">&#41;</span>  
&nbsp;
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span> EmailsToSearchFor <span style="color: #66cc66;">!</span>= <span style="color: #ff4500;">0</span> <span style="color: black;">&#41;</span>:
    breakTime += <span style="color: #ff4500;">1</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span> breakTime == EmailsToSearchFor <span style="color: black;">&#41;</span>:
      <span style="color: #ff7700;font-weight:bold;">break</span><span style="color: #66cc66;">;</span>
&nbsp;
LogFile.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
EmailListFile.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Log results to a file.</span>
OutputFile = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;output.log&quot;</span>, <span style="color: #483d8b;">&quot;w&quot;</span> <span style="color: black;">&#41;</span>
&nbsp;
divider = <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>======== Found ========================================&quot;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> divider
OutputFile.<span style="color: black;">write</span><span style="color: black;">&#40;</span> divider <span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> EmailFound:
  <span style="color: #ff7700;font-weight:bold;">print</span> i
  OutputFile.<span style="color: black;">write</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> + i <span style="color: black;">&#41;</span>
&nbsp;
divider = <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>======== Not Found ====================================&quot;</span>  
<span style="color: #ff7700;font-weight:bold;">print</span> divider
OutputFile.<span style="color: black;">write</span><span style="color: black;">&#40;</span> divider <span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">for</span> i <span style="color: #ff7700;font-weight:bold;">in</span> EmailNotFound:
  <span style="color: #ff7700;font-weight:bold;">print</span> i
  OutputFile.<span style="color: black;">write</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span> + i <span style="color: black;">&#41;</span>
&nbsp;
OutputFile.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Pretty straightforward. The script also writes a file called &#8220;output.log&#8221; which has a list of emails that were found (marked under &#8220;found&#8221;) and not found (marked under &#8220;not found&#8221;). </p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/&amp;submitHeadline=Search+In+One+File+from+Keywords+in+Another+File&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/&amp;title=Search+In+One+File+from+Keywords+in+Another+File" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/&amp;title=Search+In+One+File+from+Keywords+in+Another+File" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/&amp;title=Search+In+One+File+from+Keywords+in+Another+File" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/&amp;bm_description=Search+In+One+File+from+Keywords+in+Another+File" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/&amp;T=Search+In+One+File+from+Keywords+in+Another+File" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/&amp;title=Search+In+One+File+from+Keywords+in+Another+File" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/&amp;title=Search+In+One+File+from+Keywords+in+Another+File" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Search+In+One+File+from+Keywords+in+Another+File+@+http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/&amp;t=Search+In+One+File+from+Keywords+in+Another+File" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shinylight.com/2010/04/24/search-in-one-file-from-keywords-in-another-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Simple Way to Show/Hide with a Checkbox using jQuery</title>
		<link>http://www.shinylight.com/2010/04/03/quick-simple-way-to-showhide-with-a-checkbox-using-jquery/</link>
		<comments>http://www.shinylight.com/2010/04/03/quick-simple-way-to-showhide-with-a-checkbox-using-jquery/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 23:52:49 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.shinylight.com/?p=918</guid>
		<description><![CDATA[Here&#8217;s a quick and simple way to do this. I often have to show and hide set of panels based on whether something is checked or not. jQuery code is pretty straightforward and it comes in handy.

$&#40; function&#40;&#41; &#123;    
&#160;
  function toggleCheckbox&#40; trigger, hidethese &#41;
  &#123;
    if [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick and simple way to do this. I often have to show and hide set of panels based on whether something is checked or not. jQuery code is pretty straightforward and it comes in handy.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">$<span style="color: #009900;">&#40;</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>    
&nbsp;
  <span style="color: #003366; font-weight: bold;">function</span> toggleCheckbox<span style="color: #009900;">&#40;</span> trigger<span style="color: #339933;">,</span> hidethese <span style="color: #009900;">&#41;</span>
  <span style="color: #009900;">&#123;</span>
    <span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span> $<span style="color: #009900;">&#40;</span> trigger <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">attr</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;checked&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      $<span style="color: #009900;">&#40;</span> hidethese <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">hide</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
    <span style="color: #000066; font-weight: bold;">else</span>
    <span style="color: #009900;">&#123;</span>
      $<span style="color: #009900;">&#40;</span> hidethese <span style="color: #009900;">&#41;</span>.<span style="color: #660066;">show</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// jQuery object that has your checkbox</span>
  <span style="color: #003366; font-weight: bold;">var</span> triggerCheckbox <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span> <span style="color: #3366CC;">&quot;#showPreonDescription&quot;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #006600; font-style: italic;">// jQuery object for collection of elements you want to hide</span>
  <span style="color: #006600; font-style: italic;">// For this example, I could've also just done #panel by itself</span>
  <span style="color: #006600; font-style: italic;">// to hide everything</span>
  <span style="color: #003366; font-weight: bold;">var</span> panelsToHide <span style="color: #339933;">=</span> $<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#subpanel,#maincontent,#nav&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>  
&nbsp;
  <span style="color: #006600; font-style: italic;">// Call the function on click.</span>
  triggerCheckbox.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span>
    <span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
      toggleCheckbox<span style="color: #009900;">&#40;</span> triggerCheckbox<span style="color: #339933;">,</span> panelsToHide <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>I have <a href="/wp-content/uploads/2010/03/test.html">the demo</a> if you want the source as well. </p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://www.shinylight.com/2010/04/03/quick-simple-way-to-showhide-with-a-checkbox-using-jquery/&amp;submitHeadline=Quick+Simple+Way+to+Show%2FHide+with+a+Checkbox+using+jQuery&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.shinylight.com/2010/04/03/quick-simple-way-to-showhide-with-a-checkbox-using-jquery/&amp;title=Quick+Simple+Way+to+Show%2FHide+with+a+Checkbox+using+jQuery" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.shinylight.com/2010/04/03/quick-simple-way-to-showhide-with-a-checkbox-using-jquery/&amp;title=Quick+Simple+Way+to+Show%2FHide+with+a+Checkbox+using+jQuery" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://www.shinylight.com/2010/04/03/quick-simple-way-to-showhide-with-a-checkbox-using-jquery/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.shinylight.com/2010/04/03/quick-simple-way-to-showhide-with-a-checkbox-using-jquery/&amp;title=Quick+Simple+Way+to+Show%2FHide+with+a+Checkbox+using+jQuery" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://www.shinylight.com/2010/04/03/quick-simple-way-to-showhide-with-a-checkbox-using-jquery/&amp;bm_description=Quick+Simple+Way+to+Show%2FHide+with+a+Checkbox+using+jQuery" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://www.shinylight.com/2010/04/03/quick-simple-way-to-showhide-with-a-checkbox-using-jquery/&amp;T=Quick+Simple+Way+to+Show%2FHide+with+a+Checkbox+using+jQuery" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.shinylight.com/2010/04/03/quick-simple-way-to-showhide-with-a-checkbox-using-jquery/&amp;title=Quick+Simple+Way+to+Show%2FHide+with+a+Checkbox+using+jQuery" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.shinylight.com/2010/04/03/quick-simple-way-to-showhide-with-a-checkbox-using-jquery/&amp;title=Quick+Simple+Way+to+Show%2FHide+with+a+Checkbox+using+jQuery" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.shinylight.com/2010/04/03/quick-simple-way-to-showhide-with-a-checkbox-using-jquery/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://www.shinylight.com/2010/04/03/quick-simple-way-to-showhide-with-a-checkbox-using-jquery/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Quick+Simple+Way+to+Show%2FHide+with+a+Checkbox+using+jQuery+@+http://www.shinylight.com/2010/04/03/quick-simple-way-to-showhide-with-a-checkbox-using-jquery/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.shinylight.com/2010/04/03/quick-simple-way-to-showhide-with-a-checkbox-using-jquery/&amp;t=Quick+Simple+Way+to+Show%2FHide+with+a+Checkbox+using+jQuery" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shinylight.com/2010/04/03/quick-simple-way-to-showhide-with-a-checkbox-using-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>IsNumericList() Function</title>
		<link>http://www.shinylight.com/2010/04/03/isnumericlist-function/</link>
		<comments>http://www.shinylight.com/2010/04/03/isnumericlist-function/#comments</comments>
		<pubDate>Fri, 02 Apr 2010 22:59:41 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[ColdFusion]]></category>

		<guid isPermaLink="false">http://www.shinylight.com/?p=912</guid>
		<description><![CDATA[Whipped up this UDF while working on a project. It checks to see if the list is valid to use in a TSQL WHERE IN Clause. I wanted to check for a list of valid positive integers (including 0), ignoring spaces.

&#60;cffunction name=&#34;isNumericList&#34; returntype=&#34;boolean&#34; hint=&#34;Check for either single positive number or a set of positive numbers. [...]]]></description>
			<content:encoded><![CDATA[<p>Whipped up this UDF while working on a project. It checks to see if the list is valid to use in a TSQL WHERE IN Clause. I wanted to check for a list of valid positive integers (including 0), ignoring spaces.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;isNumericList&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;boolean&quot;</span> <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Check for either single positive number or a set of positive numbers. Spaces ignored.&quot;</span> <span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!--- Useful when inserting into an &quot;IN&quot; TSQL list in the WHERE clause.  ---&gt;</span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;list&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;delimiter&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;false&quot;</span> <span style="color: #0000FF;">default</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;,&quot;</span><span style="color: #0000FF;">&gt;</span></span>   
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> isNumericList <span style="color: #0000FF;">=</span> false <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfif</span> <span style="color: #0000FF;">REFind</span><span style="color: #0000FF;">&#40;</span> <span style="color: #009900;">&quot;^(<span style="color: #000099; font-weight: bold;">\d</span>+)$|^(([<span style="color: #000099; font-weight: bold;">\d</span><span style="color: #000099; font-weight: bold;">\s</span>]+#Arguments.delimiter#)+<span style="color: #000099; font-weight: bold;">\s</span>*<span style="color: #000099; font-weight: bold;">\d</span>+)$&quot;</span>, <span style="color: #0000FF;">Trim</span><span style="color: #0000FF;">&#40;</span>Arguments.<span style="color: #0000FF;">list</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">&gt;</span></span>
&nbsp;
    <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> true <span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfif</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> isNumericList <span style="color: #0000FF;">&gt;</span></span>  
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Now let&#8217;s test it!</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!--- Dummy Data ---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> dataList <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">ArrayNew</span><span style="color: #0000FF;">&#40;</span><span style="color: #FF0000;">1</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> dataList<span style="color: #0000FF;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;456c&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> dataList<span style="color: #0000FF;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;456&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> dataList<span style="color: #0000FF;">&#91;</span><span style="color: #FF0000;">3</span><span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;45c,&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> dataList<span style="color: #0000FF;">&#91;</span><span style="color: #FF0000;">4</span><span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;5,,,&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> dataList<span style="color: #0000FF;">&#91;</span><span style="color: #FF0000;">5</span><span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;565,651,34,643232,45&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> dataList<span style="color: #0000FF;">&#91;</span><span style="color: #FF0000;">6</span><span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;454,c,45,5454,32&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> dataList<span style="color: #0000FF;">&#91;</span><span style="color: #FF0000;">7</span><span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;121.45,43,565,1,1,2&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> dataList<span style="color: #0000FF;">&#91;</span><span style="color: #FF0000;">8</span><span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;43,54,65,1,&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> dataList<span style="color: #0000FF;">&#91;</span><span style="color: #FF0000;">9</span><span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;67,54,73,436,&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> dataList<span style="color: #0000FF;">&#91;</span><span style="color: #FF0000;">10</span><span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;,6565,656,77,32,3&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> dataList<span style="color: #0000FF;">&#91;</span><span style="color: #FF0000;">11</span><span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> dataList<span style="color: #0000FF;">&#91;</span><span style="color: #FF0000;">12</span><span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;,43656&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> dataList<span style="color: #0000FF;">&#91;</span><span style="color: #FF0000;">13</span><span style="color: #0000FF;">&#93;</span> <span style="color: #0000FF;">=</span> <span style="color: #009900;">&quot;4365,  55,31,24,   5,   5  ,1,      34&quot;</span> <span style="color: #0000FF;">/&gt;</span></span></pre></div></div>

<p>Now let&#8217;s use it!</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">&lt;!--- Use it! ---&gt;</span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span>
   <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfloop</span> array<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;#dataList#&quot;</span> <span style="color: #0000FF;">index</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;i&quot;</span><span style="color: #0000FF;">&gt;</span></span>  
      [<span style="color: #0000FF;">#i#</span>] =&gt; <span style="color: #0000FF;">#isNumericList<span style="color: #0000FF;">&#40;</span>i<span style="color: #0000FF;">&#41;</span>#</span><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">br</span> <span style="color: #0000FF;">/&gt;</span></span>
   <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfloop</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Results!</p>

<div class="wp_syntax"><div class="code"><pre class="txt" style="font-family:monospace;">[456c] =&gt; false
&nbsp;
[456] =&gt; true
&nbsp;
[45c,] =&gt; false
&nbsp;
[5,,,] =&gt; false
&nbsp;
[565,651,34,643232,45] =&gt; true
&nbsp;
[454,c,45,5454,32] =&gt; false
&nbsp;
[121.45,43,565,1,1,2] =&gt; false
&nbsp;
[43,54,65,1,] =&gt; false
&nbsp;
[67,54,73,436,] =&gt; false
&nbsp;
[,6565,656,77,32,3] =&gt; false
&nbsp;
[] =&gt; false
&nbsp;
[,43656] =&gt; false
&nbsp;
[4365,  55,31,24,   5,   5  ,1,      34] =&gt; true</pre></div></div>

<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://www.shinylight.com/2010/04/03/isnumericlist-function/&amp;submitHeadline=IsNumericList%28%29+Function&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.shinylight.com/2010/04/03/isnumericlist-function/&amp;title=IsNumericList%28%29+Function" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.shinylight.com/2010/04/03/isnumericlist-function/&amp;title=IsNumericList%28%29+Function" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://www.shinylight.com/2010/04/03/isnumericlist-function/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.shinylight.com/2010/04/03/isnumericlist-function/&amp;title=IsNumericList%28%29+Function" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://www.shinylight.com/2010/04/03/isnumericlist-function/&amp;bm_description=IsNumericList%28%29+Function" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://www.shinylight.com/2010/04/03/isnumericlist-function/&amp;T=IsNumericList%28%29+Function" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.shinylight.com/2010/04/03/isnumericlist-function/&amp;title=IsNumericList%28%29+Function" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.shinylight.com/2010/04/03/isnumericlist-function/&amp;title=IsNumericList%28%29+Function" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.shinylight.com/2010/04/03/isnumericlist-function/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://www.shinylight.com/2010/04/03/isnumericlist-function/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+IsNumericList%28%29+Function+@+http://www.shinylight.com/2010/04/03/isnumericlist-function/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.shinylight.com/2010/04/03/isnumericlist-function/&amp;t=IsNumericList%28%29+Function" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shinylight.com/2010/04/03/isnumericlist-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert Relative URLs to Absolute</title>
		<link>http://www.shinylight.com/2010/02/19/convert-relative-urls-to-absolute/</link>
		<comments>http://www.shinylight.com/2010/02/19/convert-relative-urls-to-absolute/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 04:29:02 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[ColdFusion]]></category>

		<guid isPermaLink="false">http://www.shinylight.com/?p=874</guid>
		<description><![CDATA[I put this ColdFusion UDF together the other day to turn relative URLs to Absolute. Code is pretty straightforward.

&#60;cffunction name=&#34;URLRelativeToAbsolute&#34; returntype=&#34;string&#34;
  hint=&#34;Converts relative URLs in an element and converts to absolute. It includes the http:// protocol prefix.&#34;&#62;  
&#160;
  &#60;cfargument name=&#34;content&#34; type=&#34;string&#34; required=&#34;true&#34; hint=&#34;HTML content that will be scanned and replaced.&#34; /&#62;
&#160;
  [...]]]></description>
			<content:encoded><![CDATA[<p>I put this ColdFusion UDF together the other day to turn relative URLs to Absolute. Code is pretty straightforward.</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cffunction</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;URLRelativeToAbsolute&quot;</span> returntype<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span></span>
<span style="color: #333333;">  <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Converts relative URLs in an element and converts to absolute. It includes the http:// protocol prefix.&quot;</span><span style="color: #0000FF;">&gt;</span></span>  
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;content&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;HTML content that will be scanned and replaced.&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfargument</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;domain&quot;</span> <span style="color: #0000FF;">type</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;string&quot;</span> <span style="color: #0000FF;">required</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;true&quot;</span> <span style="color: #0000FF;">hint</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;Add domain name to relative links.&quot;</span> <span style="color: #0000FF;">/&gt;</span></span>
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> <span style="color: #000000; font-weight: bold;">var</span> local <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">StructNew</span><span style="color: #0000FF;">&#40;</span><span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span> 
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!--- The following regexp handles the following elements: link, a, img, script, form, frame. ---&gt;</span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> local.contentFixed <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">REReplaceNoCase</span><span style="color: #0000FF;">&#40;</span> Arguments.<span style="color: #0000FF;">content</span>, <span style="color: #009900;">&quot;(href|src|action)=&quot;</span><span style="color: #009900;">&quot;/?((<span style="color: #000099; font-weight: bold;">\.</span>/)|(<span style="color: #000099; font-weight: bold;">\.</span><span style="color: #000099; font-weight: bold;">\.</span>/)+|)(?=[^http])&quot;</span>, <span style="color: #009900;">&quot;<span style="color: #000099; font-weight: bold;">\1</span>=&quot;</span><span style="color: #009900;">&quot;http://&quot;</span> <span style="color: #0000FF;">&amp;</span> domain <span style="color: #0000FF;">&amp;</span> <span style="color: #009900;">&quot;/&quot;</span>, <span style="color: #009900;">&quot;all&quot;</span> <span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>  
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!--- The following regexp handles the url() attribute of the background CSS property. ---&gt;</span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfset</span> local.contentFixed <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">REReplaceNoCase</span><span style="color: #0000FF;">&#40;</span> local.contentFixed, <span style="color: #009900;">&quot;url<span style="color: #000099; font-weight: bold;">\(</span>(<span style="color: #000099; font-weight: bold;">\s</span>)?(')?/?((<span style="color: #000099; font-weight: bold;">\.</span>/)|(<span style="color: #000099; font-weight: bold;">\.</span><span style="color: #000099; font-weight: bold;">\.</span>/)+|)(?=[^http])&quot;</span>, <span style="color: #009900;">&quot;url(<span style="color: #000099; font-weight: bold;">\2</span>http://&quot;</span> <span style="color: #0000FF;">&amp;</span> domain <span style="color: #0000FF;">&amp;</span> <span style="color: #009900;">&quot;/&quot;</span>, <span style="color: #009900;">&quot;all&quot;</span> <span style="color: #0000FF;">&#41;</span> <span style="color: #0000FF;">/&gt;</span></span>  
&nbsp;
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfreturn</span> local.contentFixed <span style="color: #0000FF;">/&gt;</span></span>    
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cffunction</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Usage:</p>

<div class="wp_syntax"><div class="code"><pre class="cfm" style="font-family:monospace;"><span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfsavecontent</span> variable<span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;htmlContent&quot;</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">textarea</span> <span style="color: #0000FF;">name</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;data&quot;</span> <span style="color: #0000FF;">rows</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;20&quot;</span> <span style="color: #0000FF;">cols</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;60&quot;</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">style</span><span style="color: #0000FF;">&gt;</span></span>
    body { 
      background-image:url('stars.png');
      background-image:url('../stars.png');
      background-image:url('/stars.png');
      background-image:url('/../../../stars.png');
    }
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">style</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">a</span> <span style="color: #0000FF;">href</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;../../../images/shiny.jpg&quot;</span><span style="color: #0000FF;">&gt;</span></span>Shiny<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">a</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">a</span> <span style="color: #0000FF;">href</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;http://www.google.com&quot;</span><span style="color: #0000FF;">&gt;</span></span>This should not be touched<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">a</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">img</span> <span style="color: #0000FF;">border</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;0&quot;</span> <span style="color: #0000FF;">src</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;/images/cool.png&quot;</span> <span style="color: #0000FF;">/&gt;</span></span> 
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">link</span> <span style="color: #0000FF;">rel</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;index&quot;</span> <span style="color: #0000FF;">href</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;../../index.asp&quot;</span><span style="color: #0000FF;">&gt;</span></span>
  <span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #000000; font-weight: bold;">form</span> <span style="color: #0000FF;">method</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;POST&quot;</span> <span style="color: #0000FF;">action</span><span style="color: #0000FF;">=</span><span style="color: #009900;">&quot;cgi/processing.cgi&quot;</span><span style="color: #0000FF;">&gt;</span></span><span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">form</span><span style="color: #0000FF;">&gt;</span></span>  
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #000000; font-weight: bold;">textarea</span><span style="color: #0000FF;">&gt;</span></span>
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfsavecontent</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span>
&nbsp;
  <span style="color: #0000FF;">#htmlContent#</span>
  #URLRelativeToAbsolute( htmlContent, &quot;www.shinylight.com&quot; )#
&nbsp;
<span style="color: #333333;"><span style="color: #0000FF;">&lt;/</span><span style="color: #990000; font-weight: bold;">cfoutput</span><span style="color: #0000FF;">&gt;</span></span></pre></div></div>

<p>Result:</p>
<p><img src="http://www.shinylight.com/wp-content/uploads/2010/02/before-after1.png" /></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://www.shinylight.com/2010/02/19/convert-relative-urls-to-absolute/&amp;submitHeadline=Convert+Relative+URLs+to+Absolute&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.shinylight.com/2010/02/19/convert-relative-urls-to-absolute/&amp;title=Convert+Relative+URLs+to+Absolute" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.shinylight.com/2010/02/19/convert-relative-urls-to-absolute/&amp;title=Convert+Relative+URLs+to+Absolute" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://www.shinylight.com/2010/02/19/convert-relative-urls-to-absolute/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.shinylight.com/2010/02/19/convert-relative-urls-to-absolute/&amp;title=Convert+Relative+URLs+to+Absolute" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://www.shinylight.com/2010/02/19/convert-relative-urls-to-absolute/&amp;bm_description=Convert+Relative+URLs+to+Absolute" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://www.shinylight.com/2010/02/19/convert-relative-urls-to-absolute/&amp;T=Convert+Relative+URLs+to+Absolute" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.shinylight.com/2010/02/19/convert-relative-urls-to-absolute/&amp;title=Convert+Relative+URLs+to+Absolute" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.shinylight.com/2010/02/19/convert-relative-urls-to-absolute/&amp;title=Convert+Relative+URLs+to+Absolute" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.shinylight.com/2010/02/19/convert-relative-urls-to-absolute/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://www.shinylight.com/2010/02/19/convert-relative-urls-to-absolute/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Convert+Relative+URLs+to+Absolute+@+http://www.shinylight.com/2010/02/19/convert-relative-urls-to-absolute/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.shinylight.com/2010/02/19/convert-relative-urls-to-absolute/&amp;t=Convert+Relative+URLs+to+Absolute" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shinylight.com/2010/02/19/convert-relative-urls-to-absolute/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get Latest File</title>
		<link>http://www.shinylight.com/2010/02/04/get-latest-file/</link>
		<comments>http://www.shinylight.com/2010/02/04/get-latest-file/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 03:37:31 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Automation / Scripting]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.shinylight.com/?p=794</guid>
		<description><![CDATA[In my last post, I made a quick script that checks for the date. It was very limiting, since it used the dir command. This one uses several date/time Python modules and is more capable.

import os, os.path, stat, time
from datetime import date, timedelta, datetime
&#160;
# Reference
# http://docs.python.org/library/datetime.html
# http://docs.python.org/library/time.html
&#160;
def getFileDate&#40; filenamePath &#41;:    
&#160;
  [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://www.shinylight.com/2010/01/30/compress-and-move-log-files/">my last post</a>, I made a quick script that checks for the date. It was very limiting, since it used the dir command. This one uses several date/time Python modules and is more capable.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>, <span style="color: #dc143c;">os</span>.<span style="color: black;">path</span>, <span style="color: #dc143c;">stat</span>, <span style="color: #dc143c;">time</span>
<span style="color: #ff7700;font-weight:bold;">from</span> <span style="color: #dc143c;">datetime</span> <span style="color: #ff7700;font-weight:bold;">import</span> date, timedelta, <span style="color: #dc143c;">datetime</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Reference</span>
<span style="color: #808080; font-style: italic;"># http://docs.python.org/library/datetime.html</span>
<span style="color: #808080; font-style: italic;"># http://docs.python.org/library/time.html</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> getFileDate<span style="color: black;">&#40;</span> filenamePath <span style="color: black;">&#41;</span>:    
&nbsp;
  used = <span style="color: #dc143c;">os</span>.<span style="color: #dc143c;">stat</span><span style="color: black;">&#40;</span> filenamePath <span style="color: black;">&#41;</span>.<span style="color: black;">st_mtime</span>      
  year, day, month, hour, minute, second = <span style="color: #dc143c;">time</span>.<span style="color: black;">localtime</span><span style="color: black;">&#40;</span>used<span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>:<span style="color: #ff4500;">6</span><span style="color: black;">&#93;</span>
  objDateTime = <span style="color: #dc143c;">datetime</span><span style="color: black;">&#40;</span>year, day, month, hour, minute, second<span style="color: black;">&#41;</span>
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">return</span> objDateTime
&nbsp;
  <span style="color: #808080; font-style: italic;"># Ways to reference this DateTime Object</span>
  <span style="color: #808080; font-style: italic;"># objDateTime.strftime(&quot;%Y-%m-%d %I:%M %p&quot;)</span>
  <span style="color: #808080; font-style: italic;"># objDateTime.year</span>
  <span style="color: #808080; font-style: italic;"># objDateTime.month</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">def</span> isDaysOldFromNow<span style="color: black;">&#40;</span> filenamepath, days <span style="color: black;">&#41;</span>:
&nbsp;
  <span style="color: #808080; font-style: italic;"># Checks how old a file is. Is it older than &quot;days&quot; [variable] days?</span>
  inTimeRange = <span style="color: #008000;">False</span>  
  timeDeltaDiff = <span style="color: black;">&#40;</span> <span style="color: #dc143c;">datetime</span>.<span style="color: black;">now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>-getFileDate<span style="color: black;">&#40;</span> filenamepath <span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>.<span style="color: black;">days</span>
&nbsp;
  <span style="color: #808080; font-style: italic;"># Check if the file's date is days old or less:</span>
  <span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span> timeDeltaDiff <span style="color: #66cc66;">&gt;</span>= days <span style="color: black;">&#41;</span>:
    inTimeRange = <span style="color: #008000;">True</span>  
&nbsp;
  <span style="color: #ff7700;font-weight:bold;">return</span> inTimeRange
&nbsp;
fname = <span style="color: #483d8b;">&quot;C:/temp/decision2.pdf&quot;</span>  
&nbsp;
<span style="color: #808080; font-style: italic;"># Set this variable to check if the file is this days old</span>
howOld = <span style="color: #ff4500;">3</span>
&nbsp;
&nbsp;
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: black;">&#40;</span> isDaysOldFromNow<span style="color: black;">&#40;</span> fname, howOld <span style="color: black;">&#41;</span> <span style="color: black;">&#41;</span>:
  <span style="color: #ff7700;font-weight:bold;">print</span> fname, <span style="color: #483d8b;">&quot;is more than&quot;</span>, howOld, <span style="color: #483d8b;">&quot;days old&quot;</span>
<span style="color: #ff7700;font-weight:bold;">else</span>:
  <span style="color: #ff7700;font-weight:bold;">print</span> fname, <span style="color: #483d8b;">&quot;is NOT more than&quot;</span>, howOld, <span style="color: #483d8b;">&quot;days old&quot;</span></pre></div></div>

<p>Output:<br />
<img src="http://www.shinylight.com/wp-content/uploads/2010/02/walk1.gif" alt="" title="walk1" width="546" height="387" class="alignnone size-full wp-image-795" /></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://www.shinylight.com/2010/02/04/get-latest-file/&amp;submitHeadline=Get+Latest+File&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.shinylight.com/2010/02/04/get-latest-file/&amp;title=Get+Latest+File" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.shinylight.com/2010/02/04/get-latest-file/&amp;title=Get+Latest+File" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://www.shinylight.com/2010/02/04/get-latest-file/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.shinylight.com/2010/02/04/get-latest-file/&amp;title=Get+Latest+File" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://www.shinylight.com/2010/02/04/get-latest-file/&amp;bm_description=Get+Latest+File" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://www.shinylight.com/2010/02/04/get-latest-file/&amp;T=Get+Latest+File" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.shinylight.com/2010/02/04/get-latest-file/&amp;title=Get+Latest+File" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.shinylight.com/2010/02/04/get-latest-file/&amp;title=Get+Latest+File" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.shinylight.com/2010/02/04/get-latest-file/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://www.shinylight.com/2010/02/04/get-latest-file/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Get+Latest+File+@+http://www.shinylight.com/2010/02/04/get-latest-file/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.shinylight.com/2010/02/04/get-latest-file/&amp;t=Get+Latest+File" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shinylight.com/2010/02/04/get-latest-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compress and Move Log Files</title>
		<link>http://www.shinylight.com/2010/01/30/compress-and-move-log-files/</link>
		<comments>http://www.shinylight.com/2010/01/30/compress-and-move-log-files/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 23:51:10 +0000</pubDate>
		<dc:creator>Dan</dc:creator>
				<category><![CDATA[Automation / Scripting]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Systems]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.shinylight.com/?p=788</guid>
		<description><![CDATA[Sometimes log files bog a system down. For one of our servers, I made this little Python script that compresses (via WinRAR) the log files in a directory, and then moves them to a backup location. The only little catch is that I wanted to leave the latest log files for in that directory. Log [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes log files bog a system down. For one of our servers, I made this little Python script that compresses (via WinRAR) the log files in a directory, and then moves them to a backup location. The only little catch is that I wanted to leave the latest log files for in that directory. Log files are created daily, so the the latest log files have a datestamp of today. Here&#8217;s how I did it.</p>
<p>First Create the Python Script:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">datetime</span>
&nbsp;
dateStamp  = <span style="color: #dc143c;">datetime</span>.<span style="color: #dc143c;">datetime</span>.<span style="color: black;">now</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">strftime</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;%Y-%m-%d&quot;</span><span style="color: black;">&#41;</span> 
imsLogPath = <span style="color: #483d8b;">'d:<span style="color: #000099; font-weight: bold;">\\</span>LogFiles<span style="color: #000099; font-weight: bold;">\\</span>'</span>                     
<span style="color: #808080; font-style: italic;"># Don't use a mapped drive but use UNC for network drives. Task Schedule seems to choke when it calls Python.</span>
newRARPath = <span style="color: #483d8b;">'&quot;<span style="color: #000099; font-weight: bold;">\\</span><span style="color: #000099; font-weight: bold;">\\</span>192.168.1.2<span style="color: #000099; font-weight: bold;">\\</span>Root<span style="color: #000099; font-weight: bold;">\\</span>backups<span style="color: #000099; font-weight: bold;">\\</span>'</span> + dateStamp + <span style="color: #483d8b;">'.rar&quot;'</span>
rarPath    = <span style="color: #483d8b;">'&quot;C:<span style="color: #000099; font-weight: bold;">\\</span>Program Files<span style="color: #000099; font-weight: bold;">\\</span>WinRAR<span style="color: #000099; font-weight: bold;">\\</span>rar.exe&quot; a -m5 '</span> + newRARPath 
&nbsp;
<span style="color: #808080; font-style: italic;"># Get Latest Files</span>
smtpLatest   = <span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;dir /od /a-d /b &quot;</span> + imsLogPath + <span style="color: #483d8b;">&quot;SMTP*.log&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">splitlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
postLatest   = <span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;dir /od /a-d /b &quot;</span> + imsLogPath + <span style="color: #483d8b;">&quot;POST*.log&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">splitlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
ischedLatest = <span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;dir /od /a-d /b &quot;</span> + imsLogPath + <span style="color: #483d8b;">&quot;iSched*.log&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">splitlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
relayLatest  = <span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;dir /od /a-d /b &quot;</span> + imsLogPath + <span style="color: #483d8b;">&quot;Relay*.log&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">splitlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
qengLatest   = <span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;dir /od /a-d /b &quot;</span> + imsLogPath + <span style="color: #483d8b;">&quot;Qeng*.log&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">splitlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span>-<span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Get List of All Files</span>
allFiles     = <span style="color: #dc143c;">os</span>.<span style="color: black;">popen</span><span style="color: black;">&#40;</span>r<span style="color: #483d8b;">&quot;dir /od /a-d /b &quot;</span> + imsLogPath + <span style="color: #483d8b;">&quot;*.log&quot;</span><span style="color: black;">&#41;</span>.<span style="color: black;">read</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">splitlines</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Remove Latest Files from All Files List</span>
allFiles.<span style="color: black;">remove</span><span style="color: black;">&#40;</span> smtpLatest <span style="color: black;">&#41;</span>
allFiles.<span style="color: black;">remove</span><span style="color: black;">&#40;</span> postLatest <span style="color: black;">&#41;</span>
allFiles.<span style="color: black;">remove</span><span style="color: black;">&#40;</span> ischedLatest <span style="color: black;">&#41;</span>
allFiles.<span style="color: black;">remove</span><span style="color: black;">&#40;</span> relayLatest <span style="color: black;">&#41;</span>
allFiles.<span style="color: black;">remove</span><span style="color: black;">&#40;</span> qengLatest <span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># allFiles Array Has the list of files</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Flatten Array allFiles to be used as a parameter in system command</span>
flatLogPathList = <span style="color: #483d8b;">&quot;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">for</span> filenameWithPath <span style="color: #ff7700;font-weight:bold;">in</span> allFiles:
  flatLogPathList = flatLogPathList + imsLogPath + filenameWithPath + <span style="color: #483d8b;">&quot; &quot;</span>
&nbsp;
&nbsp;
<span style="color: #808080; font-style: italic;"># Execute WinRar</span>
path = rarPath + <span style="color: #483d8b;">&quot; &quot;</span> + flatLogPathList.<span style="color: black;">rstrip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
<span style="color: #dc143c;">os</span>.<span style="color: black;">system</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">'&quot;'</span> + path + <span style="color: #483d8b;">'&quot;'</span> <span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Delete all log files</span>
<span style="color: #dc143c;">os</span>.<span style="color: black;">system</span><span style="color: black;">&#40;</span> <span style="color: #483d8b;">'&quot;del '</span> + flatLogPathList.<span style="color: black;">rstrip</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span> + <span style="color: #483d8b;">'&quot;'</span> <span style="color: black;">&#41;</span></pre></div></div>

<p>Then I set up the Scheduled Task:</p>
<p><img src="http://www.shinylight.com/wp-content/uploads/2010/01/ims-1.gif" alt="" title="ims-1" width="405" height="448" class="alignnone size-full wp-image-789" /></p>
<p>With these Settings:</p>
<p><img src="http://www.shinylight.com/wp-content/uploads/2010/01/ims-2.gif" alt="" title="ims-2" width="403" height="448" class="alignnone size-full wp-image-790" /></p>
<!-- Social Bookmarks BEGIN -->
<div class="social_bookmark">
<a><strong><em></em></strong></a>
<br />
<div class="d">
<br />
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://buzz.yahoo.com/submit?submitUrl=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/&amp;submitHeadline=Compress+and+Move+Log+Files&amp;submitSummary=" rel="nofollow" title="Add to&nbsp;Buzz"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/buzz.png" title="Add to&nbsp;Buzz" alt="Add to&nbsp;Buzz" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://del.icio.us/post?url=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/&amp;title=Compress+and+Move+Log+Files" rel="nofollow" title="Add to&nbsp;Del.icio.us"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/delicious.png" title="Add to&nbsp;Del.icio.us" alt="Add to&nbsp;Del.icio.us" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://digg.com/submit?phase=2&amp;url=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/&amp;title=Compress+and+Move+Log+Files" rel="nofollow" title="Add to&nbsp;digg"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/digg.png" title="Add to&nbsp;digg" alt="Add to&nbsp;digg" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.facebook.com/sharer.php?u=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/" rel="nofollow" title="Add to&nbsp;Facebook"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/facebook.png" title="Add to&nbsp;Facebook" alt="Add to&nbsp;Facebook" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.google.com/bookmarks/mark?op=edit&amp;output=popup&amp;bkmk=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/&amp;title=Compress+and+Move+Log+Files" rel="nofollow" title="Add to&nbsp;Google Bookmarks"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/google.png" title="Add to&nbsp;Google Bookmarks" alt="Add to&nbsp;Google Bookmarks" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.mister-wong.com/index.php?action=addurl&amp;bm_url=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/&amp;bm_description=Compress+and+Move+Log+Files" rel="nofollow" title="Add to&nbsp;Mister Wong"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/misterwong.png" title="Add to&nbsp;Mister Wong" alt="Add to&nbsp;Mister Wong" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.netscape.com/submit/?U=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/&amp;T=Compress+and+Move+Log+Files" rel="nofollow" title="Add to&nbsp;Netscape"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/netscape.png" title="Add to&nbsp;Netscape" alt="Add to&nbsp;Netscape" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://reddit.com/submit?url=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/&amp;title=Compress+and+Move+Log+Files" rel="nofollow" title="Add to&nbsp;reddit"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/reddit.png" title="Add to&nbsp;reddit" alt="Add to&nbsp;reddit" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.stumbleupon.com/submit.php?url=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/&amp;title=Compress+and+Move+Log+Files" rel="nofollow" title="Add to&nbsp;Stumble Upon"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/stumbleupon.png" title="Add to&nbsp;Stumble Upon" alt="Add to&nbsp;Stumble Upon" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://www.technorati.com/faves?add=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/" rel="nofollow" title="Add to&nbsp;Technorati"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/technorati.png" title="Add to&nbsp;Technorati" alt="Add to&nbsp;Technorati" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://tipd.com/submit.php?url=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/" rel="nofollow" title="Add to&nbsp;Tip'd"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/tipd.png" title="Add to&nbsp;Tip'd" alt="Add to&nbsp;Tip'd" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://twitter.com/home/?status=Check+out+Compress+and+Move+Log+Files+@+http://www.shinylight.com/2010/01/30/compress-and-move-log-files/" rel="nofollow" title="Add to&nbsp;Twitter"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/twitter.png" title="Add to&nbsp;Twitter" alt="Add to&nbsp;Twitter" /></a>
<a onclick="window.open(this.href, '_blank', 'scrollbars=yes,menubar=no,height=600,width=750,resizable=yes,toolbar=no,location=no,status=no'); return false;" href="http://myweb2.search.yahoo.com/myresults/bookmarklet?u=http://www.shinylight.com/2010/01/30/compress-and-move-log-files/&amp;t=Compress+and+Move+Log+Files" rel="nofollow" title="Add to&nbsp;Yahoo My Web"><img class="social_img" src="http://www.shinylight.com/wp-content/plugins/social-bookmarks/images/yahoo.png" title="Add to&nbsp;Yahoo My Web" alt="Add to&nbsp;Yahoo My Web" /></a>
<br />
</div>
</div>
<!-- Social Bookmarks END -->
]]></content:encoded>
			<wfw:commentRss>http://www.shinylight.com/2010/01/30/compress-and-move-log-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
