<?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>purpleAsphalt &#187; code</title>
	<atom:link href="http://www.purpleasphalt.com/cats/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.purpleasphalt.com</link>
	<description>a programmers ramblings about everything</description>
	<lastBuildDate>Tue, 22 Feb 2011 21:12:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>I heart groovy</title>
		<link>http://www.purpleasphalt.com/2011/01/19/i-heart-groovy/</link>
		<comments>http://www.purpleasphalt.com/2011/01/19/i-heart-groovy/#comments</comments>
		<pubDate>Wed, 19 Jan 2011 14:51:39 +0000</pubDate>
		<dc:creator>David Herman</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[groovy]]></category>

		<guid isPermaLink="false">http://www.purpleasphalt.com/?p=164</guid>
		<description><![CDATA[Reason number 2343242354 why i love groovy &#8211; I had a bunch of urls and I needed to run NSLOOKUP on them. I had a couple of options, write a shell script, do each by hand, write it in java (eeek) or write it in groovy. I chose groovy. ["https://www.googleadservices.com", "https://roia.biz", "https://www.emjcd.com", "https://nmargin.com", "https://ssl.google-analytics.com", "https://www.ifactz.com", [...]]]></description>
			<content:encoded><![CDATA[<p>Reason number 2343242354 why i love groovy &#8211; I had a bunch of urls and I needed to run NSLOOKUP on them.  I had a couple of options, write a shell script, do each by hand, write it in java (eeek) or write it in groovy.  I chose groovy.</p>
<pre class="brush: groovy">["https://www.googleadservices.com",
"https://roia.biz",
"https://www.emjcd.com",
"https://nmargin.com",
"https://ssl.google-analytics.com",
"https://www.ifactz.com",
"https://secure.interclick.com",
"https://r.turn.com",
"https://secure.trafficmp.com",
"https://secure.fastclick.net",
"https://ads.revsci.net",
"https://conv.opt.fimserve.com",
"https://ds.contextweb.com",
"https://ad.yieldmanager.com",
"https://beacon.dedicatednetworks.com",
"https://flex.atdmt.com",
"https://seal.verisign.com",
"https://sealserver.trustkeeper.net"].each{ url -&gt;
println "nslookup ${url[8..-1]}".execute().text
}</pre>
<p>Ok let&#8217;s look whats going on here.  First thing you&#8217;ll notice if you&#8217;re coming from the java world is there is no class definition, there&#8217;s an implicit class created for you so for simple scripts especially run once scripts like this, it&#8217;s not necessary.</p>
<p>
The first part is a list which is created with []</p>
<pre class="brush: groovy">["https://www.googleadservices.com",
"https://roia.biz"]</pre>
</p>
<p>
Next we are calling a method on the list called .each which accepts a closure which is in this case</p>
<pre class="brush: groovy">{ url -&gt;
println "nslookup ${url[8..-1]}".execute().text
}</pre>
</p>
<p>
Contained in this closure is what I really needed to do, which was do an <code>NSLOOKUP</code> on each url, but only the domain, I had to strip out the protocol (I know this could have easily been done with a search and replace in my editor but then you don&#8217;t have any example code)
</p>
<p>We start by creating a groovy string &#8211; denoted by the<code>""</code> which allows us to substitute the url in with the ${url} syntax. Another niceity is to omit the {}&#8217;s if you do not need to run any additional methods on the variable you are substituting &#8211; had the <code>https://</code> not been in the url i could have written it like so:</p>
<pre  class="brush: groovy">
println "nslookup $url".execute().text
</pre>
</p>
<p>What you&#8217;ll notice is by using the array index notation with a range I am able to get all chars starting at position 8 and go all the way to the end (in groovy -1 means the end of the string, -2 would be 2 from the right -3, 3 from the right etc. &#8211; <code>no more subString(pos, string.len - pos)</code>) This same syntax also works with lists</p>
<p>Now that I have the portion of the domain I need, we call .execute() on it.  In groovy a <code>.execute</code> method is added to the String class and when doing so the entire string will be passed to the command line and executed. The following would print out the directory listing where the script was running.</p>
<pre  class="brush: groovy">
"ls -la".execute().text
</pre>
</p>
<p>Finally we call <code>.text </code>(equivalent of .<code>getText()</code>) since .execute only returns a <code>java.lang.UNIXProcess</code> and the text property gives you back the output</p>
<p>Also note that println is the equivalent of <code>System.out.println("text")</code> &#8211; it&#8217;s just another groovy shortcut.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.purpleasphalt.com/2011/01/19/i-heart-groovy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pods Fail</title>
		<link>http://www.purpleasphalt.com/2008/11/30/pods-fail/</link>
		<comments>http://www.purpleasphalt.com/2008/11/30/pods-fail/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 16:03:11 +0000</pubDate>
		<dc:creator>David Herman</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[cms]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[pods]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.purpleasphalt.com/?p=97</guid>
		<description><![CDATA[Always on the lookout for new tools I thought I&#8217;d try and install pods.Â  Pods claims to be a simple cms tool that allows you to create relatable objects. You can create master &#62; detail pages, calendars, photo albums. Seems to be the simple &#8220;relational db&#8221; plugin I&#8217;ve been looking for. The install instructions are: [...]]]></description>
			<content:encoded><![CDATA[<p>Always on the lookout for new tools I thought I&#8217;d try and install <a title="pods" href="http://pods.uproot.us/">pods</a>.Â  Pods claims to be a simple cms tool that allows you to create relatable objects.  You can create master &gt; detail pages, calendars, photo albums.  Seems to be the simple &#8220;relational db&#8221; plugin I&#8217;ve been looking for.</p>
<p>The install instructions are:</p>
<ol>
<li>Copy the pods .htaccess file and overwrite yours</li>
<li>Change the permalink to /%postname%/</li>
<li>Activate plugin</li>
</ol>
<p>I followed those instructions and got the following warnings</p>
<p><code>Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /purpleasphalt/wp-content/plugins/pods/init.php on line 33</code></p>
<p><code>Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /purpleasphalt/wp-content/plugins/pods/sql/update.php on line 4<br />
</code></p>
<p><code>Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /purpleasphalt/wp-content/plugins/pods/sql/update.php on line 11<br />
</code></p>
<p><code>Warning: Cannot modify header information - headers already sent by (output started at /purpleasphalt/wp-content/plugins/pods/init.php:33) in /purpleasphalt/wp-includes/classes.php on line 1569<br />
</code></p>
<p>On I trudged ignoring the errors.  I was able to create a new pod, or at least it showed up on the screen, but when I refreshed, it was gone.</p>
<p>I started poking around the comments section of the site and found that the warnings would be cleared up in the next release.   I also noted that issues can be cleared up by removing the associated pods tables, and that they would be re-created.  However it looks like from my warnings that pods could not determine if it had already installed itself.  My suspicions were correct when I checked mysql and found that there were no pods tables found.</p>
<p>I&#8217;ll post more when 1.2.1 hits and the warnings go away.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.purpleasphalt.com/2008/11/30/pods-fail/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

