<?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; Tips and Tricks</title>
	<atom:link href="http://www.jtanium.com/category/tips-and-tricks/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>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>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>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>
		<item>
		<title>Expected response to be a &lt;:redirect&gt;, but was &lt;0&gt;</title>
		<link>http://www.jtanium.com/2009/11/20/expected-response-to-be-a-redirect-but-was-0/</link>
		<comments>http://www.jtanium.com/2009/11/20/expected-response-to-be-a-redirect-but-was-0/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 22:34:58 +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[ruby on rails]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.jtanium.com/2009/11/20/expected-response-to-be-a-but-was/</guid>
		<description><![CDATA[If you&#8217;re seeing this in your test: Expected response to be a &#60;:redirect&#62; , but was &#60;0&#62; You are probably doing something like this in your controller: redirect_to :action => 'messages', :status => 'read' Watch out when using :status in your params. :status is used to set the http status code in the redirect_to method, [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re seeing this in your test:</p>
<pre>Expected response to be a &lt;:redirect&gt; , but was &lt;0&gt;</pre>
<p>You are probably doing something like this in your controller:</p>
<pre>redirect_to :action => 'messages', :status => 'read'
</pre>
<p>Watch out when using <code>:status</code> in your params.  <code>:status</code> is used to set the http status code in the <code>redirect_to</code> method, like so:</p>
<pre>redirect_to :action=>'atom', :status=>302
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.jtanium.com/2009/11/20/expected-response-to-be-a-redirect-but-was-0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Enforcing Executing User on Bash Scripts</title>
		<link>http://www.jtanium.com/2009/11/04/enforcing-executing-user-on-bash-scripts/</link>
		<comments>http://www.jtanium.com/2009/11/04/enforcing-executing-user-on-bash-scripts/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 17:04:01 +0000</pubDate>
		<dc:creator>jtanium</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[root]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.jtanium.com/2009/11/04/enforcing-executing-user-on-bash-scripts/</guid>
		<description><![CDATA[Sometimes I want to make sure that a script is *not* being run by the root user: #!/bin/bash if [[ $EUID -eq 0 ]]; then echo "Don't run as root!" exit 1 fi]]></description>
			<content:encoded><![CDATA[<p>Sometimes I want to make sure that a script is *not* being run by the root user:</p>
<pre>#!/bin/bash
if [[ $EUID -eq 0 ]]; then
  echo "Don't run as root!"
  exit 1
fi</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.jtanium.com/2009/11/04/enforcing-executing-user-on-bash-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rails fields_for &#8220;is not allowed as an instance variable name&#8221;</title>
		<link>http://www.jtanium.com/2009/11/03/rails-fields_for-is-not-allowed-as-an-instance-variable-name/</link>
		<comments>http://www.jtanium.com/2009/11/03/rails-fields_for-is-not-allowed-as-an-instance-variable-name/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 21:22:34 +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=173</guid>
		<description><![CDATA[So I&#8217;ve been trying to figure this error out, it just cropped up: `@my_object[such_and_such_attributes]' is not allowed as an instance variable name As is usually the case with Rails, the answer is pretty obvious once you understand what&#8217;s going on. Here&#8217;s the relevant code: &#60;% fields_for 'my_object[such_and_suches_attributes]', @my_object.such_and_suches.first do &#124;such_and_such_form&#124; -%&#62; &#60;%= such_and_such_form.text_field :name %&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve been trying to figure this error out, it just cropped up:</p>
<pre>
`@my_object[such_and_such_attributes]' is not allowed as an instance variable name
</pre>
<p>As is usually the case with Rails, the answer is pretty obvious once you understand what&#8217;s going on. Here&#8217;s the relevant code:</p>
<pre>
&lt;% fields_for 'my_object[such_and_suches_attributes]', @my_object.such_and_suches.first do |such_and_such_form| -%&gt;
  &lt;%= such_and_such_form.text_field :name %&gt;
&lt;% end -%&gt;
</pre>
<p>So why was the above creating the error? It&#8217;s because @my_object.such_and_suches was empty, thus Rails would try and use &#8220;my_object[such_and_suches_attributes]&#8221; as the attribute name which naturally didn&#8217;t work.  This is the shortcut that allows this to work:</p>
<pre>
&lt;% fields_for :posts do |post_form| -%&gt;
  &lt;%= post_form.text_field :title %&gt;
&lt;% end -%&gt;
</pre>
<p>Now in my situation, why the &#8220;such_and_suches&#8221; is empty is a whole other problem&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jtanium.com/2009/11/03/rails-fields_for-is-not-allowed-as-an-instance-variable-name/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

