<rss version='2.0' xmlns:atom='http://www.w3.org/2005/Atom'>
  <channel>
    <link>http://autonomousmachine.com</link>
    <title>Autonomous Machine</title>
    <description>The code blog of Jim Benton</description>
    <language>en-us</language>
    <atom:link href="http://autonomousmachine.com/posts.rss" rel="self" type="application/rss+xml" />
    <item>
      <pubDate>Sun, 02 Jun 2013 18:40:19 +0000</pubDate>
      <guid>http://autonomousmachine.com/posts/2013/6/2/prix-fixe-adds-prefixes-to-all-css-class-names-in-a-stylesheet</guid>
      <link>http://autonomousmachine.com/posts/2013/6/2/prix-fixe-adds-prefixes-to-all-css-class-names-in-a-stylesheet</link>
      <title>Prix Fixe adds prefixes to all CSS class names in a stylesheet</title>
      <description xml:space='preserve'>
        &lt;p&gt;I've been hacking on a mobile app using &lt;a href=&quot;http://emberjs.com/&quot;&gt;Ember.js&lt;/a&gt; and the CSS from &lt;a href=&quot;http://maker.github.io/ratchet/&quot;&gt;Ratchet&lt;/a&gt;. I was trying to keep my application styles separate from those provided by the &quot;framework&quot;, and I found myself wishing that the styles provided by Ratchet were easier to tell apart from the ones defined in my application. For example, I thought a classname like &lt;code&gt;.rt-button&lt;/code&gt; communicated this more clearly than the basic &lt;code&gt;.button&lt;/code&gt;.&lt;/p&gt;
        
        &lt;p&gt;I decided to see how hard it would be actually process a stylesheet and add prefixes to its classnames. Luckily, the &lt;a href=&quot;http://sass-lang.com/&quot;&gt;SASS&lt;/a&gt; project had already done the difficult work of writing a CSS parser. Using their &lt;a href=&quot;https://github.com/nex3/sass/blob/stable/lib/sass/css.rb&quot;&gt;CSS importer&lt;/a&gt; as a starting point, I built a small script to add a prefix to the beginning of all CSS classnames in a stylesheet. This weekend, I put together &lt;a href=&quot;http://prix-fixe.herokuapp.com/&quot;&gt;Prix Fixe&lt;/a&gt; to make it easy for anyone to perform this kind of modification to a stylesheet.&lt;/p&gt;
        
        &lt;p&gt;A few caveats:&lt;/p&gt;
        
        &lt;ul&gt;
        &lt;li&gt;Since this tool it only operates on CSS, frameworks that ship with JavaScript will probably be broken when using prefixed styles.&lt;/li&gt;
        &lt;li&gt;Likewise, since it only modifies classnames, rules that include other types of selectors (basic elements, etc) won't be modified.&lt;/li&gt;
        &lt;/ul&gt;
        
        
        &lt;p&gt;Prix Fixe works pretty well. I've been using a prefixed stylesheet on a project for a while now, and I don't plan on going back.&lt;/p&gt;
        
        &lt;p&gt;&lt;a href=&quot;https://github.com/jim/prix-fixe&quot;&gt;The source&lt;/a&gt; is on GitHub.&lt;/p&gt;
      </description>
    </item>
    <item>
      <pubDate>Wed, 03 Oct 2012 19:39:43 +0000</pubDate>
      <guid>http://autonomousmachine.com/posts/2012/10/3/convert-string-values-to-ruby-objects</guid>
      <link>http://autonomousmachine.com/posts/2012/10/3/convert-string-values-to-ruby-objects</link>
      <title>Convert string values to Ruby objects</title>
      <description xml:space='preserve'>
        &lt;p&gt;On a project at work we've started to use environment variables to toggle features on and off in the application. We're just getting into feature toggling, and this seemed to be the best lightest-weight way to get started.&lt;/p&gt;
        
        &lt;p&gt;Since environment variables are strings, and some of our values will be objects of other types, we needed a way to convert these strings into Ruby objects. A preliminary search yielded many options that utilized complicated regular expressions and other gymnastics. There had to be a better way.&lt;/p&gt;
        
        &lt;p&gt;Enter &lt;code&gt;YAML&lt;/code&gt;. It supports serializing the types we needed:&lt;/p&gt;
        
        &lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;irb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;&lt;span class=&quot;mo&quot;&gt;001&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;yaml&amp;#39;&lt;/span&gt;&amp;#x000A;&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;true&lt;/span&gt;&amp;#x000A;&lt;span class=&quot;n&quot;&gt;irb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;&lt;span class=&quot;mo&quot;&gt;002&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;YAML&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;load&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;true&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&amp;#x000A;&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;kp&quot;&gt;true&lt;/span&gt;&amp;#x000A;&lt;span class=&quot;n&quot;&gt;irb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;&lt;span class=&quot;mo&quot;&gt;003&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;YAML&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;load&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;108&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&amp;#x000A;&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;108&lt;/span&gt;&amp;#x000A;&lt;span class=&quot;n&quot;&gt;irb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;&lt;span class=&quot;mo&quot;&gt;004&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;YAML&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;load&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;just a string&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&amp;#x000A;&lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;just a string&amp;quot;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
        
        
        &lt;p&gt;Beautiful.&lt;/p&gt;
      </description>
    </item>
    <item>
      <pubDate>Mon, 27 Aug 2012 08:20:21 +0000</pubDate>
      <guid>http://autonomousmachine.com/posts/2012/8/27/jist-is-a-new-library-to-publish-gists-from-the-ruby-or-the-command-line</guid>
      <link>http://autonomousmachine.com/posts/2012/8/27/jist-is-a-new-library-to-publish-gists-from-the-ruby-or-the-command-line</link>
      <title>Jist is a new library to publish Gists from the Ruby or the command line</title>
    </item>
    <item>
      <pubDate>Wed, 27 Jun 2012 13:44:26 +0000</pubDate>
      <guid>http://autonomousmachine.com/posts/2012/6/27/a-working-fork-of-the-gist-command-line-gem</guid>
      <link>http://autonomousmachine.com/posts/2012/6/27/a-working-fork-of-the-gist-command-line-gem</link>
      <title>A working fork of the Gist command line gem</title>
      <description xml:space='preserve'>
        &lt;p&gt;Adds support for OAuth. To install:&lt;/p&gt;
        
        &lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git clone https://github.com/dr4g0nnn/gist.git&amp;#x000A;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;gist&amp;#x000A;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;gem build gist.gemspec&amp;#x000A;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;gem install gist-3.1.0&lt;/pre&gt;&lt;/div&gt;
        
        
        &lt;p&gt;Hopefully at some point the official repo is brought up to date, but in the meantime, this will allow for command-line Gisting.&lt;/p&gt;
      </description>
    </item>
    <item>
      <pubDate>Wed, 30 May 2012 08:54:37 +0000</pubDate>
      <guid>http://autonomousmachine.com/posts/2012/5/30/troubleshooting-db-push-errors-on-heroku</guid>
      <link>http://autonomousmachine.com/posts/2012/5/30/troubleshooting-db-push-errors-on-heroku</link>
      <title>Troubleshooting db:push errors on Heroku</title>
      <description xml:space='preserve'>
        &lt;p&gt;Here is the error I was seeing today (truncated for brevity):&lt;/p&gt;
        
        &lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;heroku db:push --app&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;my-app-name --confirm&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;my-app-name&amp;#x000A;Loaded Taps v0.3.23&amp;#x000A;Auto-detected &lt;span class=&quot;nb&quot;&gt;local &lt;/span&gt;database: postgres://localhost/app_development?encoding&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;utf8&amp;#x000A;&amp;#x000A;Sending schema&amp;#x000A;Schema:        100% |&lt;span class=&quot;o&quot;&gt;==========================================&lt;/span&gt;| Time: 00:00:29&amp;#x000A;Sending indexes&amp;#x000A;table_1:       100% |&lt;span class=&quot;o&quot;&gt;==========================================&lt;/span&gt;| Time: 00:00:01&amp;#x000A;schema_migrat: 100% |&lt;span class=&quot;o&quot;&gt;==========================================&lt;/span&gt;| Time: 00:00:00&amp;#x000A;table_2:       100% |&lt;span class=&quot;o&quot;&gt;==========================================&lt;/span&gt;| Time: 00:00:00&amp;#x000A;Sending data&amp;#x000A;20 tables, 2,783 records&amp;#x000A;table_3:       0% |                                          | ETA:  --:--:--&amp;#x000A;Saving session to push_201205300813.dat..&amp;#x000A;!!! Caught Server Exception&amp;#x000A;HTTP CODE: 500&amp;#x000A;Taps Server Error: LoadError: no such file to load -- sequel/adapters/&amp;#x000A;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;/app/.bundle/gems/ruby/1.9.1/gems/sequel-3.20.0/lib/sequel/core.rb:249:in `require&amp;#39;&amp;quot;&lt;/span&gt;, ...&lt;/pre&gt;&lt;/div&gt;
        
        
        &lt;p&gt;This was caused by my app not having a &lt;code&gt;DATABASE_URL&lt;/code&gt; config variable set. I assumed that &lt;code&gt;db:push&lt;/code&gt; would fail much earlier if it wasn't able to connect to a database, but this turned out to not be accurate.&lt;/p&gt;
        
        &lt;p&gt;The simple solution was to &lt;a href=&quot;https://devcenter.heroku.com/articles/heroku-postgres-dev-plan#promotion&quot;&gt;promote the existing database&lt;/a&gt;:&lt;/p&gt;
        
        &lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;heroku pg:promote HEROKU_POSTGRESQL_COPPER --app&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;my-app-name&lt;/pre&gt;&lt;/div&gt;
        
        
        &lt;p&gt;To find the name of the database to use in the previous command, use &lt;code&gt;heroku config --app=my-app-name&lt;/code&gt;. It should have a name like &lt;code&gt;HEROKU_POSTGRESQL_*_URL&lt;/code&gt;.&lt;/p&gt;
      </description>
    </item>
    <item>
      <pubDate>Wed, 23 May 2012 07:28:11 +0000</pubDate>
      <guid>http://autonomousmachine.com/posts/2012/5/23/running-ruby-1-9-3-on-heroku-cedar</guid>
      <link>http://autonomousmachine.com/posts/2012/5/23/running-ruby-1-9-3-on-heroku-cedar</link>
      <title>Running Ruby 1.9.3 on Heroku Cedar</title>
      <description xml:space='preserve'>
        &lt;p&gt;Heroku &lt;a href=&quot;http://blog.heroku.com/archives/2012/5/9/multiple_ruby_version_support_on_heroku/&quot;&gt;now supports specifying a Ruby version in an application's Gemfile&lt;/a&gt;:&lt;/p&gt;
        
        &lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;c1&quot;&gt;# Gemfile&lt;/span&gt;&amp;#x000A;&lt;span class=&quot;n&quot;&gt;ruby&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;1.9.3&amp;#39;&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
        
        
        &lt;p&gt;This requires Bundler 1.2.0, which can be installed with the &lt;code&gt;--pre&lt;/code&gt; flag:&lt;/p&gt;
        
        &lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;gem install bundler --pre&lt;/pre&gt;&lt;/div&gt;
        
        
        &lt;p&gt;You also need to move 'bin' to the beginning of your application's PATH so the correct Ruby binary is found when starting your web processes:&lt;/p&gt;
        
        &lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;heroku config:add &lt;span class=&quot;nv&quot;&gt;PATH&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;bin:vendor/bundle/ruby/1.9.1/bin:/usr/local/bin:/usr/bin:/bin --app YOU_APP_NAME&lt;/pre&gt;&lt;/div&gt;
        
        
        &lt;p&gt;Commit the Gemfile changes and push to Heroku, and your app should be running under Ruby 1.9.3!&lt;/p&gt;
      </description>
    </item>
    <item>
      <pubDate>Wed, 16 May 2012 08:41:22 +0000</pubDate>
      <guid>http://autonomousmachine.com/posts/2012/5/16/watch-railsconf-2012-presentations-at-confreaks</guid>
      <link>http://autonomousmachine.com/posts/2012/5/16/watch-railsconf-2012-presentations-at-confreaks</link>
      <title>Watch Railsconf 2012 presentations at ConFreaks</title>
      <description xml:space='preserve'>
        &lt;p&gt;So far I've seen &lt;a href=&quot;http://www.confreaks.com/videos/907-railsconf2012-rails-the-next-five-years&quot;&gt;Yehuda Katz's&lt;/a&gt; and &lt;a href=&quot;http://www.confreaks.com/videos/880-railsconf2012-keynote-i-ve-made-a-huge-mistake&quot;&gt;Aaron Patterson's&lt;/a&gt;, both of which I would recommend.&lt;/p&gt;
        
        &lt;p&gt;Also note that audio-only downloads are offered, which I find convenient as a frequent podcast listener.&lt;/p&gt;
      </description>
    </item>
    <item>
      <pubDate>Wed, 16 May 2012 08:35:05 +0000</pubDate>
      <guid>http://autonomousmachine.com/posts/2012/5/16/a-visual-guide-to-some-advanced-css-selectors</guid>
      <link>http://autonomousmachine.com/posts/2012/5/16/a-visual-guide-to-some-advanced-css-selectors</link>
      <title>A visual guide to some advanced CSS selectors</title>
      <description xml:space='preserve'>&lt;p&gt;Very useful stuff. Some of the most useful are IE9+, but I doubt many will find that surprising.&lt;/p&gt;</description>
    </item>
    <item>
      <pubDate>Sat, 05 May 2012 11:11:43 +0000</pubDate>
      <guid>http://autonomousmachine.com/posts/2012/5/5/use-active-model-serializers-with-mongoid</guid>
      <link>http://autonomousmachine.com/posts/2012/5/5/use-active-model-serializers-with-mongoid</link>
      <title>Use Active Model Serializers with Mongoid</title>
      <description xml:space='preserve'>
        &lt;p&gt;I'm adding some new features to &lt;a href=&quot;http://forkchop.com&quot;&gt;Forkchop&lt;/a&gt; using &lt;a href=&quot;http://emberjs.com/&quot;&gt;Ember&lt;/a&gt;, &lt;a href=&quot;https://github.com/emberjs/ember-rails&quot;&gt;ember-rails&lt;/a&gt;, and the associated &lt;a href=&quot;https://github.com/josevalim/active_model_serializers&quot;&gt;active_model_serializers&lt;/a&gt;. The only hiccup is that I'm using Mongoid, and Active Model Serializers only hooks into Active Record when it loads. This means that Rails doesn't automatically look for the appropriate serializer when using &lt;code&gt;render json: @object&lt;/code&gt;.&lt;/p&gt;
        
        &lt;p&gt;To remedy this, I added the following lines &lt;a href=&quot;https://gist.github.com/2492990&quot;&gt;from this Gist&lt;/a&gt; to &lt;code&gt;config/initializers/mongoid_active_model_initializers&lt;/code&gt;:&lt;/p&gt;
        
        &lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;no&quot;&gt;Mongoid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Document&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:include&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;ActiveModel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;SerializerSupport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&amp;#x000A;&lt;span class=&quot;no&quot;&gt;Mongoid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Criteria&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;delegate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;:active_model_serializer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:to_a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
      </description>
    </item>
    <item>
      <pubDate>Wed, 18 Apr 2012 09:15:51 +0000</pubDate>
      <guid>http://autonomousmachine.com/posts/2012/4/18/github-s-hidden-compare-view</guid>
      <link>http://autonomousmachine.com/posts/2012/4/18/github-s-hidden-compare-view</link>
      <title>GitHub's Hidden Compare View</title>
      <description xml:space='preserve'>&lt;p&gt;One of the hardest to find but most useful GitHub features.&lt;/p&gt;</description>
    </item>
    <item>
      <pubDate>Sat, 24 Mar 2012 21:50:09 +0000</pubDate>
      <guid>http://autonomousmachine.com/posts/2012/3/24/store-hashie-mash-objects-in-mongoid-documents</guid>
      <link>http://autonomousmachine.com/posts/2012/3/24/store-hashie-mash-objects-in-mongoid-documents</link>
      <title>Store Hashie::Mash objects in Mongoid Documents</title>
      <description xml:space='preserve'>
        &lt;p&gt;I've started using &lt;a href=&quot;http://mongoid.org/&quot;&gt;Mongoid&lt;/a&gt;'s &lt;a href=&quot;html&quot;&gt;support for abitrary field types&lt;/a&gt; on a project. It involves working with a lot of nested hashes that are the result of parsing JSON, and I've found wrapping a &lt;a href=&quot;https://github.com/intridea/hashie&quot;&gt;&lt;code&gt;Hashie::Mash&lt;/code&gt;&lt;/a&gt; around these data structures helps keep the code interacting with them clean:&lt;/p&gt;
        
        &lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;doc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;another_key&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;and_another_key&lt;/span&gt;&amp;#x000A;&lt;span class=&quot;c1&quot;&gt;# vs&lt;/span&gt;&amp;#x000A;&lt;span class=&quot;n&quot;&gt;doc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;key&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;another_key&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;][&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;and_another_key&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
        
        
        &lt;p&gt;Since &lt;code&gt;Hashie::Mash&lt;/code&gt; objects are just a subclass of Ruby's standard &lt;code&gt;Hash&lt;/code&gt;, they can be stored in a field that's defined as a &lt;code&gt;Hash&lt;/code&gt; in Mongoid:&lt;/p&gt;
        
        &lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Doc&lt;/span&gt;&amp;#x000A;  &lt;span class=&quot;kp&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Mongoid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Document&lt;/span&gt;&amp;#x000A;  &lt;span class=&quot;n&quot;&gt;field&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Hash&lt;/span&gt;&amp;#x000A;&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
        
        
        &lt;p&gt;But when these documents are loaded back out of the database, the &lt;code&gt;data&lt;/code&gt; field will contain a standard &lt;code&gt;Hash&lt;/code&gt;. I'd like these hashes to be &lt;code&gt;Hashie::Mash&lt;/code&gt; instances. To accomplish this, I defined a new column type for Mongoid called &lt;code&gt;Mashed&lt;/code&gt;:&lt;/p&gt;
        
        &lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Mashed&lt;/span&gt;&amp;#x000A;  &lt;span class=&quot;kp&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Mongoid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Fields&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Serializable&lt;/span&gt;&amp;#x000A;&amp;#x000A;  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;deserialize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&amp;#x000A;    &lt;span class=&quot;no&quot;&gt;Hashie&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Mash&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&amp;#x000A;  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;&amp;#x000A;&amp;#x000A;  &lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;serialize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&amp;#x000A;    &lt;span class=&quot;no&quot;&gt;Hash&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&amp;#x000A;  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;&amp;#x000A;&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
        
        
        &lt;p&gt;That's all that is required to create a new column type in Mongoid, which can be specified just like any other in your document class:&lt;/p&gt;
        
        &lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Doc&lt;/span&gt;&amp;#x000A;  &lt;span class=&quot;kp&quot;&gt;include&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Mongoid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Document&lt;/span&gt;&amp;#x000A;  &lt;span class=&quot;n&quot;&gt;field&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;:data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Mashed&lt;/span&gt;&amp;#x000A;&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
        
        
        &lt;p&gt;Now I can save and load documents with &lt;code&gt;Hashie::Mash&lt;/code&gt; fields. This is a trivally simple example, but by replacing the implementations of &lt;code&gt;deserialize&lt;/code&gt; and &lt;code&gt;serialize&lt;/code&gt; above, just about any kind of object could be persisted in a Mongoid document.&lt;/p&gt;
      </description>
    </item>
    <item>
      <pubDate>Mon, 19 Mar 2012 21:04:29 +0000</pubDate>
      <guid>http://autonomousmachine.com/posts/2012/3/19/requestbin-makes-it-easy-to-debug-web-hooks</guid>
      <link>http://autonomousmachine.com/posts/2012/3/19/requestbin-makes-it-easy-to-debug-web-hooks</link>
      <title>RequestBin makes it easy to debug web hooks</title>
      <description xml:space='preserve'>&lt;p&gt;Useful for debugging anything that makes POST requests. Just point it at RequestBin.&lt;/p&gt;</description>
    </item>
    <item>
      <pubDate>Sat, 17 Mar 2012 21:08:56 +0000</pubDate>
      <guid>http://autonomousmachine.com/posts/2012/3/17/tell-sprockets-to-precompile-files-other-than-application-js</guid>
      <link>http://autonomousmachine.com/posts/2012/3/17/tell-sprockets-to-precompile-files-other-than-application-js</link>
      <title>Tell Sprockets to precompile files other than application.js</title>
      <description xml:space='preserve'>
        &lt;p&gt;I usually bundle all of a Rails project's JavaScript together. Occasionally, only a few pages need a large JavaScript library, and I don't want it to have to be downloaded on every page of the application. In these situations, I don't require the large library file or it's dependencies in &lt;code&gt;application.js&lt;/code&gt; so it won't be bundled with the rest of the project's scripts. I'll add a script tag for the library to just the pages that need it, which works locally in development mode. And then inevitably I deploy and the additional files can't be found on the server because they haven't been precompiled.&lt;/p&gt;
        
        &lt;p&gt;It is &lt;a href=&quot;http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets&quot;&gt;in the docs&lt;/a&gt;, but I always seem to forget that for Sprockets to precompile anything other than &lt;code&gt;application.js&lt;/code&gt;, the additional files must be specifed in &lt;code&gt;config/application.rb&lt;/code&gt;:&lt;/p&gt;
        
        &lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;span class=&quot;n&quot;&gt;config&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;assets&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;precompile&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;another_file.js&amp;#39;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;]&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;
        
        
        &lt;p&gt;That's all there is to it.&lt;/p&gt;
      </description>
    </item>
    <item>
      <pubDate>Sun, 12 Feb 2012 19:15:30 +0000</pubDate>
      <guid>http://autonomousmachine.com/posts/2012/2/12/briefcase-is-a-tool-to-facilitate-keeping-dotfiles-in-git</guid>
      <link>http://autonomousmachine.com/posts/2012/2/12/briefcase-is-a-tool-to-facilitate-keeping-dotfiles-in-git</link>
      <title>Briefcase is a tool to facilitate keeping dotfiles in git.</title>
      <description xml:space='preserve'>&lt;p&gt;I've been using this library for my own dotfiles for the last year. I packaged it up and released it today to see if others would find it useful.&lt;/p&gt;</description>
    </item>
    <item>
      <pubDate>Mon, 06 Feb 2012 07:22:36 +0000</pubDate>
      <guid>http://autonomousmachine.com/posts/2012/2/6/osx-gcc-installer</guid>
      <link>http://autonomousmachine.com/posts/2012/2/6/osx-gcc-installer</link>
      <title>OSX GCC Installer</title>
      <description xml:space='preserve'>&lt;p&gt;Install on top of Mac OS X 10.7 and Xcode 4.2.&lt;/p&gt;</description>
    </item>
    <item>
      <pubDate>Fri, 03 Feb 2012 11:18:50 +0000</pubDate>
      <guid>http://autonomousmachine.com/posts/2012/2/3/vim-find-and-replace-text-across-files</guid>
      <link>http://autonomousmachine.com/posts/2012/2/3/vim-find-and-replace-text-across-files</link>
      <title>Vim: Find and replace text across files</title>
      <description xml:space='preserve'>
        &lt;p&gt;Performing find and replace operations across a project is something I used to do regularly in various editors, but I never took the time to learn how to do it in Vim. I finally learned how to do this today, and it turns out it's easy.&lt;/p&gt;
        
        &lt;p&gt;The article goes into more detail, but here are the basic commands:&lt;/p&gt;
        
        &lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;:args paths/to/search/*&amp;#x000A;:argdo %s/value_to_find/replacement/ge | update&lt;/pre&gt;&lt;/div&gt;
        
        
        &lt;p&gt;The first line sets up what files to perform the search against so it can be scoped to a certain parts of the project. &lt;code&gt;%s&lt;/code&gt; performs the &lt;a href=&quot;http://vim.wikia.com/wiki/Search_and_replace&quot;&gt;substitution&lt;/a&gt;, and &lt;code&gt;update&lt;/code&gt; saves all modified files after performing the replacements.&lt;/p&gt;
      </description>
    </item>
    <item>
      <pubDate>Sat, 07 Jan 2012 18:11:25 +0000</pubDate>
      <guid>http://autonomousmachine.com/posts/2012/1/7/ico-windows-icon-file-format-plugin-for-photoshop</guid>
      <link>http://autonomousmachine.com/posts/2012/1/7/ico-windows-icon-file-format-plugin-for-photoshop</link>
      <title>ICO (Windows Icon) file format plugin for Photoshop</title>
      <description xml:space='preserve'>&lt;p&gt;I don't know why this isn't built into Photoshop at this point, but if you need to work with ICO files, this plugin makes it painless.&lt;/p&gt;</description>
    </item>
    <item>
      <pubDate>Sat, 07 Jan 2012 13:20:07 +0000</pubDate>
      <guid>http://autonomousmachine.com/posts/2012/1/7/creating-an-amazon-iam-user-who-can-access-a-single-s3-bucket</guid>
      <link>http://autonomousmachine.com/posts/2012/1/7/creating-an-amazon-iam-user-who-can-access-a-single-s3-bucket</link>
      <title>Creating An Amazon IAM User Who Can Access A Single S3 Bucket</title>
      <description xml:space='preserve'>&lt;p&gt;&lt;a href=&quot;http://andrewhitchcock.org/?post=325&quot;&gt;Andrew Hitchcock's tutorial&lt;/a&gt; on how to grant an AWS IAM user access to a single S3 bucket saved me a lot of time today. I am in the process of adding image uploading via S3 to &lt;a href=&quot;http://forkchop&quot;&gt;Forkchop&lt;/a&gt;, and I want to have a seperate bucket and corresponding user (and therefore credentials) for each environment.&lt;/p&gt;</description>
    </item>
    <item>
      <pubDate>Sat, 07 Jan 2012 11:32:15 +0000</pubDate>
      <guid>http://autonomousmachine.com/posts/2012/1/7/sourcetree</guid>
      <link>http://autonomousmachine.com/posts/2012/1/7/sourcetree</link>
      <title>SourceTree</title>
      <description xml:space='preserve'>
        &lt;p&gt;I started using &lt;a href=&quot;http://www.sourcetreeapp.com&quot;&gt;SourceTree&lt;/a&gt; a week ago to as a GUI to local Git repositories. I'm comfortable using Git from the command line, but I find a GUI helpful when looking at history or selecting which parts of the current working tree I want to commit.&lt;/p&gt;
        
        &lt;p&gt;It's currently free, but I would pay to use it.&lt;/p&gt;
      </description>
    </item>
    <item>
      <pubDate>Wed, 04 Jan 2012 10:13:34 +0000</pubDate>
      <guid>http://autonomousmachine.com/posts/2012/1/4/understanding-m17n</guid>
      <link>http://autonomousmachine.com/posts/2012/1/4/understanding-m17n</link>
      <title>Understanding M17n</title>
      <description xml:space='preserve'>&lt;p&gt;James Edward Gray II wrote a seven-part series of articles on character encoding in Ruby a few years ago. It is just as relevent today, and it covers just about everything one would need to know about how character encodings work in both Ruby 1.8 and 1.9.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
