<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: rails code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 10 Oct 2008 23:17:53 GMT</pubDate>
    <description>DZone Snippets: rails 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>Typo export to Wordpress WXR (script version)</title>
      <link>http://snippets.dzone.com/posts/show/4326</link>
      <description>I tried to use this method here: http://snippets.dzone.com/posts/show/3264 however my typo blog was too slow and it kept timing out (which is why we're switching to wordpress anyway...).  So I stole the code and hacked it up a bit so it could be run as a script.&lt;br /&gt;&lt;br /&gt;Put this in $RAILS_ROOT/script/wp_export.rb, and run it like:&lt;br /&gt;&lt;code&gt;&lt;br /&gt;RAILS_ENV=production ./script/wp_export.rb &gt; out.wxr&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Import it with the "Import Wordpress" tool in your wordpress blog's admin interface.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/usr/bin/env ruby&lt;br /&gt;require File.dirname(__FILE__) + '/../config/boot'&lt;br /&gt;require 'environment'&lt;br /&gt;&lt;br /&gt;require 'application'&lt;br /&gt;&lt;br /&gt;# we need a controller to generate html output&lt;br /&gt;class FakeController &lt; ApplicationController&lt;br /&gt;  include ActionView::Helpers::TextHelper&lt;br /&gt;  include ActionView::Helpers::TagHelper&lt;br /&gt;end&lt;br /&gt;fake_controller = FakeController.new&lt;br /&gt;&lt;br /&gt;articles = Article.find(:all)&lt;br /&gt;&lt;br /&gt;xml = Builder::XmlMarkup.new(:target =&gt; STDOUT, :indent =&gt; 2)&lt;br /&gt;&lt;br /&gt;xml.instruct! :xml, :version=&gt;"1.0", :encoding=&gt;"UTF-8"&lt;br /&gt;xml.rss 'version' =&gt; "2.0",&lt;br /&gt;        'xmlns:content' =&gt; "http://purl.org/rss/1.0/modules/content/",&lt;br /&gt;        'xmlns:wfw' =&gt; "http://wellformedweb.org/CommentAPI/",&lt;br /&gt;        'xmlns:dc' =&gt; "http://purl.org/dc/elements/1.1/",&lt;br /&gt;        'xmlns:wp' =&gt; "http://wordpress.org/export/1.0/" do&lt;br /&gt;  xml.channel do&lt;br /&gt;    xml.title "The Robot Co-op"&lt;br /&gt;    xml.link "http://www.robotcoop.com"&lt;br /&gt;    xml.language "en-us"&lt;br /&gt;    xml.ttl "40"&lt;br /&gt;    xml.description "Robot coop blog"&lt;br /&gt;&lt;br /&gt;    articles.each do |a|&lt;br /&gt;        xml.item do&lt;br /&gt;          xml.title a.title&lt;br /&gt;          xml.content(:encoded) { |x| x &lt;&lt; a.html(fake_controller, :all) }&lt;br /&gt;          xml.pubDate a.published_at.rfc2822&lt;br /&gt;          xml.guid "urn:uuid:{a.guid}", "isPermaLink" =&gt; "false"&lt;br /&gt;          author = a.user.name rescue a.author&lt;br /&gt;          xml.author author&lt;br /&gt;          xml.dc :creator, author&lt;br /&gt;          for category in a.categories&lt;br /&gt;            xml.category category.name&lt;br /&gt;          end&lt;br /&gt;          for tag in a.tags&lt;br /&gt;            xml.category tag.display_name&lt;br /&gt;          end&lt;br /&gt;          xml.wp :post_id, a.id&lt;br /&gt;          xml.wp :post_date, a.published_at.strftime("%Y-%m-%d %H:%M:%S")&lt;br /&gt;          xml.wp :comment_status, 'closed'&lt;br /&gt;          xml.wp :ping_status, 'closed'&lt;br /&gt;          xml.wp :post_name, a.permalink&lt;br /&gt;          xml.wp :status, 'publish'&lt;br /&gt;          xml.wp :post_parent, '0'&lt;br /&gt;          xml.wp :post_type, 'post'&lt;br /&gt;          for comment in a.comments&lt;br /&gt;            xml.wp(:comment) do&lt;br /&gt;              xml.wp :comment_id, comment.id&lt;br /&gt;              xml.wp :comment_author, comment.author&lt;br /&gt;              xml.wp :comment_author_email, comment.email&lt;br /&gt;              xml.wp :comment_author_url, comment.url&lt;br /&gt;              xml.wp :comment_author_IP, comment.ip&lt;br /&gt;              xml.wp :comment_date, comment.published_at.strftime("%Y-%m-%d %H:%M:%S")&lt;br /&gt;              xml.wp(:comment_content) { |x| x &lt;&lt; comment.body }&lt;br /&gt;              xml.wp :comment_approved, '1'&lt;br /&gt;              xml.wp :comment_parent, '0'&lt;br /&gt;            end&lt;br /&gt;          end&lt;br /&gt;       end&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 18 Jul 2007 23:41:54 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4326</guid>
      <author>laurelfan (Laurel Fan)</author>
    </item>
  </channel>
</rss>
