<?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>Gudasoft &#187; source</title>
	<atom:link href="http://www.gudasoft.com/tag/source/feed" rel="self" type="application/rss+xml" />
	<link>http://www.gudasoft.com</link>
	<description>Impossible is nothing</description>
	<lastBuildDate>Thu, 06 Oct 2011 07:17:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.5</generator>
		<item>
		<title>Chunks for the String method.</title>
		<link>http://www.gudasoft.com/english/development/09/10/125/chunks-for-the-string-method/2008</link>
		<comments>http://www.gudasoft.com/english/development/09/10/125/chunks-for-the-string-method/2008#comments</comments>
		<pubDate>Wed, 10 Sep 2008 08:59:47 +0000</pubDate>
		<dc:creator>guda</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[open]]></category>
		<category><![CDATA[source]]></category>

		<guid isPermaLink="false">http://www.gudasoft.com/?p=125</guid>
		<description><![CDATA[If you want to generate some sort of chunks from a large strings you can use the following method. You give as a param an array of arrays, each array is pointing with % the start position of the chunk and the last position. class String def String.random_alphanumeric(size=16) (1..size).collect { (i = Kernel.rand(62); i += [...]]]></description>
			<content:encoded><![CDATA[<p>If you want to generate some sort of chunks from a large strings you can use the following method.<br />
You give as a param an array of arrays, each array is pointing with % the start position of the chunk and the last position.</p>
<p><code><br />
class String</p>
<p>  def String.random_alphanumeric(size=16)<br />
    (1..size).collect { (i = Kernel.rand(62); i += ((i < 10) ? 48 : ((i < 36) ? 55 : 61 ))).chr }.join<br />
  end</p>
<p>  def chunkanize(parts = [[0,4], [48, 52], [95, 100]])<br />
    return [self] if self.size <= 1</p>
<p>    # working with words<br />
    terms_array = self.split(/ /)<br />
    join_type = " "</p>
<p>    # working with letters<br />
    if terms_array.size <= 100<br />
      terms_array = self.split(//)<br />
      join_type = ""<br />
    end</p>
<p>    one_percent = terms_array.size.to_f / 100</p>
<p>    parts.collect do |part|<br />
      start = part[0]<br />
      stop = part[1]<br />
      terms_array[(start * one_percent)..(stop * one_percent)].join(join_type)<br />
    end<br />
  end</p>
<p>end<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gudasoft.com/english/development/09/10/125/chunks-for-the-string-method/2008/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

