<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Tristan Media Blog</title>
	
	<link>http://blog.tristanmedia.com</link>
	<description>One can never have enough scripting languages: Notes on Perl, PHP, and Ruby</description>
	<lastBuildDate>Thu, 27 Jan 2011 16:21:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/TristanMediaBlog" /><feedburner:info uri="tristanmediablog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>TristanMediaBlog</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Validating URLs for non-ActiveRecord objects</title>
		<link>http://feedproxy.google.com/~r/TristanMediaBlog/~3/pa14yVfQc4c/</link>
		<comments>http://blog.tristanmedia.com/2010/07/validating-urls-for-non-activerecord-objects/#comments</comments>
		<pubDate>Fri, 09 Jul 2010 23:12:10 +0000</pubDate>
		<dc:creator>Barry</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[mongoid]]></category>

		<guid isPermaLink="false">http://blog.tristanmedia.com/?p=107</guid>
		<description><![CDATA[I'm using Mongoid and MongoDB on a new project, so my models are not derived from ActiveModel. On previous projects I just used the validates_url_format_of plugin, but for this project I put the code from the module into an initializer (config/initializers/validation.rb) and used extend. module ValidatesUrlFormatOf IPv4_PART = /\d&#124;&#91;1-9&#93;\d&#124;1\d\d&#124;2&#91;0-4&#93;\d&#124;25&#91;0-5&#93;/ # 0-255 REGEXP = %r&#123; \A [...]]]></description>
			<content:encoded><![CDATA[<p>I'm using <a href="http://mongoid.org/">Mongoid</a> and MongoDB on a new project, so my models are not derived from ActiveModel.  On previous projects I just used the <a href="http://github.com/henrik/validates_url_format_of">validates_url_format_of</a> plugin, but for this project I put the code from the module into an initializer (config/initializers/validation.rb) and used <code>extend</code>.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> ValidatesUrlFormatOf
  IPv4_PART = <span style="color:#006600; font-weight:bold;">/</span>\d<span style="color:#006600; font-weight:bold;">|</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span>\d<span style="color:#006600; font-weight:bold;">|</span><span style="color:#006666;">1</span>\d\d<span style="color:#006600; font-weight:bold;">|</span><span style="color:#006666;">2</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#93;</span>\d<span style="color:#006600; font-weight:bold;">|</span><span style="color:#006666;">25</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">/</span>  <span style="color:#008000; font-style:italic;"># 0-255</span>
  REGEXP = <span style="color:#006600; font-weight:bold;">%</span>r<span style="color:#006600; font-weight:bold;">&#123;</span>
    \A
    https?:<span style="color:#006600; font-weight:bold;">//</span>                                                    <span style="color:#008000; font-style:italic;"># http:// or https://</span>
    <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\s:@<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+</span>:<span style="color:#006600; font-weight:bold;">&#91;</span>^\s:@<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">*</span>@<span style="color:#006600; font-weight:bold;">&#41;</span>?                                        <span style="color:#008000; font-style:italic;"># optional username:pw@</span>
    <span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\W_<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+</span>\.<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">*</span>xn<span style="color:#006600; font-weight:bold;">--</span><span style="color:#006600; font-weight:bold;">&#41;</span>?<span style="color:#006600; font-weight:bold;">&#91;</span>^\W_<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">-</span>.<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span>^\W_<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">+</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">*</span>\.<span style="color:#006600; font-weight:bold;">&#91;</span>a<span style="color:#006600; font-weight:bold;">-</span>z<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006666;">2</span>,<span style="color:#006666;">6</span><span style="color:#006600; font-weight:bold;">&#125;</span>\.? <span style="color:#006600; font-weight:bold;">|</span>  <span style="color:#008000; font-style:italic;"># domain (including Punycode/IDN)...</span>
        <span style="color:#008000; font-style:italic;">#{IPv4_PART}(\.#{IPv4_PART}){3} )                        # or IPv4</span>
    <span style="color:#006600; font-weight:bold;">&#40;</span>:\d<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006666;">1</span>,<span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>?                                                  <span style="color:#008000; font-style:italic;"># optional port</span>
    <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">/</span>?<span style="color:#006600; font-weight:bold;">&#93;</span>\S<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span>?                                                   <span style="color:#008000; font-style:italic;"># optional /whatever or ?whatever</span>
    \Z
  <span style="color:#006600; font-weight:bold;">&#125;</span>iux
&nbsp;
  DEFAULT_MESSAGE     = <span style="color:#996600;">'does not appear to be a valid URL'</span>
  DEFAULT_MESSAGE_URL = <span style="color:#996600;">'does not appear to be valid'</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> validates_url_format_of<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">*</span>attr_names<span style="color:#006600; font-weight:bold;">&#41;</span>
    options = <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:allow_nil</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>,
                <span style="color:#ff3333; font-weight:bold;">:allow_blank</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>,
                <span style="color:#ff3333; font-weight:bold;">:with</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> REGEXP <span style="color:#006600; font-weight:bold;">&#125;</span>
    options = options.<span style="color:#9900CC;">merge</span><span style="color:#006600; font-weight:bold;">&#40;</span>attr_names.<span style="color:#9900CC;">pop</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> attr_names.<span style="color:#9900CC;">last</span>.<span style="color:#9900CC;">is_a</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">Hash</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    attr_names.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>attr_name<span style="color:#006600; font-weight:bold;">|</span>
      message = attr_name.<span style="color:#9900CC;">to_s</span>.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span>_<span style="color:#006600; font-weight:bold;">|</span>\b<span style="color:#006600; font-weight:bold;">&#41;</span>URL<span style="color:#006600; font-weight:bold;">&#40;</span>_<span style="color:#006600; font-weight:bold;">|</span>\b<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span>i<span style="color:#006600; font-weight:bold;">&#41;</span> ? DEFAULT_MESSAGE_URL : DEFAULT_MESSAGE
      validates_format_of<span style="color:#006600; font-weight:bold;">&#40;</span>attr_name, <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:message</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> message <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">merge</span><span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Then my model extends that module:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Location
  <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">Mongoid::Document</span>
  <span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">Mongoid::Timestamps</span>
  extend ValidatesUrlFormatOf
&nbsp;
  validates_url_format_of <span style="color:#ff3333; font-weight:bold;">:url</span>, <span style="color:#ff3333; font-weight:bold;">:allow_blank</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
...</pre></div></div>

<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=pa14yVfQc4c:QlJhiUdFn18:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=pa14yVfQc4c:QlJhiUdFn18:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?i=pa14yVfQc4c:QlJhiUdFn18:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=pa14yVfQc4c:QlJhiUdFn18:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?i=pa14yVfQc4c:QlJhiUdFn18:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/TristanMediaBlog/~4/pa14yVfQc4c" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.tristanmedia.com/2010/07/validating-urls-for-non-activerecord-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.tristanmedia.com/2010/07/validating-urls-for-non-activerecord-objects/</feedburner:origLink></item>
		<item>
		<title>Testing HTTP basic authentication with RSpec 2</title>
		<link>http://feedproxy.google.com/~r/TristanMediaBlog/~3/urpTxGTAWns/</link>
		<comments>http://blog.tristanmedia.com/2010/07/testing-http-basic-authentication-with-rspec-2/#comments</comments>
		<pubDate>Wed, 07 Jul 2010 02:00:50 +0000</pubDate>
		<dc:creator>Barry</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[rspec]]></category>

		<guid isPermaLink="false">http://blog.tristanmedia.com/?p=97</guid>
		<description><![CDATA[Here's how I test my admin controllers that use HTTP basic authentication using RSpec 2: before&#40;:each&#41; do user = 'test' pw = 'test_pw' request.env&#91;'HTTP_AUTHORIZATION'&#93; = ActionController::HttpAuthentication::Basic.encode_credentials&#40;user,pw&#41; end Actually, that's how I did it when I first tested things, but I've since put it in its own module under spec/support/auth_helper: module AuthHelper # do admin login [...]]]></description>
			<content:encoded><![CDATA[<p>Here's how I test my admin controllers that use HTTP basic authentication using RSpec 2:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">before<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:each</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    user = <span style="color:#996600;">'test'</span>
    pw = <span style="color:#996600;">'test_pw'</span>
    request.<span style="color:#9900CC;">env</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'HTTP_AUTHORIZATION'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#6666ff; font-weight:bold;">ActionController::HttpAuthentication::Basic</span>.<span style="color:#9900CC;">encode_credentials</span><span style="color:#006600; font-weight:bold;">&#40;</span>user,pw<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Actually, that's how I did it when I first tested things, but I've since put it in its own module under spec/support/auth_helper:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> AuthHelper
  <span style="color:#008000; font-style:italic;"># do admin login</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> admin_login
    user = <span style="color:#996600;">'test'</span>
    pw = <span style="color:#996600;">'test_pw'</span>
    request.<span style="color:#9900CC;">env</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'HTTP_AUTHORIZATION'</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#6666ff; font-weight:bold;">ActionController::HttpAuthentication::Basic</span>.<span style="color:#9900CC;">encode_credentials</span><span style="color:#006600; font-weight:bold;">&#40;</span>user,pw<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>  
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>and now my controller spec looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">describe <span style="color:#6666ff; font-weight:bold;">Admin::LocationsController</span> <span style="color:#9966CC; font-weight:bold;">do</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">include</span> AuthHelper
&nbsp;
  before<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:each</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    admin_login
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  describe <span style="color:#996600;">&quot;GET index&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    it <span style="color:#996600;">&quot;assigns all locations as @locations&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      loc = Factory.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:location</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      get <span style="color:#ff3333; font-weight:bold;">:index</span>
      assigns<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:locations</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">should</span> eq<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>loc<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  describe <span style="color:#996600;">&quot;GET show&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    it <span style="color:#996600;">&quot;assigns the requested location as @location&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      loc = Factory.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:location</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      get <span style="color:#ff3333; font-weight:bold;">:show</span>, <span style="color:#ff3333; font-weight:bold;">:id</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> loc.<span style="color:#9900CC;">id</span>
      assigns<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:location</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">should</span> === loc
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>  
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>That "Factory" line comes from my use of <a href="http://github.com/thoughtbot/factory_girl">factory_girl</a> rather than fixtures.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=urpTxGTAWns:9NhjA5Fst9M:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=urpTxGTAWns:9NhjA5Fst9M:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?i=urpTxGTAWns:9NhjA5Fst9M:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=urpTxGTAWns:9NhjA5Fst9M:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?i=urpTxGTAWns:9NhjA5Fst9M:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/TristanMediaBlog/~4/urpTxGTAWns" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.tristanmedia.com/2010/07/testing-http-basic-authentication-with-rspec-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.tristanmedia.com/2010/07/testing-http-basic-authentication-with-rspec-2/</feedburner:origLink></item>
		<item>
		<title>Rails 3, RSpec, Mongoid and Database Cleaner</title>
		<link>http://feedproxy.google.com/~r/TristanMediaBlog/~3/YoLPavwi3y4/</link>
		<comments>http://blog.tristanmedia.com/2010/07/rails-3-rspec-and-database-cleaner/#comments</comments>
		<pubDate>Mon, 05 Jul 2010 21:59:34 +0000</pubDate>
		<dc:creator>Barry</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[mongoid]]></category>
		<category><![CDATA[rspec]]></category>

		<guid isPermaLink="false">http://blog.tristanmedia.com/?p=88</guid>
		<description><![CDATA[After wrestling with various combinations of cleaning out my database between tests, this is what I'm using on a new Rails 3 application that uses Mongoid, RSpec 2, and Database Cleaner. I have one table (neighborhoods) which is populated using rake db:seed, so I'm excluding that from the cleanup. Put this into your spec/spec_helper.rb: require [...]]]></description>
			<content:encoded><![CDATA[<p>After wrestling with various combinations of cleaning out my database between tests, this is what I'm using on a new Rails 3 application that uses <a href="http://mongoid.org/">Mongoid</a>, <a href="http://github.com/rspec/rspec-rails">RSpec 2</a>, and <a href="http://github.com/bmabey/database_cleaner">Database Cleaner</a>.  I have one table (neighborhoods) which is populated using rake db:seed, so I'm excluding that from the cleanup.</p>
<p>Put this into your spec/spec_helper.rb:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'database_cleaner'</span>
&nbsp;
RSpec.<span style="color:#9900CC;">configure</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>config<span style="color:#006600; font-weight:bold;">|</span>
  config.<span style="color:#9900CC;">mock_with</span> <span style="color:#ff3333; font-weight:bold;">:rspec</span>
&nbsp;
  config.<span style="color:#9900CC;">before</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:each</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    DatabaseCleaner.<span style="color:#9900CC;">orm</span> = <span style="color:#996600;">&quot;mongoid&quot;</span> 
    DatabaseCleaner.<span style="color:#9900CC;">strategy</span> = <span style="color:#ff3333; font-weight:bold;">:truncation</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:except <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#91;</span> neighborhoods <span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
    DatabaseCleaner.<span style="color:#9900CC;">clean</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p><strong>UPDATE:</strong> This isn't working for me now.  Apparently the <code>config.before(:each)</code> part isn't being called in the versions of rspec (2.0.0.beta.21), cucumber (0.8.5), and cucumber-rails (0.3.2) that I'm using now.  I'm now using the approach by Kevin Faustino <a href="http://adventuresincoding.com/2010/07/how-to-configure-cucumber-and-rspec-to-work-with-mongoid/">here</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=YoLPavwi3y4:XCiXJKz6Sho:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=YoLPavwi3y4:XCiXJKz6Sho:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?i=YoLPavwi3y4:XCiXJKz6Sho:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=YoLPavwi3y4:XCiXJKz6Sho:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?i=YoLPavwi3y4:XCiXJKz6Sho:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/TristanMediaBlog/~4/YoLPavwi3y4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.tristanmedia.com/2010/07/rails-3-rspec-and-database-cleaner/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://blog.tristanmedia.com/2010/07/rails-3-rspec-and-database-cleaner/</feedburner:origLink></item>
		<item>
		<title>MacPorts annoyance with PHP and MySQL</title>
		<link>http://feedproxy.google.com/~r/TristanMediaBlog/~3/Z0RcbWkJfjE/</link>
		<comments>http://blog.tristanmedia.com/2009/10/macports-annoyance-with-php-and-mysql/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 17:36:25 +0000</pubDate>
		<dc:creator>Barry</dc:creator>
				<category><![CDATA[Web Dev]]></category>
		<category><![CDATA[macports]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://blog.tristanmedia.com/?p=86</guid>
		<description><![CDATA[I'm doing some local WordPress development, so I set up Apache, PHP, and MySQL using MacPorts. Apparently, the default setup does not set the location of the MySQL socket for you, so I copied /opt/local/etc/php5/php.ini-development to /opt/local/etc/php5/php.ini and changed these lines: pdo_mysql.default_socket=/opt/local/var/run/mysql5/mysqld.sock mysql.default_socket =/opt/local/var/run/mysql5/mysqld.sock mysqli.default_socket =/opt/local/var/run/mysql5/mysqld.sock]]></description>
			<content:encoded><![CDATA[<p>I'm doing some local WordPress development, so I set up Apache, PHP, and MySQL using <a href="http://www.macports.org/">MacPorts</a>.  Apparently, the default setup does not set the location of the MySQL socket for you, so I copied /opt/local/etc/php5/php.ini-development to /opt/local/etc/php5/php.ini and changed these lines:</p>
<pre>
pdo_mysql.default_socket=/opt/local/var/run/mysql5/mysqld.sock
mysql.default_socket =/opt/local/var/run/mysql5/mysqld.sock
mysqli.default_socket =/opt/local/var/run/mysql5/mysqld.sock
</pre>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=Z0RcbWkJfjE:R_VqCd7zT8c:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=Z0RcbWkJfjE:R_VqCd7zT8c:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?i=Z0RcbWkJfjE:R_VqCd7zT8c:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=Z0RcbWkJfjE:R_VqCd7zT8c:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?i=Z0RcbWkJfjE:R_VqCd7zT8c:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/TristanMediaBlog/~4/Z0RcbWkJfjE" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.tristanmedia.com/2009/10/macports-annoyance-with-php-and-mysql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.tristanmedia.com/2009/10/macports-annoyance-with-php-and-mysql/</feedburner:origLink></item>
		<item>
		<title>Quick fix for moving to Vlad the Deployer 2.0.0 with git</title>
		<link>http://feedproxy.google.com/~r/TristanMediaBlog/~3/ONnuVbReb8M/</link>
		<comments>http://blog.tristanmedia.com/2009/09/2-quick-fixes-for-moving-to-vlad-the-deployer-2-0-0/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 19:43:57 +0000</pubDate>
		<dc:creator>Barry</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[vlad]]></category>

		<guid isPermaLink="false">http://blog.tristanmedia.com/?p=76</guid>
		<description><![CDATA[I just upgraded my dev machine to version 2.0.0 of Vlad the Deployer. I got one unexpected error -- "Please specify the deploy path via the :deploy_to variable" -- but here is how I fixed it: git support is now a separate gem, so remember to run sudo gem install vlad-git I also had some [...]]]></description>
			<content:encoded><![CDATA[<p>I just upgraded my dev machine to version 2.0.0 of <a href="http://rubyhitsquad.com/Vlad_the_Deployer.html">Vlad the Deployer</a>. I got one unexpected error -- "Please specify the deploy path via the :deploy_to variable" -- but here is how I fixed it:</p>
<p>git support is now a separate gem, so remember to run</p>
<pre>
sudo gem install vlad-git
</pre>
<p>I also had some problems when version 1.4.0 was also on my machine, so I uninstalled that one with:</p>
<pre>
sudo gem uninstall vlad -v "1.4.0"
</pre>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=ONnuVbReb8M:xupxkVClblA:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=ONnuVbReb8M:xupxkVClblA:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?i=ONnuVbReb8M:xupxkVClblA:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=ONnuVbReb8M:xupxkVClblA:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?i=ONnuVbReb8M:xupxkVClblA:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/TristanMediaBlog/~4/ONnuVbReb8M" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.tristanmedia.com/2009/09/2-quick-fixes-for-moving-to-vlad-the-deployer-2-0-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.tristanmedia.com/2009/09/2-quick-fixes-for-moving-to-vlad-the-deployer-2-0-0/</feedburner:origLink></item>
		<item>
		<title>Using Amazon’s CloudFront with Rails &amp; Paperclip</title>
		<link>http://feedproxy.google.com/~r/TristanMediaBlog/~3/HO-E2IgY1xM/</link>
		<comments>http://blog.tristanmedia.com/2009/09/using-amazons-cloudfront-with-rails-and-paperclip/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 00:01:57 +0000</pubDate>
		<dc:creator>Barry</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[cloudfront]]></category>
		<category><![CDATA[paperclip]]></category>
		<category><![CDATA[s3]]></category>

		<guid isPermaLink="false">http://blog.tristanmedia.com/?p=56</guid>
		<description><![CDATA[It took me a bit of experimentation, and I never found an example in a single place that showed how to set it up exactly how I wanted, so here is my code in my model for storing images used by the ArtCat calendar on Amazon S3. I am using Paperclip version 2.3.1. First you [...]]]></description>
			<content:encoded><![CDATA[<p>It took me a bit of experimentation, and I never found an example in a single place that showed how to set it up exactly how I wanted, so here is my code in my model for storing images used by the <a href="http://www.artcat.com/">ArtCat</a> calendar on <a href="http://aws.amazon.com/s3/">Amazon S3</a>.  I am using <a href="http://github.com/thoughtbot/paperclip/tree/master">Paperclip</a> version 2.3.1.</p>
<p>First you will need to set up the distribution in Amazon for your given bucket, so that you have a URL to use for the :s3_host_alist value. I also set up a <a href="http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/index.html?CNAMEs.html">CNAME</a> so that I can use a nice url like calcdn.artcat.com.</p>
<p>Note that I don't want to store any images other than my resized ones, so my :default_style is set to :original.  Some of these values are actually constants in my config files, but I've replaced those here to make it more clear.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">    has_attached_file <span style="color:#ff3333; font-weight:bold;">:image</span>,
      <span style="color:#ff3333; font-weight:bold;">:storage</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'s3'</span>,
      <span style="color:#ff3333; font-weight:bold;">:s3_credentials</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;#{RAILS_ROOT}/config/s3_credentials.yml&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:bucket</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'artcal-production'</span>,
      <span style="color:#ff3333; font-weight:bold;">:s3_host_alias</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'calcdn.artcat.com'</span>,
      <span style="color:#ff3333; font-weight:bold;">:url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">':s3_alias_url'</span>,
      <span style="color:#ff3333; font-weight:bold;">:path</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;images/:class/:id_:timestamp.:style.:extension&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:styles</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:thumb</span>  <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'60x60#'</span>, <span style="color:#ff3333; font-weight:bold;">:medium</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'270x200#'</span>, <span style="color:#ff3333; font-weight:bold;">:original</span>  <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'600x600&gt;'</span> <span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#ff3333; font-weight:bold;">:default_style</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:original</span>,
      <span style="color:#ff3333; font-weight:bold;">:default_url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'http://cdn1.artcat.com/pixel.gif'</span>,
      <span style="color:#ff3333; font-weight:bold;">:s3_headers</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#996600;">'Expires'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> 1.<span style="color:#9900CC;">year</span>.<span style="color:#9900CC;">from_now</span>.<span style="color:#9900CC;">httpdate</span> <span style="color:#006600; font-weight:bold;">&#125;</span>,
      <span style="color:#ff3333; font-weight:bold;">:convert_options</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:all</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'-strip -trim'</span> <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>Note that you do NOT have to set the ActionController::Base.asset_host to your CNAME for images.  Paperclip just handles it as expected for these images.</p>
<p>You'll notice an interpolation in the :path that is not standard.  Thanks to this Intridea Company Blog <a href="http://www.intridea.com/2009/7/8/amazon-cloudfront-preventing-stale-assets?blog=company">post</a> I learned that I will need to change my image names when they are updated.  CloudFront will not update my image due to that Expires header I set above for a whole year, which is not what we want to happen.  I solved this by including the timestamp based on the updated_at value for the image.  Based on that Intridea post, this is the code I added to config/initalizers/paperclib.rb.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">Paperclip.<span style="color:#9900CC;">interpolates</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:timestamp</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>attachment, style<span style="color:#006600; font-weight:bold;">|</span>
  attachment.<span style="color:#9900CC;">instance_read</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:updated_at</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">to_i</span>  
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>At first I was storing the images on the file system and serving them via Apache.  Moving them to CloudFront improved my page load times by at least 50%, and means that I don't have to run as powerful as server to handle a lot of traffic on this image-heavy site as I might otherwise need.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=HO-E2IgY1xM:x7IV4obLu4Q:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=HO-E2IgY1xM:x7IV4obLu4Q:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?i=HO-E2IgY1xM:x7IV4obLu4Q:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=HO-E2IgY1xM:x7IV4obLu4Q:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?i=HO-E2IgY1xM:x7IV4obLu4Q:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/TristanMediaBlog/~4/HO-E2IgY1xM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.tristanmedia.com/2009/09/using-amazons-cloudfront-with-rails-and-paperclip/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		<feedburner:origLink>http://blog.tristanmedia.com/2009/09/using-amazons-cloudfront-with-rails-and-paperclip/</feedburner:origLink></item>
		<item>
		<title>Don’t buy a Samsung monitor &amp; Tekserve rocks</title>
		<link>http://feedproxy.google.com/~r/TristanMediaBlog/~3/zRYxJrWWORY/</link>
		<comments>http://blog.tristanmedia.com/2009/04/dont-buy-a-samsung-monitor-tekserve-rocks/#comments</comments>
		<pubDate>Fri, 10 Apr 2009 17:55:53 +0000</pubDate>
		<dc:creator>Barry</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[samsung]]></category>
		<category><![CDATA[tekserve]]></category>

		<guid isPermaLink="false">http://blog2.tristanmedia.com/2009/04/dont-buy-a-samsung-monitor-tekserve-rocks/</guid>
		<description><![CDATA[The perils of buying a Samsung monitor are now evident. Feburary 6: bought a Samsung 2043BWX monitor from Tekserve Last week of February: monitor dies -- no image whatsoever March 10: trying to meet deadlines, finally have time to submit an exchange request to Samsung, giving a credit card so they can mail a replacement [...]]]></description>
			<content:encoded><![CDATA[<p>The perils of buying a Samsung monitor are now evident.</p>
<ul>
<li>Feburary 6: bought a Samsung 2043BWX monitor from <a href="http://tekserve.com/">Tekserve</a></li>
<li>Last week of February: monitor dies -- no image whatsoever</li>
<li>March 10: trying to meet deadlines, finally have time to submit an exchange request to Samsung, giving a credit card so they can mail a replacement</li>
<li>Next 4 weeks: status on Samsung site does change.  I call weekly, am told that it will ship out after 15 business days, and I should be patient.</li>
<li>April 3: Told no monitor is available for an exchange, and I will be called back with options such as other monitors they could send.</li>
<li>April 6: I call back after getting no call from Samsung service, am told the person who could authorize shipping me a different model has been out and they will call me the next day.</li>
<li>April 8: I call again, and I'm told that shipping a replacement is impossible.  I will need to ship them my monitor and wait 5+ business days for it to be repaired.</li>
</ul>
<p>So, basically 4+ weeks of phone calls, and empty promises to call me back, to learn they&#8217;re not going to replace a monitor that I could have shipped in had I been told to do so on March 10.  Since I bill hourly for my consulting work, I would have been better off just throwing away the monitor based on the time this has taken.</p>
<p><strong>Update:</strong> I sent an email to customer service at <a href="http://tekserve.com/">Tekserve</a> with a link to this blog post asking for help, and one of the owners(!) wrote back to say they&#8217;ll replace it right away.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=zRYxJrWWORY:eQdYBmduxiI:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=zRYxJrWWORY:eQdYBmduxiI:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?i=zRYxJrWWORY:eQdYBmduxiI:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=zRYxJrWWORY:eQdYBmduxiI:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?i=zRYxJrWWORY:eQdYBmduxiI:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/TristanMediaBlog/~4/zRYxJrWWORY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.tristanmedia.com/2009/04/dont-buy-a-samsung-monitor-tekserve-rocks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://blog.tristanmedia.com/2009/04/dont-buy-a-samsung-monitor-tekserve-rocks/</feedburner:origLink></item>
		<item>
		<title>Notes on mysql replication in Ubuntu hardy</title>
		<link>http://feedproxy.google.com/~r/TristanMediaBlog/~3/cpZcJ6g-eBc/</link>
		<comments>http://blog.tristanmedia.com/2008/09/notes-on-mysql-replication-in-ubuntu-hardy/#comments</comments>
		<pubDate>Mon, 08 Sep 2008 23:53:30 +0000</pubDate>
		<dc:creator>Barry</dc:creator>
				<category><![CDATA[Web Dev]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[replication]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog2.tristanmedia.com/2008/09/notes-on-mysql-replication-in-ubuntu-hardy/</guid>
		<description><![CDATA[I'm moving some sites currently on shared hosting to Slicehost: and setting up MySQL replication so I can run backups from the slave and push them to Amazon S3 storage on a regular basis using s3sync. This ONLamp article gives a handy step-by-step guide. One thing that got me though, was that I had set [...]]]></description>
			<content:encoded><![CDATA[<p>I'm moving some sites currently on shared hosting to <a href="https://manage.slicehost.com/customers/new?referrer=a8284dea9d9b5be8497b288872559c4d">Slicehost</a>: and setting up MySQL replication so I can run backups from the slave and push them to Amazon S3 storage on a regular basis using <a href="http://s3sync.net/wiki">s3sync</a>.</p>
<p>This ONLamp <a href="http://www.onlamp.com/pub/a/onlamp/2005/06/16/MySQLian.html">article</a> gives a handy step-by-step guide.  One thing that got me though, was that I had set up iptables to firewall my servers, and I needed to get my master and slave able to talk to each other without opening up MySQL to the whole world.  My solution was to email Slicehost and request private IP addresses for both servers.  </p>
<p>I then changed this line in /etc/mysql/my.cnf from</p>
<pre>
bq. bind-address          = 127.0.0.1
</pre>
<p>to</p>
<pre>
bq. bind-address          = my private IP address
</pre>
<p>on each server.  Then I added this to my iptables rules on both:</p>
<pre>
-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
</pre>
<p>I reloaded the iptables rules with iptables-restore, and then checked with telnet from another server outside of those 2 to make sure I couldn't reach port 3306.</p>
<p>The next problem I encountered was an error like this when I restarted the slave after copying over the data in the master to get started:</p>
<pre>
error: 'Access denied for user 'debian-sys-maint'@'localhost' (using password: YES)'
</pre>
<p>A search of the Ubuntu forums gave me this <a href="http://ubuntuforums.org/archive/index.php/t-112505.html">thread</a> which explained that debian uses a file called /etc/mysql/debian.cnf for that user password, and when I moved things over from the master DB, I changed the password for that user.  The solution is to change to password in that file on the slave to the same password found on the master.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=cpZcJ6g-eBc:yIvHQEy_4dk:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=cpZcJ6g-eBc:yIvHQEy_4dk:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?i=cpZcJ6g-eBc:yIvHQEy_4dk:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=cpZcJ6g-eBc:yIvHQEy_4dk:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?i=cpZcJ6g-eBc:yIvHQEy_4dk:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/TristanMediaBlog/~4/cpZcJ6g-eBc" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.tristanmedia.com/2008/09/notes-on-mysql-replication-in-ubuntu-hardy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.tristanmedia.com/2008/09/notes-on-mysql-replication-in-ubuntu-hardy/</feedburner:origLink></item>
		<item>
		<title>Culture Pundits official launch</title>
		<link>http://feedproxy.google.com/~r/TristanMediaBlog/~3/Cvd-VlJp0b8/</link>
		<comments>http://blog.tristanmedia.com/2008/09/culture-pundits-official-launch/#comments</comments>
		<pubDate>Mon, 08 Sep 2008 17:58:44 +0000</pubDate>
		<dc:creator>Barry</dc:creator>
				<category><![CDATA[Web Biz]]></category>
		<category><![CDATA[ad network]]></category>
		<category><![CDATA[culture pundits]]></category>

		<guid isPermaLink="false">http://blog2.tristanmedia.com/2008/09/culture-pundits-official-launch/</guid>
		<description><![CDATA[We first set up the Culture Pundits website in August 2007, but now that we have reached a critical mass of websites, traffic, and advertisers, we have announced the official launch. Check out the press release.]]></description>
			<content:encoded><![CDATA[<p><img src="http://blog.tristanmedia.com/wp-content/uploads/2008/09/cp-logo.gif" alt="cp-logo" title="cp-logo" width="218" height="47" class="alignnone size-full wp-image-71" style="padding: 10px" /></p>
<p>We first set up the <a href="http://www.culturepundits.com/">Culture Pundits</a> website in August 2007, but now that we have reached a critical mass of websites, traffic, and advertisers, we have announced the official launch.</p>
<p>Check out the <a href="http://archive.culturepundits.com/pr/official_launch_20080908">press release</a>.</p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=Cvd-VlJp0b8:8C8PxHx--xw:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=Cvd-VlJp0b8:8C8PxHx--xw:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?i=Cvd-VlJp0b8:8C8PxHx--xw:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=Cvd-VlJp0b8:8C8PxHx--xw:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?i=Cvd-VlJp0b8:8C8PxHx--xw:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/TristanMediaBlog/~4/Cvd-VlJp0b8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.tristanmedia.com/2008/09/culture-pundits-official-launch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.tristanmedia.com/2008/09/culture-pundits-official-launch/</feedburner:origLink></item>
		<item>
		<title>Custom Drupal Modules – creating filters for Views</title>
		<link>http://feedproxy.google.com/~r/TristanMediaBlog/~3/HJE98EwVdKk/</link>
		<comments>http://blog.tristanmedia.com/2008/07/custom-drupal-modules-creating-filters-for-views/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 20:40:45 +0000</pubDate>
		<dc:creator>Barry</dc:creator>
				<category><![CDATA[Drupal5]]></category>
		<category><![CDATA[drupal modules]]></category>
		<category><![CDATA[drupal views]]></category>

		<guid isPermaLink="false">http://blog2.tristanmedia.com/2008/07/custom-drupal-modules-creating-filters-for-views/</guid>
		<description><![CDATA[Continuing my exploration of custom modules and views, here is my code for allowing view builders to filter entries based on a status field, say "special offers", that is represented in our module's database table by an integer with 1 for true or 0 for false. Add this key to your array entry for a [...]]]></description>
			<content:encoded><![CDATA[<p>Continuing my exploration of custom modules and views, here is my code for allowing view builders to filter entries based on a status field, say "special offers", that is represented in our module's database table by an integer with 1 for true or 0 for false.</p>
<p>Add this key to your array entry for a table, at the same level as the "join" key.  See my <a href="/2008/06/custom-drupal-modules-and-views/">earlier post</a> for how the rest of the array works.</p>
<p></p>
<p>In this case, the database column is called "is_special_offer".  The keys you should supply are discussed <a href="http://drupal.org/node/99794">here</a> in the Views handbook.</p>
<div class="wp_syntax">
<div class="code">
<pre class="php" style="font-family:monospace;"><span style="color: #0000ff;">&#8216;filters&#8217;</span> <span style="color: #339933;">=></span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
  <span style="color: #0000ff;">&#8216;is_special_offer&#8217;</span> <span style="color: #339933;">=></span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
    <span style="color: #0000ff;">&#8216;name&#8217;</span> <span style="color: #339933;">=></span> <span style="color: #0000ff;">&#8216;Product: Is Special Offer&#8217;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">&#8216;operator&#8217;</span> <span style="color: #339933;">=></span> <span style="color: #0000ff;">&#8216;views_handler_operator_eqneq&#8217;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">&#8216;list&#8217;</span> <span style="color: #339933;">=></span> <span style="color: #0000ff;">&#8216;views_handler_operator_yesno&#8217;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">&#8216;list-type&#8217;</span> <span style="color: #339933;">=></span> <span style="color: #0000ff;">&#8216;select&#8217;</span><span style="color: #339933;">,</span>
    <span style="color: #0000ff;">&#8216;help&#8217;</span> <span style="color: #339933;">=></span> t<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&#8216;Show only Special Offers&#8217;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span></pre>
</div>
</div>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=HJE98EwVdKk:9yNzyQ6RXP4:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=HJE98EwVdKk:9yNzyQ6RXP4:F7zBnMyn0Lo"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?i=HJE98EwVdKk:9yNzyQ6RXP4:F7zBnMyn0Lo" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/TristanMediaBlog?a=HJE98EwVdKk:9yNzyQ6RXP4:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/TristanMediaBlog?i=HJE98EwVdKk:9yNzyQ6RXP4:V_sGLiPBpWU" border="0"></img></a>
</div><img src="http://feeds.feedburner.com/~r/TristanMediaBlog/~4/HJE98EwVdKk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://blog.tristanmedia.com/2008/07/custom-drupal-modules-creating-filters-for-views/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://blog.tristanmedia.com/2008/07/custom-drupal-modules-creating-filters-for-views/</feedburner:origLink></item>
	</channel>
</rss>

