<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-5991476036615161393</atom:id><lastBuildDate>Fri, 06 Sep 2024 05:30:27 +0000</lastBuildDate><category>rails</category><category>ruby</category><category>code</category><category>git</category><category>mac</category><category>memcache</category><category>routes</category><category>sqeez</category><category>testing</category><title>Eli Miller</title><description></description><link>http://elimiller.blogspot.com/</link><managingEditor>noreply@blogger.com (Elijah Miller)</managingEditor><generator>Blogger</generator><openSearch:totalResults>9</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5991476036615161393.post-3830677556369456275</guid><pubDate>Thu, 10 Apr 2008 03:09:00 +0000</pubDate><atom:updated>2008-12-06T15:36:57.992-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">git</category><category domain="http://www.blogger.com/atom/ns#">mac</category><title>Getting postgresql and git to play nice on Mac OS X</title><description>If you installed postgresql83 using macports, you may run into some trouble building the apr dependency.

&lt;pre&gt;&lt;code&gt;
In file included from misc/unix/rand.c:39:
/opt/local/include/uuid.h:94: error: conflicting types for &#39;uuid_t&#39;
/usr/include/unistd.h:133: error: previous declaration of &#39;uuid_t&#39; was here
&lt;/code&gt;&lt;/pre&gt;

uuid_t is defined in the port of apr(git dependency) and ossp-uuid(postgresql83 dependency). Simply uninstalling postgresql83 and ossp-uuid does not solve the problem. Apparently macports is happy to let one port overwrite files from another without a huge red flag. The commands below should do everything you need.

&lt;pre&gt;&lt;code&gt;
port uninstall postgresql83-server postgresql83 ossp-uuid
port clean apr
port install git-core +svn
port install postgresql83-server
&lt;code&gt;&lt;/pre&gt;</description><link>http://elimiller.blogspot.com/2008/04/getting-postgresql-and-git-to-play-nice.html</link><author>noreply@blogger.com (Elijah Miller)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5991476036615161393.post-2235622808585955548</guid><pubDate>Tue, 18 Dec 2007 14:22:00 +0000</pubDate><atom:updated>2007-12-18T09:23:50.793-05:00</atom:updated><title>How many HTML elements can you name in 5 minutes?</title><description>&lt;a id=&quot;mingle2_badge&quot; href=&quot;http://www.justsayhi.com/bb/html_quiz&quot; style=&quot;display: block; background:url(http://assets.justsayhi.com/badges/719/472/html_elements.eu1v30r57s.jpg) no-repeat top left; height: 147px; width: 335px; text-decoration: none; color: #fff;&quot;&gt;&lt;strong id=&quot;mingle2_badge_score&quot; style=&quot;display: block; padding-left: 125px; padding-top: 44px; font-weight: normal; font-family: Times New Roman, Arial; font-size: 45px;&quot;&gt;51&lt;/strong&gt;&lt;/a&gt;

&lt;p&gt;I missed a lot of easy ones still. . . &lt;/p&gt;</description><link>http://elimiller.blogspot.com/2007/12/how-many-html-elements-can-you-name-in.html</link><author>noreply@blogger.com (Elijah Miller)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5991476036615161393.post-775698555946810678</guid><pubDate>Sat, 15 Sep 2007 17:50:00 +0000</pubDate><atom:updated>2007-09-15T13:00:11.873-05:00</atom:updated><title>Easily display svn revision</title><description>&lt;p&gt;In one of my projects we&#39;ll occasionally have production servers that don&#39;t get restarted on a deploy and this is a nightmare when it comes to tracking down bugs. Following the &lt;a href=&quot;http://glu.ttono.us/articles/2007/08/17/snippet-svn-info-parsing-with-yaml&quot;&gt;easy svn info parsing with YAML&lt;/a&gt;, we create a constant that holds our revision that gets set only when the server is starting.&lt;/p&gt;

&lt;p&gt;Put this in your environment.rb:&lt;/p&gt;

&lt;pre&gt;&lt;code src=&quot;ruby&quot;&gt;Revision = YAML::load(`svn info $RAILS_ROOT`)[&quot;Revision&quot;]&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We can then easily display it along with other debug information to certain user accounts.&lt;/p&gt;

&lt;p&gt;Note: since this is set in environment.rb it will only be set once at application startup. This is great for performance but will show stale revision information in development mode. This should be a non-issue for everyone since this exists solely for debugging production server failed restarts.&lt;/p&gt;</description><link>http://elimiller.blogspot.com/2007/09/easily-display-svn-revision.html</link><author>noreply@blogger.com (Elijah Miller)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5991476036615161393.post-7851513848989412549</guid><pubDate>Sun, 19 Aug 2007 08:10:00 +0000</pubDate><atom:updated>2007-08-19T03:22:19.318-05:00</atom:updated><title>Less is more with redgreen</title><description>When running tests, it&#39;s normal to put the most basic functionality tests at the begining, but when you run a test with a lot of errors you&#39;ll end up with more complex end tests staring you in the face. I used to try to solve what was in front of me, so I would start at the end. This is obviously harder and basically a waste of time, so my next move was to run the test case and pipe it through less.

&lt;pre&gt;&lt;code src=&quot;bash&quot;&gt;ruby test.rb | less
&lt;/code&gt;&lt;/pre&gt;

That worked perfectly fine until I installed redgreen to highlight my successes and failures. Now less ends up escaping all of the color codes and I&#39;m left with a messy screen of numbers and reversed colors.

&lt;pre&gt;&lt;code src=&quot;bash&quot;&gt;ruby test.rb | less -R
&lt;/code&gt;&lt;/pre&gt;

Shouldn&#39;t less default to displaying color codes? Alias that!</description><link>http://elimiller.blogspot.com/2007/08/less-is-more-with-redgreen.html</link><author>noreply@blogger.com (Elijah Miller)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5991476036615161393.post-4097108944199388907</guid><pubDate>Thu, 21 Jun 2007 05:32:00 +0000</pubDate><atom:updated>2007-06-21T16:10:04.180-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">ruby</category><title>&quot;duck typing made easy&quot;.gsub(/y$/, &#39;ier&#39;)</title><description>&lt;p&gt;I was reading through the ever amazing &lt;a href=&quot;http://beast.caboo.se/&quot;&gt;Beast Forum&lt;/a&gt; code and came across this bit in distance_of_time_in_words method of application helper.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;from_time = from_time.to_time if from_time.respond_to?(:to_time)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Duck typing is great, and you should use it when possible, but look at how ugly it makes things. You have to type to_time twice, once as a method and once as a symbol. The object has to be typed twice as well, maybe if I had some fancy Textmate snippet or something to help me. Or some slightly clever Ruby code.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;def method_missing(method, *args)
  return super unless method.to_s =~ /_if_respond_to$/
  method_name = method.to_s.gsub(/_if_respond_to$/, &#39;&#39;)
  return self unless self.respond_to? method_name
  return self.send(method_name)
end&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now we can easily do:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;from_time.to_time_if_respond_to
# =&gt; Thu Jun 20 17:25:13 -0400 2007

123.to_s_if_respond_to
# =&gt; &quot;123&quot;


# What if it doesn&#39;t respond_to? your method?
123.to_roman_numerals_if_respond_to
# =&gt; 123

&lt;/code&gt;&lt;/pre&gt;</description><link>http://elimiller.blogspot.com/2007/06/duck-typing-made-easyer.html</link><author>noreply@blogger.com (Elijah Miller)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5991476036615161393.post-1585360143951436722</guid><pubDate>Sat, 16 Jun 2007 04:11:00 +0000</pubDate><atom:updated>2007-06-21T16:08:28.955-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">memcache</category><category domain="http://www.blogger.com/atom/ns#">rails</category><title>Proper cache expiry with after_commit</title><description>&lt;p&gt;I&#39;m using &lt;a href=&quot;http://require.errtheblog.com/plugins/browser/cache_fu&quot;&gt;cache_fu&lt;/a&gt; to handle all of my ActiveRecord memcaching these days. It is an amazingly simple and powerful addition to AR to easily use &lt;a href=&quot;http://danga.com/memcached/&quot;&gt;memcached&lt;/a&gt;, and I highly recommend it. I&#39;ve really only had this one problem with it, the suggested cache expiry is:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;after_save :expire_cache
after_destroy :expire_cache&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I noticed a troubling thing about using after_save to expire caches, after_save is still within the transaction that save is automatically wrapped in. I assume this is to protect against an error during the after_save call, so you can roll back the database to it&#39;s previous state. When you&#39;re expiring caches though, you need to make sure the underlying data is actually changed before you expire the cache, otherwise you risk caching the old data before the new data is committed. This could go unnoticed, but if you&#39;re using &lt;a href=&quot;http://api.rubyonrails.org/classes/ActiveRecord/Locking/Optimistic.html&quot;&gt;optimistic locking&lt;/a&gt;, it raises exceptions when you try to save stale data.&lt;/p&gt;

&lt;p&gt;To be a little more clear, a normal post.save looks something like this:&lt;/p&gt;

&lt;pre&gt;SQL (0.000363)   BEGIN
Post Update (0.000572)   UPDATE posts SET &quot;created_at&quot; = &#39;2007-06-13 21:15:40.212720&#39;,
&quot;last_edited_at&quot; = NULL, &quot;user_id&quot; = 8, &quot;body&quot; = &#39;hello world&#39;, &quot;updated_at&quot; = &#39;2007-06-16
18:45:24.412415&#39;, &quot;topic_id&quot; = 7 WHERE &quot;id&quot; = 11
SQL (0.000893)   COMMIT&lt;/pre&gt;

&lt;p&gt;Notice how everything is wrapped nicely with a BEGIN and COMMIT.&lt;/p&gt;

&lt;p&gt;Now after adding an after_save method that simply logs &quot;Expire Cache!&quot; we can see the order of events:&lt;/p&gt;

&lt;pre&gt;SQL (0.000363)   BEGIN
Post Update (0.000591)   UPDATE posts SET &quot;created_at&quot; = &#39;2007-06-13 21:15:40.212720&#39;,
&quot;last_edited_at&quot; = NULL, &quot;user_id&quot; = 8, &quot;body&quot; = &#39;hello world&#39;, &quot;updated_at&quot; = &#39;2007-06-16
18:49:49.869814&#39;, &quot;topic_id&quot; = 7 WHERE &quot;id&quot; = 11
Expire Cache!
SQL (0.000874)   COMMIT&lt;/pre&gt;

&lt;p&gt;If we imagine that Expire Cache! took 10 seconds to run, we can see that there is a measurable amount of time between Expire Cache! and the COMMIT. Database servers don&#39;t want to hand out incomplete or just wrong data, so they will serve the &quot;old&quot; data during this time, switching to the UPDATEd data after the COMMIT. If this post gets requested again during that 10 second window, it will be cached as the &quot;old&quot; data. Now we have a database with one value, and a cache with another, but they both think they have the correct data. We need to move the expire cache operation outside of the commit to remove this problem area.&lt;/p&gt;

&lt;h3&gt;Enter after_commit&lt;/h3&gt;

&lt;p&gt;We add a callback right after any save or destroy operation, which does the operation and then calls after_commit. Theoretically this works with update_attribute and any other AcitveRecord write operation, but I haven&#39;t fully tested those cases.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;module ActiveRecord
  class Base

    class &lt;&lt; self


      # Class methods


      def after_commit(*callbacks, &amp;block)
        callbacks &lt;&lt; block if block_given?
        write_inheritable_array(:after_commit, callbacks)
      end

    end


    # Instance Methods


    def save_with_after_commit_callback(*args)
      value = save_without_after_commit_callback(args)
      callback(:after_commit)
      return value
    end
    alias_method_chain :save, :after_commit_callback


    def save_with_after_commit_callback!(*args)
      value = save_without_after_commit_callback!
      callback(:after_commit)
      return value
    end
    alias_method_chain :save!, :after_commit_callback


    def destroy_with_after_commit_callback
      value = destroy_without_after_commit_callback
      callback(:after_commit)
      return value
    end
    alias_method_chain :destroy, :after_commit_callback

  end
end&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Since we wrapped save and destroy to call after_commit, we need only add one callback to expire caches now:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;after_commit :expire_cache&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And here is the log:&lt;/p&gt;

&lt;pre&gt;SQL (0.000365)   BEGIN
Post Update (0.000772)   UPDATE posts SET &quot;created_at&quot; = &#39;2007-06-13 21:15:40.212720&#39;,
&quot;last_edited_at&quot; = NULL, &quot;user_id&quot; = 8, &quot;body&quot; = &#39;hello world&#39;, &quot;updated_at&quot; = &#39;2007-06-16
19:05:55.108429&#39;, &quot;topic_id&quot; = 7 WHERE &quot;id&quot; = 11
SQL (0.000929)   COMMIT
Expire Cache!&lt;/pre&gt;</description><link>http://elimiller.blogspot.com/2007/06/proper-cache-expiry-with-aftercommit.html</link><author>noreply@blogger.com (Elijah Miller)</author><thr:total>8</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5991476036615161393.post-3879566266647609945</guid><pubDate>Fri, 04 May 2007 17:07:00 +0000</pubDate><atom:updated>2007-06-21T16:11:15.593-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">ruby</category><category domain="http://www.blogger.com/atom/ns#">testing</category><title>assert_changes</title><description>&lt;div class=&quot;update&quot;&gt;Update: I have a patch awaiting approval on &lt;a href=&quot;http://chneukirchen.org/repos/testspec/&quot;&gt;test-spec&lt;/a&gt; to add should.differ, change, increase and decrease. These read a lot better than the assert_difference/change methods.&lt;/div&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;# Checks multiple methods on object before and after the block asserting that there is
# a different value returned for each method. This is especially good for non-numeric fields.
def assert_changes(object, methods = nil)
  methods = [methods] unless methods.is_a? Array

  initial_values = {}
  for method in methods
    initial_values[method] = object.send(method)
  end


  yield
  object.reload if object.respond_to? :reload


  for method in methods
    assert_not_equal initial_values[method], object.send(method), &quot;#{object}##{method}&quot;
  end
end

alias assert_change assert_changes&lt;/code&gt;&lt;/pre&gt;</description><link>http://elimiller.blogspot.com/2007/05/assertchanges.html</link><author>noreply@blogger.com (Elijah Miller)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5991476036615161393.post-3417637072975453023</guid><pubDate>Thu, 25 Jan 2007 20:02:00 +0000</pubDate><atom:updated>2008-03-19T13:27:35.853-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">rails</category><category domain="http://www.blogger.com/atom/ns#">routes</category><title>Static Controller Shortcuts</title><description>&lt;div class=&quot;update&quot;&gt;Update: Gabe da Silveira is doing something similar at &lt;/span&gt;&lt;a style=&quot;font-weight: bold;&quot; href=&quot;http://darwinweb.net/article/Routing_Nested_Static_Content_In_Rails&quot;&gt;Routing Nested Static Content in Rails&lt;/a&gt;.&lt;/div&gt;


&lt;p&gt;The first tidbit.&lt;/p&gt;

&lt;p&gt;Most sites tend to have at least 4+ static pages. Typically: about us, user agreement, contact, privacy policy and 404. I&#39;ll assume you already have a static controller that holds these view templates. Instead of making a bunch of static routes from &quot;/about&quot; to &quot;views/static/about&quot;, you can add one simple to direct everything that doesn&#39;t go to an existing controller to your static controller.&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;# Add this after your default route &#39;:controller/:action/:id&#39;
map.static &#39;:action/&#39;, :controller=&gt;&#39;static&#39;&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Since the Rails default route will only match a url if the controller name exists, /about will not match and it will be displayed by our new static route. For bonus points this is a &lt;a href=&quot;http://wiki.rubyonrails.org/rails/pages/NamedRoutes&quot;&gt;named route&lt;/a&gt; and you can use this code to generate the url for the about page:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;static_url(:action =&gt; :about)&lt;/code&gt;&lt;/pre&gt;</description><link>http://elimiller.blogspot.com/2007/01/static-controller-shortcuts.html</link><author>noreply@blogger.com (Elijah Miller)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-5991476036615161393.post-5368424207836549423</guid><pubDate>Thu, 25 Jan 2007 19:33:00 +0000</pubDate><atom:updated>2007-06-21T16:13:20.450-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">code</category><category domain="http://www.blogger.com/atom/ns#">rails</category><category domain="http://www.blogger.com/atom/ns#">ruby</category><category domain="http://www.blogger.com/atom/ns#">sqeez</category><title>&#39;Bout time.</title><description>&lt;p&gt;Today I decided to resurrect my blogger account from my &lt;a href=&quot;http://www.informatics.indiana.edu/&quot;&gt;Informatics&lt;/a&gt; days at &lt;a href=&quot;http://iub.edu/&quot;&gt;IU Bloomington&lt;/a&gt;, and actually do something worthwhile with it. So here is the story that starts this saga.&lt;/p&gt;

&lt;p&gt;Last year I was contracted to code a pretty basic social networking site in &lt;a href=&quot;http://www.rubyonrails.org/&quot;&gt;Ruby on Rails&lt;/a&gt;. Although my main competency was PHP, the client was certain that they wanted it done with Rails. This was fine with me, I had read a few articles about Rails and knew that it had a lot of features that I&#39;ve been dying for in PHP.&lt;/p&gt;

&lt;p&gt;So over the next few months I learned Ruby and Rails and implemented a few iterations of the site. Since Rails is a relative newcomer, I was purchasing lots of books on it and Ruby while subscribing to many ruby news/blog feeds. All the while I struggled through all the deployment issues, multiple hosts and rails version change breaks. If it weren&#39;t for the sheer joy of coding Ruby and using Rails, I am sure I would have stopped after a month.&lt;/p&gt;

&lt;p&gt;Anyhow, I&#39;ve come to find that the Rails documentation does go a long way, but I learned the most from reading the weblogs of people who use Rails daily. There is a project underway to improve not only the documentation, but the way the documentation is created. I will happily contribute to that once it is available, but until then I will hopefully be sharing bits of Ruby and Rails wisdom on this blog like those before me.&lt;/p&gt;</description><link>http://elimiller.blogspot.com/2007/01/bout-time.html</link><author>noreply@blogger.com (Elijah Miller)</author><thr:total>0</thr:total></item></channel></rss>