<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Phrogz's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 07 Sep 2008 18:15:15 GMT</pubDate>
    <description>DZone Snippets: Phrogz's Code Snippets</description>
    <item>
      <title>Splitting/Joining URLs</title>
      <link>http://snippets.dzone.com/posts/show/237</link>
      <description>&lt;code&gt;File.dirname "http://foo.com/bar/stuff.html"&lt;br /&gt;#=&gt; "http://foo.com/bar"&lt;br /&gt;&lt;br /&gt;File.basename "http://foo.com/bar/stuff.html"&lt;br /&gt;#=&gt; "stuff.html"&lt;br /&gt;&lt;br /&gt;File.split "http://foo.com/bar/stuff.html"&lt;br /&gt;#=&gt; ["http://foo.com/bar", "stuff.html"]&lt;br /&gt;&lt;br /&gt;File.join( File.dirname("http://foo.com/bar/doc.html"), "relative_link.html" )&lt;br /&gt;# =&gt; "http://foo.com/bar/relative_link.html"&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;(Originally by Ilmari Heikkinen on the ruby-talk mailing list.)</description>
      <pubDate>Fri, 29 Apr 2005 22:04:55 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/237</guid>
      <author>Phrogz (Gavin Kistner)</author>
    </item>
    <item>
      <title>Loop through an array without wasteful lookups</title>
      <link>http://snippets.dzone.com/posts/show/29</link>
      <description>Looking up the length of an array on each iteration of a loop is slow and inefficient (if the length of the array isn't changing).&lt;br /&gt;&lt;br /&gt;If it's OK to iterate from back to front:&lt;br /&gt;&lt;code&gt;for ( var i=myArray.length-1; i&gt;=0; --i ){&lt;br /&gt;  ...&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;If you need to go from front to back:&lt;br /&gt;&lt;code&gt;for ( var i=0, len=myArray.length; i&lt;len; ++i ){&lt;br /&gt;  ...&lt;br /&gt;}&lt;/code&gt;</description>
      <pubDate>Sun, 03 Apr 2005 06:29:18 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/29</guid>
      <author>Phrogz (Gavin Kistner)</author>
    </item>
    <item>
      <title>Add a JS function for bounded random numbers</title>
      <link>http://snippets.dzone.com/posts/show/26</link>
      <description>&lt;code&gt;Math.randomMax = function(maxVal,asFloat){&lt;br /&gt;	var val = Math.random()*maxVal;&lt;br /&gt;	return asFloat?val:Math.round(val);&lt;br /&gt;}&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;For a random integer between 0 and 10 (inclusive), simply:&lt;br /&gt;&lt;code&gt;var theNumber = Math.randomMax( 10 );&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;For a random float value between 0 and 10, pass a truth value to the second parameter:&lt;br /&gt;&lt;code&gt;var theNumber = Math.randomMax( 10, true );&lt;/code&gt;&lt;br /&gt;</description>
      <pubDate>Sun, 03 Apr 2005 06:13:12 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/26</guid>
      <author>Phrogz (Gavin Kistner)</author>
    </item>
  </channel>
</rss>
