<?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>Jtanium's Notebook &#187; jtanium</title>
	<atom:link href="http://www.jtanium.com/author/jtanium/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jtanium.com</link>
	<description>I jot things down, in hopes of finding them later...</description>
	<lastBuildDate>Wed, 21 Dec 2011 23:21:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Bash Prompt for RVM and Git</title>
		<link>http://www.jtanium.com/2011/12/21/bash-prompt-for-rvm-and-git/</link>
		<comments>http://www.jtanium.com/2011/12/21/bash-prompt-for-rvm-and-git/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 23:21:13 +0000</pubDate>
		<dc:creator>jtanium</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[rvm]]></category>

		<guid isPermaLink="false">http://www.jtanium.com/?p=236</guid>
		<description><![CDATA[I&#8217;ve seen a lot of examples where people have a cool Bash prompt showing their Ruby version, RVM gemset, and/or their Git branch. What I couldn&#8217;t find is a complete example that helped me understand what was going on and worked properly on OS X. Here&#8217;s what I did, and maybe you&#8217;ll find it useful. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve seen a lot of examples where people have a cool Bash prompt showing their Ruby version, RVM gemset, and/or their Git branch.</p>
<p>What I couldn&#8217;t find is a complete example that helped me understand what was going on and worked properly on OS X.</p>
<p>Here&#8217;s what I did, and maybe you&#8217;ll find it useful.</p>
<pre>
ESC="\033" # This is the escape sequence
NO_COLOR="$ESC[0m"
IRED="$ESC[1;31m" # ANSI color code for intense/bold red
IGRN="$ESC[1;32m" # ANSI color code for intense/bold green

# From http://railstips.org/blog/archives/2009/02/02/bedazzle-your-bash-prompt-with-git-info/
# I had to change 'git-symbolic-ref' to 'git symbolic-ref'
function parse_git_branch {
  ref=$(git symbolic-ref HEAD 2> /dev/null) || return
  echo " ["${ref#refs/heads/}"]" # I wanted my branch wrapped in [], use () or <> or whatever
}

# from http://ariejan.net/2010/04/25/ruby-version-and-gemset-in-your-bash-prompt-yes-sir
function rvm_version {
  local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}')
  [ "$gemset" != "" ] &#038;&#038; gemset="@$gemset"
  local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}')
  [ "$version" != "" ] &#038;&#038; version="$version"
  local full="$version$gemset"
  [ "$full" != "" ] &#038;&#038; echo "${full}:" # the colon at the end is a delimiter, you could use a space instead
}

#PS1="\h:\W \u\$" # For reference, here's the default OS X prompt
#export PS1="\$(rvm_version)\W \$(parse_git_branch)\$ " # Without the colors

# I had to put the \[ and \] down here, as opposed to $IRED, to avoid wrapping funkiness.
export PS1="\[$IRED\]\$(rvm_version)\[$NO_COLOR\]\W\[$IGRN\]\$(parse_git_branch)\[$NO_COLOR\] \$ "
</pre>
<p>I encountered all kinds of weirdness getting the colors to work. The problems all centered around getting the <code>\[</code> and <code>\]</code> correct.  If you&#8217;re having problems where the wrapping is wrong, or arrow keys or the backspace causes your prompt to disappear, check your <code>\[\]</code>&#8216;s. The rule of thumb is the characters you&#8217;re escaping should be wrapped in them.  Keep in mind, the color codes don&#8217;t seem to include a <code>]</code> at the end.</p>
<p>I got my color codes from <a href="http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x329.html" title="Bash Prompt HOWTO: Chapter 6. ANSI Escape Sequences: Colours and Cursor Movement" target="_blank">here</a>. At the bottom of that page is a dandy script which prints out all the colors and backgrounds making it easy to find a good color combination for your terminal.</p>
<p>References:<br />
<a href="http://ariejan.net/2010/04/25/ruby-version-and-gemset-in-your-bash-prompt-yes-sir" target="_blank">Ruby version and gemset in your Bash prompt? Yes sir!</a><br />
<a href="http://railstips.org/blog/archives/2009/02/02/bedazzle-your-bash-prompt-with-git-info/" target="_blank">Bedazzle Your Bash Prompt with Git Info</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jtanium.com/2011/12/21/bash-prompt-for-rvm-and-git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Service-Oriented Design with Ruby and Rails</title>
		<link>http://www.jtanium.com/2010/11/29/service-oriented-design-with-ruby-and-rails/</link>
		<comments>http://www.jtanium.com/2010/11/29/service-oriented-design-with-ruby-and-rails/#comments</comments>
		<pubDate>Mon, 29 Nov 2010 21:08:35 +0000</pubDate>
		<dc:creator>jtanium</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://www.jtanium.com/?p=226</guid>
		<description><![CDATA[I got a copy of this book recently because I want to explore using web services more in some of my projects. If you are going to work through the examples, just be warned, they aren&#8217;t going to work out of the box. I don&#8217;t know who was supposed to be checking they work, but [...]]]></description>
			<content:encoded><![CDATA[<p>I got a copy of this book recently because I want to explore using web services more in some of my projects.</p>
<p>If you are going to work through the examples, just be warned, they aren&#8217;t going to work out of the box.  I don&#8217;t know who was supposed to be checking they work, but they dropped the ball.</p>
<p>This is where I&#8217;m going to keep track of all the things I had to change/tweak/massage to get it to work.</p>
<p><strong>Chapter 1: Implementing and Consuming Your First Service</strong></p>
<ul>
<li>You also need Rack-Test <code>gem install rack-test</code></li>
<li>The <code>Rackfile</code> and <code>spec/service_spec.rb</code> won&#8217;t work. I have created a <a href="https://gist.github.com/720605">gist</a> where you can view my comments about what I had to add.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.jtanium.com/2010/11/29/service-oriented-design-with-ruby-and-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache, WordPress, Passenger, and You</title>
		<link>http://www.jtanium.com/2010/11/06/apache-wordpress-passenger-and-you/</link>
		<comments>http://www.jtanium.com/2010/11/06/apache-wordpress-passenger-and-you/#comments</comments>
		<pubDate>Sat, 06 Nov 2010 21:28:45 +0000</pubDate>
		<dc:creator>jtanium</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://www.jtanium.com/?p=222</guid>
		<description><![CDATA[I was trying to get a web application running here along side WordPress, but, in essence, Apache wasn&#8217;t letting mod_rails handle the request. Several Google searches turned up precisely zero answers. After poking around I found the .htaccess file that WordPress so kindly generates for you: # BEGIN WordPress &#60;IfModule mod_rewrite.c&#62; RewriteEngine On RewriteBase / [...]]]></description>
			<content:encoded><![CDATA[<p>I was trying to get a web application running here along side WordPress, but, in essence, Apache wasn&#8217;t letting mod_rails handle the request.</p>
<p>Several Google searches turned up precisely zero answers.  After poking around I found the .htaccess file that WordPress so kindly generates for you:</p>
<pre># BEGIN WordPress
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
&lt;/IfModule&gt;

# END WordPress
</pre>
<p>What this little guy is doing is displaying a nice pretty 404 page, instead of a plain old ugly Apache page.  It does this by looking to see if there is a file or directory matching the file name in the request.</p>
<p>Obviously, there aren&#8217;t files and directories to correspond with your web app urls.  The solution is, quite simply, to tell Apache not to go looking for files and directories when the request needs to go to your web application.  So how do you that? Like this:</p>
<pre>RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/myrailsapp.*
RewriteRule . /index.php [L]
</pre>
<p>Voila!  Now Apache won&#8217;t try looking for any files or directories when the request begins with &#8220;myrailsapp.&#8221;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jtanium.com/2010/11/06/apache-wordpress-passenger-and-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OS X Server SUS Hack</title>
		<link>http://www.jtanium.com/2010/11/05/os-x-server-sus-hack/</link>
		<comments>http://www.jtanium.com/2010/11/05/os-x-server-sus-hack/#comments</comments>
		<pubDate>Fri, 05 Nov 2010 22:20:19 +0000</pubDate>
		<dc:creator>jtanium</dc:creator>
				<category><![CDATA[OS X]]></category>
		<category><![CDATA[Rant]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://www.jtanium.com/?p=219</guid>
		<description><![CDATA[I&#8217;ve been having a problem with the Software Update Server on OS X, it never generates the catalog files. As far as I can tell, the swupd_syncd process seems to get &#8220;stuck&#8221; and never generate the catalog file. Here&#8217;s how I &#8220;fixed&#8221; it. I added the following to root&#8217;s crontab: 17 3 * * * [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been having a problem with the Software Update Server on OS X, it never generates the catalog files.  As far as I can tell, the <code>swupd_syncd</code> process seems to get &#8220;stuck&#8221; and never generate the catalog file.</p>
<p>Here&#8217;s how I &#8220;fixed&#8221; it.  I added the following to root&#8217;s crontab:</p>
<pre>
17 3 * * * /bin/cat /var/db/swupd/html/content/catalogs/index.sucatalog.apple | /usr/bin/sed 's/swcdn.apple.com/10.0.5.100:8088/' > /var/db/swupd/html/content/catalogs/index.sucatalog
19 3 * * * /bin/cat /var/db/swupd/html/content/catalogs/index-leopard.merged-1.sucatalog.apple | /usr/bin/sed 's/swcdn.apple.com/10.0.5.100:8088/' > /var/db/swupd/html/content/catalogs/index-leopard.merged-1.sucatalog
23 3 * * * /bin/cat /var/db/swupd/html/content/catalogs/index-leopard-snowleopard.merged-1.sucatalog.apple | /usr/bin/sed 's/swcdn.apple.com/10.0.5.100:8088/' > /var/db/swupd/html/content/catalogs/index-leopard-snowleopard.merged-1.sucatalog
</pre>
<p>Keep in mind this is the crontab for the <code>root</code> user (I used <code>sudo crontab -e</code>), not the system crontab, which is normally located in <code>/etc/crontab</code>.  Speaking of which, where the hell did that go?</p>
<p>Seriously, Apple, WTF?  Why is it so friggin&#8217; hard to make a service that pulls a bunch of files off the web and generates an XML file? If I weren&#8217;t pressed for time, I&#8217;d replace <code>swupd_syncd</code> with a hundred lines of Ruby code.</p>
<p>When it comes to OS X Server, I&#8217;m aghast at how difficult it is to get the simplest things to work.  The &#8220;enterprisey&#8221; Apple stuff is awesome in theory, but horrible in practice.  It took days to get the OpenDirectory stuff to work properly.</p>
<p>Even still I have all kinds of problems.  For some reason OpenDirectory decides it&#8217;s just going to take a nap, and it will take three minutes (or more) for anyone on the network to do anything.  Imagine how fun it is trying to change tabs in Workgroup Manager and it takes three minutes between each mouse click.</p>
<p>Here&#8217;s another: periodically OpenDirectory will decide to disable a mobile user. For those of you who&#8217;ve never experienced this, when that happens, the client machine will disable the local user account.  And good luck getting that re-enabled (after you enable it in WGM).  You can run this command a bunch of times:</p>
<pre>
sudo pwpolicy -a LOCAL_ADMIN_SHORTNAME -n /Local/Default -u USER_SHORTNAME -enableuser
</pre>
<p>But it only works 25% of the time. The rest of the time you get messages about user not being disabled or not having a shadowhash. Sometimes if you just reset the user&#8217;s password that will re-enable the account.  Otherwise reboot it a whole bunch of times until it finally figures out the account is enabled in OpenDirectory.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jtanium.com/2010/11/05/os-x-server-sus-hack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Queue Wait Spikes with Passenger and NewRelic</title>
		<link>http://www.jtanium.com/2010/05/17/queue-wait-spikes-with-passenger-and-newrelic/</link>
		<comments>http://www.jtanium.com/2010/05/17/queue-wait-spikes-with-passenger-and-newrelic/#comments</comments>
		<pubDate>Mon, 17 May 2010 21:07:42 +0000</pubDate>
		<dc:creator>jtanium</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[newrelic]]></category>
		<category><![CDATA[passenger]]></category>

		<guid isPermaLink="false">http://www.jtanium.com/?p=206</guid>
		<description><![CDATA[So I&#8217;ve been struggling with &#8220;Queue Wait&#8221; spikes on NewRelic. I think I have pretty much determined that the spikes are caused by Passenger spinning up new threads to handle additional requests. Here&#8217;s what I did. First I restarted my app, and let it run for a bit, then I used &#8220;passenger-status&#8221; to see what [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve been struggling with &#8220;Queue Wait&#8221; spikes on NewRelic.  I think I have pretty much determined that the spikes are caused by Passenger spinning up new threads to handle additional requests.  Here&#8217;s what I did.</p>
<p>First I restarted my app, and let it run for a bit, then I used &#8220;passenger-status&#8221; to see what the threads were doing:</p>
<pre>
----------- General information -----------
max      = 30
count    = 3
active   = 0
inactive = 3
Waiting on global queue: 0

----------- Domains -----------
/srv/rails/myapp/current:
  PID: 9734    Sessions: 0    Processed: 48      Uptime: 18m 54s
  PID: 9704    Sessions: 0    Processed: 49      Uptime: 19m 5s
  PID: 9706    Sessions: 0    Processed: 57      Uptime: 19m 2s
</pre>
<p>I&#8217;d basically just run it again every few minutes to see what was happening, and then I got this:</p>
<pre>

----------- General information -----------
max      = 30
count    = 4
active   = 0
inactive = 4
Waiting on global queue: 0

----------- Domains -----------
/srv/rails/myapp/current:
  PID: 9822    Sessions: 0    Processed: 34      Uptime: 4m 57s
  PID: 9706    Sessions: 0    Processed: 103     Uptime: 26m 43s
  PID: 9704    Sessions: 0    Processed: 107     Uptime: 26m 46s
  PID: 9734    Sessions: 0    Processed: 75      Uptime: 26m 35s

Mon May 17 13:54:20 MDT 2010
</pre>
<p>(I actually started running <code>passenger-status; date</code> so I could have the time I ran the command).  The above tells us that at roughly 13:49 Passenger spun up another thread.  Refreshing NewRelic, I saw this:</p>
<p><a href="https://www.jtanium.com/wp-content/uploads/2010/05/newrelic-queue_wait.png"><img src="https://www.jtanium.com/wp-content/uploads/2010/05/newrelic-queue_wait.png" alt="" title="newrelic-queue_wait" width="664" height="306" class="alignnone size-full wp-image-207" /></a></p>
<p>I spent more time investigating, and it does seem that the queue wait spikes, roughly correspond to times that Passenger starts more threads.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jtanium.com/2010/05/17/queue-wait-spikes-with-passenger-and-newrelic/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Complex Associations in Factory Girl</title>
		<link>http://www.jtanium.com/2010/05/17/complex-associations-in-factory-girl/</link>
		<comments>http://www.jtanium.com/2010/05/17/complex-associations-in-factory-girl/#comments</comments>
		<pubDate>Mon, 17 May 2010 20:49:40 +0000</pubDate>
		<dc:creator>jtanium</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[associations]]></category>
		<category><![CDATA[factory_girl]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.jtanium.com/?p=202</guid>
		<description><![CDATA[I finally decided to bite the bullet and move the main Rails project I work on from FixtureReplacement to Factory Girl. Weighing in at 7404 lines of test code, this was a non-trivial task. If you peruse the Factory Girl docs, it mentions associations, but only how to handle a simple &#8220;belongs to&#8221; or maybe [...]]]></description>
			<content:encoded><![CDATA[<p>I finally decided to bite the bullet and move the main Rails project I work on from <a href="http://replacefixtures.rubyforge.org/">FixtureReplacement</a> to <a href="http://github.com/thoughtbot/factory_girl">Factory Girl</a>.  Weighing in at 7404 lines of test code, this was a non-trivial task.</p>
<p>If you peruse the Factory Girl docs, it mentions associations, but only how to handle a simple &#8220;belongs to&#8221; or maybe &#8220;has one&#8221; sort of association.  My <a href="http://www.google.com">good friend</a> led me to <a href="http://stackoverflow.com/questions/1506556/has-many-while-respecting-build-strategy-in-factory-girl">this thread</a> on StackOverflow.</p>
<p>Basically, the user fowlduck came up with the solution of having an &#8220;after_build&#8221; block.</p>
<p>My problem couldn&#8217;t be solved with a simple &#8220;has_many/belongs_to&#8221; association, because in this case I needed to ensure the invoice seller matched the producer of the product being invoiced.  Here was my solution:</p>
<pre>
Factory.define :invoice do |i|
  i.after_build do |invoice|
    invoice.buyer = Factory.create :consumer unless invoice.buyer
    next if invoice.seller
    invoice.line_items = [Factory.create(:line_item)]
    invoice.seller = invoice.line_items.first.product.producer
  end
end
</pre>
<p>So first, notice the &#8220;unless invoice.buyer&#8221; and &#8220;next if invoice.seller&#8221; these allow me to override these values in my tests.  You&#8217;re gonna wanna keep that in mind. Next, I create a LineItem, which automatically creates a product, which in turn, creates a producer.  After that I can just set the seller to be the producer of the product in the first line item.  Voila, product line_item producer matches invoice seller.</p>
<p>I&#8217;ve found this tremendously useful.  Here&#8217;s another example of how I&#8217;ve used it:</p>
<pre>
Factory.define :user do |a|
  name = Faker::Name.name
  a.real_name { name }
  a.username { Faker::Internet.user_name(name) }
  a.password 'secret-1'
  a.password_confirmation 'secret-1'
  a.email_address { Faker::Internet.email(name) }
  a.after_build do |login|
    next if login.valid?
    next unless login.errors.invalid?(:username)
    login.username = Faker::Internet.user_name(login.real_name)+String.random(4)
  end
end
</pre>
<p>I did this because, everyone once in a great while my tests would fail because the same username is used more than once.  But now, if this happens, I just tack on 4 random characters.  Since i did this, I haven&#8217;t had the test fail.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jtanium.com/2010/05/17/complex-associations-in-factory-girl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Capistrano + Fetcher/Daemonize</title>
		<link>http://www.jtanium.com/2010/03/12/capistrano-fetcher-daemonize/</link>
		<comments>http://www.jtanium.com/2010/03/12/capistrano-fetcher-daemonize/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 21:51:17 +0000</pubDate>
		<dc:creator>jtanium</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[fetcher]]></category>
		<category><![CDATA[nohup]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[task]]></category>

		<guid isPermaLink="false">http://www.jtanium.com/?p=200</guid>
		<description><![CDATA[So I&#8217;ve spent the afternoon slogging through this little problem. Something tells me I&#8217;m going to be referring to this post again and again. Are you using the fetcher plugin and Capistrano for deployment? Hey, me too! Apparently I&#8217;m the only one in the world who didn&#8217;t immediately know how to make them work together [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve spent the afternoon slogging through this little problem.  Something tells me I&#8217;m going to be referring to this post again and again.</p>
<p>Are you using the <a href="http://github.com/look/fetcher">fetcher plugin</a> and <a href="http://www.capify.org">Capistrano</a> for deployment? Hey, me too! Apparently I&#8217;m the only one in the world who didn&#8217;t immediately know how to make them work together though.</p>
<p>Here are my Capistrano tasks for starting/stopping/restarting my fetcher daemons:</p>
<pre>
after "deploy:restart", "fetcher:restart"

namespace :fetcher do
  desc "Stop the fetcher_mailer daemons"
  task :stop, :roles => :app do
    run "RAILS_ENV=#{rails_env} ruby #{current_path}/script/mailer_daemon_fetcher stop"
  end

  desc "Start the fetcher_mailer daemons"
  task :start, :roles => :app do
    run "RAILS_ENV=#{rails_env} nohup /opt/ruby-enterprise/bin/ruby #{current_path}/script/mailer_daemon_fetcher start", :pty => true
  end

  desc "Restart (cycle) the fetcher_mailer daemons"
  task :restart, :roles => :app do
    stop
    start
  end
end
</pre>
<p>The real key here is on the <code>:start</code> task, there are two things you need to do to get the shell to let go of the process.:</p>
<ol>
<li>Add the <a href="http://en.wikipedia.org/wiki/Nohup"><code>nohup</code></a> to your command.  If you don&#8217;t do this the process goes into the background, and as soon as the shell exits the OS says &#8220;SIGHUP&#8221; (&#8220;you don&#8217;t have to go home, but you can&#8217;t stay here.&#8221;)</li>
<li>The second thing is the <code>:pty => true</code>.  This tells Capistrano to request a <a href="http://en.wikipedia.org/wiki/Pseudo_terminal">pseudo terminal</a>. I don&#8217;t know all the nitty gritty, and have neither the time nor the inclination to dig in and find out why.</li>
</ol>
<p>So there you go, add a <code>nohup</code> and <code>:pty => true</code> and then you can get your fetcher daemon backgrounded.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jtanium.com/2010/03/12/capistrano-fetcher-daemonize/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActionView::TestCase and nil.url_for</title>
		<link>http://www.jtanium.com/2010/02/16/actionviewtestcase-and-nil-url_for/</link>
		<comments>http://www.jtanium.com/2010/02/16/actionviewtestcase-and-nil-url_for/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 18:25:26 +0000</pubDate>
		<dc:creator>jtanium</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.jtanium.com/?p=198</guid>
		<description><![CDATA[If you&#8217;re having problems testing your helpers because of messages like these: The error occurred while evaluating nil.url_for The problem, it turns out is ActionView::TestCase doesn&#8217;t like url_for, it seems to expect you&#8217;re using named routes. So, in your helper, instead of doing something like: def link_to_awesomeness(my_object) if my_object.awesome? link_to 'Awesomeness', :action => 'show_awesomeness', :id [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re having problems testing your helpers because of messages like these:</p>
<pre>The error occurred while evaluating nil.url_for
</pre>
<p>The problem, it turns out is ActionView::TestCase doesn&#8217;t like <code>url_for</code>, it seems to expect you&#8217;re using named routes.  So, in your helper, instead of doing something like:</p>
<pre>
def link_to_awesomeness(my_object)
  if my_object.awesome?
    link_to 'Awesomeness', :action => 'show_awesomeness', :id => my_object
  else
    link_to 'Make Awesome', :action => 'make_awesome', :id => my_object
  end
end
</pre>
<p>Try something more like this:</p>
<pre>
def link_to_awesomeness(my_object)
  if my_object.awesome?
    link_to 'Awesomeness', awesomeness_path(my_object)
  else
    link_to 'Make Awesome', make_awesome_path(my_object)
  end
end
</pre>
<p>Of course this implies you&#8217;ve created those named routes in your <code>config/routes.rb</code>, e.g.:</p>
<pre>
map.awesomeness 'my_objects/:id/awesomeness', :controller => 'my_objects', :action => 'show_awesomeness'
map.make_awesome 'my_objects/:id/make_awesome', :controller => 'my_objects', :action => 'make_awesome'
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.jtanium.com/2010/02/16/actionviewtestcase-and-nil-url_for/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fun Little ActiveRecord Gotcha</title>
		<link>http://www.jtanium.com/2009/12/17/fun-little-activerecord-gotcha/</link>
		<comments>http://www.jtanium.com/2009/12/17/fun-little-activerecord-gotcha/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 19:47:00 +0000</pubDate>
		<dc:creator>jtanium</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://www.jtanium.com/?p=192</guid>
		<description><![CDATA[So I was cruising along adding a new model to a project. The model is being used to store credit card information and when I generated the model, I absentmindedly did: script/generate model CreditCard ... encrypted_expiration_date:date ... Chugging along writing my tests I wrote a test like this: class CreditCardTest < ActiveSupport::TestCase context "A CreditCard [...]]]></description>
			<content:encoded><![CDATA[<p>So I was cruising along adding a new model to a project.  The model is being used to store credit card information and when I generated the model, I absentmindedly did:</p>
<pre>
script/generate model CreditCard ... encrypted_expiration_date:date ...
</pre>
<p>Chugging along writing my tests I wrote a test like this:</p>
<pre>
class CreditCardTest  < ActiveSupport::TestCase
  context "A CreditCard instance" do
    subject { CreditCard.new(:expiration_date => new_expiration_date) }
    should("ensure expiration_date is encrypted") do
      assert_equal expiration_date_cipher_text, subject.encrypted_expiration_date
    end
    def new_expiration_date; Date.today+90; end
    def expiration_date_cipher_text; "!!!EXPIRATION_DATE_CIPHER_TEXT!!!"; end
  end
</pre>
<p>And the model looking something like this:</p>
<pre>
class CreditCard < ActiveRecord::Base
  def expiration_date=(exp_date)
    @expiration_date = exp_date
    self.encrypted_expiration_date = encrypt(exp_date)
end
</pre>
<p>The test would fail every time like:</p>
<pre>
Finished in 0.030941 seconds.

  1) Failure:
test:  should encrypt expiration_date. (CreditCardTest)
    [test/unit/credit_card_test.rb:53:in `__bind_1261076018_868915'
     shoulda (2.10.2) [v] lib/shoulda/context.rb:351:in `call'
     shoulda (2.10.2) [v] lib/shoulda/context.rb:351:in `test:  should encrypt expiration_date. ']:
<"!!!EXPIRATION_DATE_CIPHER_TEXT!!!"> expected but was
<nil>.

1 tests, 1 assertions, 1 failures, 0 errors
</pre>
<p>Can you guess the problem?  Ten points to Gryffindor if you said it's because the column type is date.  And another five points if you can say it's because ActiveRecord is tries to parse it to be a date object, which fails, and returns nil.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jtanium.com/2009/12/17/fun-little-activerecord-gotcha/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Limit Access to WordPress Admin</title>
		<link>http://www.jtanium.com/2009/11/30/limit-access-to-wordpress-admin/</link>
		<comments>http://www.jtanium.com/2009/11/30/limit-access-to-wordpress-admin/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 16:31:47 +0000</pubDate>
		<dc:creator>jtanium</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[brute force]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.jtanium.com/2009/11/30/limit-access-to-wordpress-admin/</guid>
		<description><![CDATA[This entry on the Internet Storm Center&#8217;s Handler&#8217;s Diary was about &#8220;Distributed WordPress admin account cracking&#8221; &#8212; scary stuff. In the the article they suggest limiting the addresses from which the admin can be accessed. If you&#8217;re using Apache, here&#8217;s one way using the &#60;Location&#62; directive: &#60;Location /wp-admin&#62; Order Deny,Allow Deny from all Allow from [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://isc.sans.org/diary.html?n&#038;storyid=7663">This entry</a> on the Internet Storm Center&#8217;s Handler&#8217;s Diary was about &#8220;Distributed WordPress admin account cracking&#8221; &#8212; scary stuff.</p>
<p>In the the article they suggest limiting the addresses from which the admin can be accessed.  If you&#8217;re using Apache, here&#8217;s one way using the <a href="http://httpd.apache.org/docs/2.2/mod/core.html#location">&lt;Location&gt; directive</a>:</p>
<pre>
&lt;Location /wp-admin&gt;
   Order Deny,Allow
   Deny from all
   Allow from example.com 10.211.34.83
&lt;/Location&gt;
&lt;Location /wp-login.php&gt;
   Order Deny,Allow
   Deny from all
   Allow from example.com 10.211.34.83
&lt;/Location&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.jtanium.com/2009/11/30/limit-access-to-wordpress-admin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

