<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: Jazzido's Code Snippets</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 02:51:25 GMT</pubDate>
    <description>DZone Snippets: Jazzido's Code Snippets</description>
    <item>
      <title>Use the contents of a WordPress database in your Rails app</title>
      <link>http://snippets.dzone.com/posts/show/1314</link>
      <description>These two models can be used to access the posts and associated comments of a WordPress database.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class WpBlogComment &lt; ActiveRecord::Base&lt;br /&gt;&lt;br /&gt;  # if wordpress tables live in a different database (i.e. 'wordpress') change the following&lt;br /&gt;  # line to set_table_name "wordpress.wp_comments"&lt;br /&gt;  # don't forget to give the db user permissions to access the wordpress db&lt;br /&gt;  set_table_name "wp_comments"&lt;br /&gt;  set_primary_key "comment_ID"&lt;br /&gt;&lt;br /&gt;  belongs_to :post , :class_name =&gt; "WpBlogPost", :foreign_key =&gt; "comment_post_ID"&lt;br /&gt;&lt;br /&gt;  validates_presence_of :comment_post_ID, :comment_author, :comment_content, :comment_author_email&lt;br /&gt;  &lt;br /&gt;  def validate_on_create&lt;br /&gt;    if WpBlogPost.find(comment_post_ID).comment_status != 'open'&lt;br /&gt;      errors.add_to_base('Sorry, comments are closed for this post')&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;end &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class WpBlogPost &lt; ActiveRecord::Base&lt;br /&gt;&lt;br /&gt;  set_table_name "wp_posts"&lt;br /&gt;  set_primary_key "ID"&lt;br /&gt;&lt;br /&gt;  has_many :comments, :class_name =&gt; "WpBlogComment", :foreign_key =&gt; "comment_post_ID"&lt;br /&gt;&lt;br /&gt;  def self.find_by_permalink(year, month, day, title)&lt;br /&gt;    find(:first, &lt;br /&gt;         :conditions =&gt; ["YEAR(post_date) = ? AND MONTH(post_date) = ? AND DAYOFMONTH(post_date) = ? AND post_name = ?", year.to_i, month.to_i, day.to_i, title])&lt;br /&gt;  end&lt;br /&gt;end &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;</description>
      <pubDate>Mon, 30 Jan 2006 04:10:02 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1314</guid>
      <author>jazzido (Manuel Aristar&#225;n)</author>
    </item>
    <item>
      <title>On-the-fly thumbnailer method for a Rails 'Photo' controller</title>
      <link>http://snippets.dzone.com/posts/show/71</link>
      <description>&lt;code&gt;&lt;br /&gt;require 'RMagick'&lt;br /&gt;&lt;br /&gt;class PhotoController &lt; ApplicationController&lt;br /&gt;&lt;br /&gt;[...snip...]&lt;br /&gt;&lt;br /&gt;    def render_resized_image&lt;br /&gt;                @photo=Photo.find(@params["id"])&lt;br /&gt;&lt;br /&gt;                maxw = @params["width"] != nil ? @params["width"].to_i : 90&lt;br /&gt;                maxh = @params["height"] != nil ? @params["height"].to_i : 90&lt;br /&gt;                aspectratio = maxw.to_f / maxh.to_f&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;                pic = Magick::Image.from_blob(@photo.image)[0]&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;                picw = pic.columns&lt;br /&gt;                pich = pic.rows&lt;br /&gt;                picratio = picw.to_f / pich.to_f&lt;br /&gt;&lt;br /&gt;                if picratio &gt; aspectratio then&lt;br /&gt;                        scaleratio = maxw.to_f / picw&lt;br /&gt;                else&lt;br /&gt;                        scaleratio = maxh.to_f / pich&lt;br /&gt;                end&lt;br /&gt;&lt;br /&gt;                #breakpoint&lt;br /&gt;&lt;br /&gt;                thumb = pic.resize(scaleratio)&lt;br /&gt;&lt;br /&gt;                @response.headers["Content-type"]=@photo.mime&lt;br /&gt;    end&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;p&gt;Requires &lt;a href="http://rmagick.rubyforge.org/"&gt;RMagick&lt;/a&gt;&lt;/p&gt;&lt;br /&gt;&lt;p&gt;Based on &lt;a href="http://www.bigbold.com/snippets/posts/show/36"&gt;Thumbnailer in Ruby and RMagick&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Fri, 08 Apr 2005 06:47:20 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/71</guid>
      <author>jazzido (Manuel Aristar&#225;n)</author>
    </item>
  </channel>
</rss>
