<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/atom10full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:thr="http://purl.org/syndication/thread/1.0" xml:lang="en" xml:base="http://jonathanjulian.com/wp-atom.php">
	<title type="text">render :blog =&gt; 'jonathan'</title>
	<subtitle type="text">jonathan julian's discusions about ruby, rails, software development</subtitle>

	<updated>2008-08-03T00:10:55Z</updated>
	<generator uri="http://wordpress.org/" version="">WordPress</generator>

	<link rel="alternate" type="text/html" href="http://jonathanjulian.com" />
	<id>http://jonathanjulian.com/feed/atom/</id>
	

			<link rel="self" href="http://feeds.feedburner.com/jonathanjulian" type="application/atom+xml" /><entry>
		<author>
			<name>jonathan</name>
						<uri>http://jonathanjulian.com/</uri>
					</author>
		<title type="html"><![CDATA[Test all the fucking time]]></title>
		<link rel="alternate" type="text/html" href="http://jonathanjulian.com/2008/08/test-all-the-fucking-time/" />
		<id>http://jonathanjulian.com/?p=11</id>
		<updated>2008-08-03T00:10:55Z</updated>
		<published>2008-08-03T00:10:55Z</published>
		<category scheme="http://jonathanjulian.com" term="Ruby" />		<summary type="html"><![CDATA[Bryan Liles struck a chord at RubyNation this weekend with his advice for TDD and BDD folks: &#8220;How often should we test?&#8221; &#8220;Test all the fucking time!&#8220;. Luckily, it&#8217;s easy to do.
]]></summary>
		<content type="html" xml:base="http://jonathanjulian.com/2008/08/test-all-the-fucking-time/"><![CDATA[<p><a href="http://smartic.us/">Bryan Liles</a> struck a chord at <a href="http://rubynation.org">RubyNation</a> this weekend with his advice for TDD and BDD folks: &#8220;How often should we test?&#8221; &#8220;<strong>Test all the fucking time!</strong>&#8220;. Luckily, it&#8217;s <a href="http://www.zenspider.com/ZSS/Products/ZenTest/">easy to do</a>.</p>
]]></content>
		<link rel="replies" type="text/html" href="http://jonathanjulian.com/2008/08/test-all-the-fucking-time/#comments" thr:count="0" />
		<link rel="replies" type="appication/atom+xml" href="http://jonathanjulian.com/2008/08/test-all-the-fucking-time/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	</entry>
		<entry>
		<author>
			<name>jonathan</name>
						<uri>http://jonathanjulian.com/</uri>
					</author>
		<title type="html"><![CDATA[Lots of Rails books coming soon]]></title>
		<link rel="alternate" type="text/html" href="http://jonathanjulian.com/2008/07/lots-of-rails-books-coming-soon/" />
		<id>http://jonathanjulian.com/?p=10</id>
		<updated>2008-07-30T20:45:38Z</updated>
		<published>2008-07-30T20:45:38Z</published>
		<category scheme="http://jonathanjulian.com" term="Rails" />		<summary type="html"><![CDATA[The people who market technical books pay attention to the &#8220;trends&#8221; in technology. The fall of C and C++. The rise of Ruby / Rails. The rise (and fall) of Java. If us technology people &#8220;watch the watchers&#8221;, we can get a nice warm-and-fuzzy about our current technology choices. For example, look at all the [...]]]></summary>
		<content type="html" xml:base="http://jonathanjulian.com/2008/07/lots-of-rails-books-coming-soon/"><![CDATA[<p>The people who market technical books pay attention to the &#8220;trends&#8221; in technology. The fall of C and C++. The rise of Ruby / Rails. The rise (and fall) of Java. If us technology people &#8220;watch the watchers&#8221;, we can get a nice warm-and-fuzzy about our current technology choices. For example, look at all the <a href="http://rubyworld.wordpress.com/2008/07/26/wow-very-huge-list-of-upcoming-rubyrails-books-in-2008/">Ruby and Rails books </a>being published in the coming months!</p>
]]></content>
		<link rel="replies" type="text/html" href="http://jonathanjulian.com/2008/07/lots-of-rails-books-coming-soon/#comments" thr:count="0" />
		<link rel="replies" type="appication/atom+xml" href="http://jonathanjulian.com/2008/07/lots-of-rails-books-coming-soon/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	</entry>
		<entry>
		<author>
			<name>jonathan</name>
						<uri>http://jonathanjulian.com/</uri>
					</author>
		<title type="html"><![CDATA[Testing SNMP traps with snmptrapd]]></title>
		<link rel="alternate" type="text/html" href="http://jonathanjulian.com/2008/07/testing-snmp-traps-with-snmptrapd/" />
		<id>http://jonathanjulian.com/?p=9</id>
		<updated>2008-07-07T03:02:48Z</updated>
		<published>2008-07-07T03:02:48Z</published>
		<category scheme="http://jonathanjulian.com" term="Rails" /><category scheme="http://jonathanjulian.com" term="UNIX" />		<summary type="html"><![CDATA[If you&#8217;ve never worked with SNMP, then you&#8217;re in for a treat. Get ready to party like it&#8217;s 1988, with nested authentication models, over-designed protocols, and lots of meaningless numbers. Luckily, if all you need to do is write some ruby code to send SNMP traps, you have the snmp gem to help make things [...]]]></summary>
		<content type="html" xml:base="http://jonathanjulian.com/2008/07/testing-snmp-traps-with-snmptrapd/"><![CDATA[<p>If you&#8217;ve never worked with SNMP, then you&#8217;re in for a treat. Get ready to party like it&#8217;s 1988, with nested authentication models, over-designed protocols, and lots of meaningless numbers. Luckily, if all you need to do is write some ruby code to send SNMP traps, you have the <a href="http://snmplib.rubyforge.org/">snmp gem</a> to help make things pretty palatable.</p>
<p>So there I was, with my ruby model code happily sending out SNMP traps&#8230;.or was it? For development (and test and qa) I set up the yaml file to send SNMP traps to localhost (port 162 is the default). I just needed a way to recieve them.</p>
<p>Enter snmptrapd.</p>
<p>Yes! A command line tool to catch the traps and log them the stdout! This turned out to be pretty easy on my MacBookPro - <a href="http://www.net-snmp.org/">net-snmp</a> is already installed.</p>
<p>The hardest part is setting up the authorization model. Do this: Create a file called snmptrapd.conf in the current directory. Add the line &#8220;disableAuthorization yes&#8221; to it. Heheh. No need for security - we just want to see them.</p>
<p>Now run the snmptrapd in the foreground, logging everything to stdout:</p>
<p>sudo snmptrapd -f -Lo -c snmptrapd.conf</p>
<p>Done. Now your messages will show up in that console window. This was not as nearly as painful as I expected!</p>
<p>So in the yml file, I will configure the snmp_trap_destination to be localhost for all environments except production. If there is no daemon running, they will quietly be ignored (UDP rocks). If there is one running (debugging qa, development) then they can be logged. Life is good, even when working with a 20 year old protocol.</p>
<p>(and thanks to <a href="http://www.atlantageek.com/?p=21">atlantageek</a> for one of the only blog posts out there about snmp and ruby!)</p>
]]></content>
		<link rel="replies" type="text/html" href="http://jonathanjulian.com/2008/07/testing-snmp-traps-with-snmptrapd/#comments" thr:count="0" />
		<link rel="replies" type="appication/atom+xml" href="http://jonathanjulian.com/2008/07/testing-snmp-traps-with-snmptrapd/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	</entry>
		<entry>
		<author>
			<name>jonathan</name>
						<uri>http://jonathanjulian.com/</uri>
					</author>
		<title type="html"><![CDATA[Beware rendering multiple partials with layouts]]></title>
		<link rel="alternate" type="text/html" href="http://jonathanjulian.com/2008/04/beware-rendering-multiple-partials-with-layouts/" />
		<id>http://jonathanjulian.com/?p=8</id>
		<updated>2008-04-27T19:19:17Z</updated>
		<published>2008-04-27T19:19:17Z</published>
		<category scheme="http://jonathanjulian.com" term="Rails" />		<summary type="html"><![CDATA[Want to render more than one partial with the same layout in your page? Beware:

 &#8216;p1&#8242;, :layout => &#8216;layouts/p_layout&#8217; %>
 &#8216;p2&#8242;, :layout => &#8216;layouts/p_layout&#8217; %>

layouts/p_layout.html.erb




&#60;hr/&#62;

_p1.html.erb



Content!

_p2.html.erb



Content!

Did you expect this?

HeaderFor1 Content! FooterFor1

HeaderFor2 Content! FooterFor2

Nope. You get this:

HeaderFor1 Content! FooterFor1

HeaderFor1HeaderFor2 Content! FooterFor1FooterFor2

The instance variables in the layout object retain their values, even between invocations of render. My workaround [...]]]></summary>
		<content type="html" xml:base="http://jonathanjulian.com/2008/04/beware-rendering-multiple-partials-with-layouts/"><![CDATA[<p>Want to render more than one partial <strong>with the same layout</strong> in your page? Beware:</p>
<pre>
<%= render :partial => &#8216;p1&#8242;, :layout => &#8216;layouts/p_layout&#8217; %>
<%= render :partial => &#8216;p2&#8242;, :layout => &#8216;layouts/p_layout&#8217; %>
</pre>
<p>layouts/p_layout.html.erb</p>
<pre>
<%= yield :top %>
<%= yield %>
<%= yield :bottom %>
&lt;hr/&gt;
</pre>
<p>_p1.html.erb</p>
<pre>
<% content_for :top, 'HeaderFor1' %>
<% content_for :bottom, 'FooterFor1' %>
Content!
</pre>
<p>_p2.html.erb</p>
<pre>
<% content_for :top, 'HeaderFor2' %>
<% content_for :bottom, 'FooterFor2' %>
Content!
</pre>
<p>Did you expect this?</p>
<p>
HeaderFor1 Content! FooterFor1</p>
<hr/>
HeaderFor2 Content! FooterFor2</p>
<hr/>
<p>Nope. You get this:</p>
<p>
HeaderFor1 Content! FooterFor1</p>
<hr/>
HeaderFor1HeaderFor2 Content! FooterFor1FooterFor2</p>
<hr/>
<p>The instance variables in the layout object retain their values, even between invocations of render. My workaround (since I&#8217;m not sure if some would call this a &#8220;feature&#8221;)&#8230;clear the instance variables at the end of your layout.</p>
<pre>
<%= yield :top %>
<%= yield %>
<%= yield :bottom %>
&lt;hr/&gt;
<% @content_for_top, @content_for_bottom = nil %>
</pre>
<p>Now it works as I expected.</p>
]]></content>
		<link rel="replies" type="text/html" href="http://jonathanjulian.com/2008/04/beware-rendering-multiple-partials-with-layouts/#comments" thr:count="0" />
		<link rel="replies" type="appication/atom+xml" href="http://jonathanjulian.com/2008/04/beware-rendering-multiple-partials-with-layouts/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	</entry>
		<entry>
		<author>
			<name>jonathan</name>
						<uri>http://jonathanjulian.com/</uri>
					</author>
		<title type="html"><![CDATA[Rails LOC vs Java LOC]]></title>
		<link rel="alternate" type="text/html" href="http://jonathanjulian.com/2008/04/rails-loc-vs-java-loc/" />
		<id>http://jonathanjulian.com/?p=7</id>
		<updated>2008-04-25T18:53:34Z</updated>
		<published>2008-04-25T18:53:34Z</published>
		<category scheme="http://jonathanjulian.com" term="Java" /><category scheme="http://jonathanjulian.com" term="Rails" />		<summary type="html"><![CDATA[At my last client, we wrote a webservice in Java, it had perhaps 30 service calls and 3 endpoints. We worked on it for about 6 months.

$ find services -name *.java -exec wc {} \; &#124; awk '{a+=$1;print a}' &#124;tail -1
64793

At my current client, we are writing a Rails web application. It&#8217;s been a living [...]]]></summary>
		<content type="html" xml:base="http://jonathanjulian.com/2008/04/rails-loc-vs-java-loc/"><![CDATA[<p>At my last client, we wrote a webservice in Java, it had perhaps 30 service calls and 3 endpoints. We worked on it for about 6 months.</p>
<pre>
$ find services -name *.java -exec wc {} \; | awk '{a+=$1;print a}' |tail -1
64793
</pre>
<p>At my current client, we are writing a Rails web application. It&#8217;s been a living project for almost 2 years.</p>
<pre>
$ find app -name *.rb -exec wc {} \; | awk '{a+=$1;print a}' |tail -1
5133
$ find lib -name *.rb -exec wc {} \; | awk '{a+=$1;print a}' |tail -1
1141
$ find app -name *.erb -exec wc {} \; | awk '{a+=$1;print a}' |tail -1
3104
</pre>
]]></content>
		<link rel="replies" type="text/html" href="http://jonathanjulian.com/2008/04/rails-loc-vs-java-loc/#comments" thr:count="0" />
		<link rel="replies" type="appication/atom+xml" href="http://jonathanjulian.com/2008/04/rails-loc-vs-java-loc/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	</entry>
		<entry>
		<author>
			<name>jonathan</name>
						<uri>http://jonathanjulian.com/</uri>
					</author>
		<title type="html"><![CDATA[Generate mod_rails httpd.conf using cap]]></title>
		<link rel="alternate" type="text/html" href="http://jonathanjulian.com/2008/04/generate-mod_rails-httpd-conf-using-cap/" />
		<id>http://jonathanjulian.com/?p=6</id>
		<updated>2008-04-24T01:33:43Z</updated>
		<published>2008-04-24T01:33:43Z</published>
		<category scheme="http://jonathanjulian.com" term="Apache" /><category scheme="http://jonathanjulian.com" term="Capistrano" /><category scheme="http://jonathanjulian.com" term="Rails" /><category scheme="http://jonathanjulian.com" term="mod_rails" />		<summary type="html"><![CDATA[With all the discussions around the new mod_rails, I thought I&#8217;d post the Apache conf that I came up with. Here&#8217;s the strategy: generate httpd.conf using cap, upload it to the server, and graceful restart Apache. This way, you don&#8217;t have to get your hands dirty logging into the box to reconfigure anything. 
Here&#8217;s the [...]]]></summary>
		<content type="html" xml:base="http://jonathanjulian.com/2008/04/generate-mod_rails-httpd-conf-using-cap/"><![CDATA[<p>With all the discussions around the new <a href="http://modrails.com">mod_rails</a>, I thought I&#8217;d post the Apache conf that I came up with. Here&#8217;s the strategy: generate httpd.conf using cap, upload it to the server, and graceful restart Apache. This way, you don&#8217;t have to get your hands dirty logging into the box to reconfigure anything. </p>
<p>Here&#8217;s the erb template for httpd.conf:</p>
<pre>
#
# Apache httpd.conf
# generated by cap. run by <%= user %> at <%= Time.now %>
#

ServerRoot &#8220;<%= current_release %>&#8221;
PidFile &#8220;<%= current_release %>/tmp/pids/httpd.pid&#8221;
LockFile &#8220;<%= current_release %>/log/accept.lock&#8221;
ServerName localhost
ServerAdmin &#8220;me&#8221;
Listen <%= web_port %>

# prefork MPM
# StartServers: number of server processes to start
# MinSpareServers: minimum number of server processes which are kept spare
# MaxSpareServers: maximum number of server processes which are kept spare
# MaxClients: maximum number of server processes allowed at a time
# MaxRequestsPerChild: maximum number of requests a server process serves until death
StartServers          <%= apache_processes %>
MinSpareServers       <%= apache_processes %>
MaxSpareServers       <%= apache_processes %>
MaxClients            100
MaxRequestsPerChild   0

ErrorLog &#8220;<%= current_release %>/log/apache_error_log&#8221;
# Possible values include: debug, info, notice, warn, error, crit, alert, emerg
LogLevel info
LogFormat &#8220;%h %l %u %t \&#8221;%r\&#8221; %>s %b \&#8221;%{Referer}i\&#8221; \&#8221;%{User-Agent}i\&#8221;" combined
CustomLog &#8220;<%= current_release %>/log/apache_access_log&#8221; combined
#RewriteLog &#8220;<%= current_release %>/log/apache_rewrite_log&#8221;
# 0-9, 0 = off, 2 and 3 is good for debugging
#RewriteLogLevel 3

ServerTokens Prod
ServerSignature Off

DefaultType text/plain
TypesConfig /usr/local/apache2/conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz

<% if behind_https %>
# for envs that sit behind an https load balancer
RequestHeader set X-FORWARDED_PROTO https
<% end %>

# using Passenger (http://www.modrails.com/) to serve Rails
LoadModule passenger_module <%= gem_home %>/passenger-1.0.1/ext/apache2/mod_passenger.so
RailsSpawnServer            <%= gem_home %>/passenger-1.0.1/bin/passenger-spawn-server
RailsRuby             <%= ruby_binary %>

RailsUserSwitching    off
# max number of Rails processes to be spawned at a time
RailsMaxPoolSize      <%= max_rails_processes %>
# spawner processes will be killed if idle for 60 minutes
RailsPoolIdleTime     3600
RailsEnv              <%= environment %>

RailsAllowModRewrite  on
RewriteEngine On
# Check for maintenance file and redirect all requests
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
RewriteRule ^.*$ %{DOCUMENT_ROOT}/system/maintenance.html [L]

DocumentRoot &#8220;<%= current_release %>/public&#8221;
&lt;Directory <%= current_release %>/public&gt;
    Options FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all

    # Set the max size for file uploads to 10M
    LimitRequestBody 10485760
&lt;/Directory&gt;

&lt;Directory /&gt;
    Options FollowSymLinks
    AllowOverride None
    Order Deny,Allow
    Deny from all
&lt;/Directory&gt;
</pre>
<p>Here is the cap task to generate httpd.conf and upload it to the server:</p>
<pre>
desc "Generate the apache httpd.conf file from the template"
task :generate_apache_httpd_conf_file, :roles => :app do
  require 'erb'
  # set up defaults for some vars to go into the template. others are required.
  apache_processes = fetch(:www_procs, 2)
  max_rails_processes = fetch(:max_rails_procs, 2)
  ruby_binary = fetch(:ruby_binary, "ruby")
  gem_home = fetch(:gem_home, '/usr/local/lib/ruby/gems/1.8/gems')
  behind_https = fetch(:fronted_by_https, false)
  template = ERB.new(File.read('config/templates/httpd.conf.erb'), nil, '<>&#8216;)
  result = template.result(binding)
  put(result, &#8220;#{current_release}/httpd.conf&#8221;)
end
</pre>
<p>It runs in an after_update_code task. This way, <strong>all server configs are under code control.</strong> This is huge! Each deployed environment&#8217;s settings are known and tracked - not just loosely keyed on each server. I treat Apache as part of our application - not a service that happens to be running that we deploy into. Using this technique, along with <a href="http://errtheblog.com/posts/50-vendor-everything">vendor_everything</a>, we&#8217;ve minimized our host dependencies.</p>
]]></content>
		<link rel="replies" type="text/html" href="http://jonathanjulian.com/2008/04/generate-mod_rails-httpd-conf-using-cap/#comments" thr:count="0" />
		<link rel="replies" type="appication/atom+xml" href="http://jonathanjulian.com/2008/04/generate-mod_rails-httpd-conf-using-cap/feed/atom/" thr:count="0" />
		<thr:total>0</thr:total>
	</entry>
	</feed>
