<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: truncate code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 27 Jul 2008 04:09:22 GMT</pubDate>
    <description>DZone Snippets: truncate code</description>
    <item>
      <title>truncate Rails development/test logs</title>
      <link>http://snippets.dzone.com/posts/show/4399</link>
      <description>In rails applications development.log and test.log like to grow forever, which takes up space and makes them slow to grep.  If I just delete them running processes with logs open might get confused.  So I can use truncate instead:&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;truncate ~/www/*/log/*.log&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Even easier, ask cron to do it for me every night:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;4 22 * * * * truncate -s 0k  ~/www/*/log/*.log&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 07 Aug 2007 17:17:16 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4399</guid>
      <author>laurelfan (Laurel Fan)</author>
    </item>
    <item>
      <title>Truncate text with word boundaries in Ruby</title>
      <link>http://snippets.dzone.com/posts/show/804</link>
      <description>&lt;code&gt;&lt;br /&gt;  def truncate_words(text, length = 30, end_string = ' &#8230;')&lt;br /&gt;    words = text.split()&lt;br /&gt;    words[0..(length-1)].join(' ') + (words.length &gt; length ? end_string : '')&lt;br /&gt;  end&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 12 Oct 2005 04:17:01 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/804</guid>
      <author>chao (Chao Lam)</author>
    </item>
    <item>
      <title>Truncate String by Words</title>
      <link>http://snippets.dzone.com/posts/show/412</link>
      <description>This will take a phrase and truncate it at the word level&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;&lt;br /&gt;function trunc($phrase, $max_words)&lt;br /&gt;{&lt;br /&gt;   $phrase_array = explode(' ',$phrase);&lt;br /&gt;   if(count($phrase_array) &gt; $max_words &amp;&amp; $max_words &gt; 0)&lt;br /&gt;      $phrase = implode(' ',array_slice($phrase_array, 0, $max_words)).'...'  &lt;br /&gt;   return $phrase;&lt;br /&gt;}&lt;br /&gt;?&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 26 Jun 2005 02:18:59 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/412</guid>
      <author>banderson623 (Brian Anderson)</author>
    </item>
  </channel>
</rss>
