<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <title>Knowledge Base</title>
    <description>Remembering every single knowledge</description>
    <link>http://how.itnig.net/facts</link>
    <item>
      <title>Upgrade Devise to 2.0 in Rails 3.2</title>
      <description>&lt;p&gt;During the upgrading process to Rails 3.2, Devise gem was also upgraded and due to that it raises the following warnings when server starts. I'll also show you the links to remove those annoying warnings.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[DEVISE] Devise.case_insensitive_keys is false which is no longer supported. If you want to continue running 
on this mode, please ensure you are not using validatable (you can copy the validations directly to your  
model) and set case_insensitive_keys to an empty array.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Solution: &lt;a href=&quot;https://github.com/plataformatec/devise/issues/1607&quot;&gt;https://github.com/plataformatec/devise/issues/1607&lt;/a&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[DEVISE] Devise.use_salt_as_remember_token is false which is no longer supported. Devise now only uses the 
salt as remember token and the remember_token column can be removed from your models.
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Solution: &lt;a href=&quot;https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0&quot;&gt;https://github.com/plataformatec/devise/wiki/How-To:-Upgrade-to-Devise-2.0&lt;/a&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;[DEVISE] Devise.reset_password_within is nil. Please set this value to an interval (for example, 6.hours) 
and add a reset_password_sent_at field to your Devise models (if they don't have one already).
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Solution: &lt;a href=&quot;https://github.com/plataformatec/devise/issues/1509&quot;&gt;https://github.com/plataformatec/devise/issues/1509&lt;/a&gt;&lt;/p&gt;
</description>
      <publication>Wed, 08 Feb 2012 01:23:49 +0100</publication>
      <author>xeviknal</author>
      <link>http://how.itnig.net/facts/upgrade-devise-to-2-0-in-rails-3-2</link>
      <guid>http://how.itnig.net/facts/upgrade-devise-to-2-0-in-rails-3-2</guid>
    </item>
    <item>
      <title>Upgrade to Rails 3.2.1</title>
      <description>&lt;p&gt;As you may know, Rails 3.2.1 has been released with important improvements of performace. Specially in development environment thanks to &lt;a href=&quot;https://github.com/rails/journey&quot;&gt;Journey engine&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;I have recently faced the task to upgrade some projects to Rails 3.2.1 and I would like to show how I did it. It is easy to proceed.
The main thing I did was change Gemfile as follows:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gem 'rails', '3.2.1'

group :assets do
    gem 'sass-rails', &quot; ~&amp;gt; 3.2.3&quot;
    gem 'coffee-rails', &quot;~&amp;gt; 3.2.1&quot; 
    gem 'uglifier', '&amp;gt;= 1.0.3' 
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Once changed Gemfile, I just ran a&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;bundle update
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;to update properly the gem versions.&lt;/p&gt;

&lt;p&gt;It is also recommended to add couple of new configurations in /config/environtments/development.rb:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict


# Log the query plan for queries taking more than this (works
# with SQLite, MySQL, and PostgreSQL)
config.active_record.auto_explain_threshold_in_seconds = 0.5
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And also it is required to add mass_assignment_sanitizer to /config/environtments/test.rb&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# Raise exception on mass assignment protection for Active Record models
config.active_record.mass_assignment_sanitizer = :strict
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You may notice that Rails 3.2.X requires at least Ruby 1.8.7. Support for all of the previous Ruby versions has been dropped officially and you should upgrade as early as possible. Rails 3.2 is also compatible with Ruby 1.9.2.&lt;/p&gt;

&lt;p&gt;Upgrade was done with just few changes and the benefit is quite huge in terms of development.&lt;/p&gt;
</description>
      <publication>Wed, 08 Feb 2012 01:13:19 +0100</publication>
      <author>xeviknal</author>
      <link>http://how.itnig.net/facts/upgrade-to-rails-3-2-1</link>
      <guid>http://how.itnig.net/facts/upgrade-to-rails-3-2-1</guid>
    </item>
    <item>
      <title>Wicked PDF for Rails 3.1</title>
      <description>&lt;p&gt;I've recently faced the problem to generate PDF files in Rails 3.1. In many projects done with a minor version of Rails we used &lt;a href=&quot;https://github.com/mileszs/wicked_pdf&quot;&gt;wicked_pdf&lt;/a&gt; gem (that use wkhtml2pdf binary to convert html to pdf, as name says) because it make the task easier. It's just render a valid html document but in pdf extension. (More information in their github repository).&lt;/p&gt;

&lt;p&gt;Asset Pipeline in Rails 3.1 make stylesheets and images unreachable for wicked_pdf.&lt;/p&gt;

&lt;p&gt;The fact of using Asset Pipeline in Rails 3.1 makes me change the way to include CSS and Images into Html document. The point is that wicked_pdf cannot reach it using a direct url (like /assets/pageable.css), or even using the rigth way with the helper 'stylesheet_link_tag &quot;pageable&quot;'.&lt;/p&gt;

&lt;p&gt;Digging into that question, I got the solution in the master branch of their gem. Right there in the &lt;a href=&quot;https://github.com/mileszs/wicked_pdf/blob/a6bed6fc94c391c749ae716c2788836118c045a2/lib/wicked_pdf_helper.rb&quot;&gt;wicked_pdf_helper&lt;/a&gt;. As you may see, there are 4 new helpers that embed the content of CSS, JS and Images directly into the html document.&lt;/p&gt;

&lt;p&gt;So the solution is call 'wicked_pdf_stylesheet_link_tag', 'wicked_pdf_image_tag' and 'wicked_pdf_javascript_src_tag'.&lt;/p&gt;

&lt;p&gt;The last point I want to remark is that you has to include the wicked_pdf gem directly from the repository. Otherwise, you will never find those helpful helpers.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gem 'wicked_pdf', :git =&amp;gt; &quot;git://github.com/mileszs/wicked_pdf.git&quot;
&lt;/code&gt;&lt;/pre&gt;
</description>
      <publication>Wed, 08 Feb 2012 01:07:41 +0100</publication>
      <author>xeviknal</author>
      <link>http://how.itnig.net/facts/wicked-pdf-for-rails-3-1</link>
      <guid>http://how.itnig.net/facts/wicked-pdf-for-rails-3-1</guid>
    </item>
    <item>
      <title>Install rb-fsevent gem in a Mac OS X without XCode</title>
      <description>&lt;p&gt;As I do not have XCode installed in my MacBook (because I use &lt;a href=&quot;https://github.com/kennethreitz/osx-gcc-installer&quot;&gt;this wonderful solution&lt;/a&gt;), I recently ran into a problem with rb-fsevent gem installation.&lt;/p&gt;

&lt;p&gt;This gem compiles using some environment stuff that XCode provides, which I didn't have.&lt;/p&gt;

&lt;p&gt;So a solution for using this gem is to switch to the following branch on &lt;em&gt;ttilley&lt;/em&gt; repo:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
gem 'rb-fsevent', :git =&gt; 'git://github.com/ttilley/rb-fsevent.git', :branch =&gt; 'pre-compiled-gem-one-off'
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;And it works!&lt;/p&gt;

&lt;p&gt;From an &lt;a href=&quot;https://github.com/thibaudgg/rb-fsevent/issues/20&quot;&gt;issue in rb-fsevent repository&lt;/a&gt;.&lt;/p&gt;
</description>
      <publication>Tue, 24 Jan 2012 13:02:02 +0100</publication>
      <author>Albert</author>
      <link>http://how.itnig.net/facts/install-rb-fsevent-gem-in-a-mac-os-x-without-xcode</link>
      <guid>http://how.itnig.net/facts/install-rb-fsevent-gem-in-a-mac-os-x-without-xcode</guid>
    </item>
    <item>
      <title>How to install a specific firefox version</title>
      <description>&lt;p&gt;I just faced the problem of having to use firefox 7.0.1 in ubuntu 10.04. Not easy at all! By default it comes with the old 3.6 version. You can install the ubuntu mozilla stable ppa and get a newer version from there, but it's currently providing firefox 9.0.1 and selenium does not support it yet.&lt;/p&gt;

&lt;p&gt;After trying to install a lower version from the ppa, pinning packages and trying to install the download package manually, the only working way I get was to download the source code and execute it directly.&lt;/p&gt;

&lt;p&gt;More consice instructions can be found here:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;http://askubuntu.com/questions/83227/how-can-i-install-a-specific-older-version-of-firefox-and-keep-it-from-automatic
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And you can download the source from the official ftp, for example the mentioned version:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ftp://ftp.mozilla.org/pub/mozilla.org/firefox/releases/7.0.1/linux-i686/en-GB/
&lt;/code&gt;&lt;/pre&gt;
</description>
      <publication>Mon, 26 Dec 2011 20:36:33 +0100</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/how-to-install-a-specific-firefox-version</link>
      <guid>http://how.itnig.net/facts/how-to-install-a-specific-firefox-version</guid>
    </item>
    <item>
      <title>How to avoid intermittent errors on capybara and selenium</title>
      <description>&lt;p&gt;Running selenium specs sometimes it might happen that the test suite is green in our computer, but in the integration server (I've also experienced this issue on Travis) it randomly fails with Capybara ElementNotFound errors or similar, for example:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; Failure/Error: text = page.find(&quot;##{id} input&quot;).value
 Capybara::ElementNotFound:
   Unable to find css &quot;#best_in_place_user_1210_address input&quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;It has been a hard issue to track down, because the real error is a timeout error. It happens that, when executing javascript tests, capybara waits some time before throwing an error (like element not found). When the connection between selenium and firefox is too slow, maybe due to the high system load or anything else, the firefox instance may not respond in time and capybara fails the expectation.&lt;/p&gt;

&lt;p&gt;Incrementing the default timeout may increase the success rate (setting Capybara.default_wait_time to some big number) but it does not solve the issue in any case. I've been googling for this issue and I haven't found any solution, so I come up with a simple one: Retry the test if it fails due to timeout or element not found errors. Add this snippet to some support file:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
def retry_on_timeout(n = 3, &amp;block)
  block.call
rescue Capybara::TimeoutError, Capybara::ElementNotFound =&gt; e
  if n &gt; 0
    puts &quot;Catched error: #{e.message}. #{n-1} more attempts.&quot;
    retry_on_timeout(n - 1, &amp;block)
  else
    raise
  end
end
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Then in your failing spec wrap the code in a retry_on_timeout call:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
retry_on_timeout do
  # your test
end
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;By default it will try the test for 3 times, you can override it by calling it like so: retry_on_timeout(5)&lt;/p&gt;
</description>
      <publication>Sun, 25 Dec 2011 19:46:44 +0100</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/how-to-avoid-intermittent-errors-on-capybara-and-selenium</link>
      <guid>http://how.itnig.net/facts/how-to-avoid-intermittent-errors-on-capybara-and-selenium</guid>
    </item>
    <item>
      <title>How to get access to rails view helpers from rspec support files</title>
      <description>&lt;p&gt;Within the rspec context we already have access to a special method &quot;helper&quot; wich we can use like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;it &quot;should show the price&quot; do
  res = helper.number_to_currency 56
  res.should == &quot;56,00 &#8364;&quot;
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Well, only in the &quot;request&quot; type specs of course. The problem is that this special 'helper' method is not available to our files under the &quot;spec/support&quot; folder. If we want to make use of it from there we have to run our own solution. This is an easy one: Add a new support file with this content:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
def helper
  Helper.instance
end

class Helper
  include Singleton
  include ActionView::Helpers::NumberHelper
  # Include the rest of view helpers you need here
end
&lt;/code&gt;&lt;/pre&gt;

</description>
      <publication>Sat, 17 Dec 2011 18:23:38 +0100</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/how-to-get-access-to-rails-view-helpers-from-rspec-support-files</link>
      <guid>http://how.itnig.net/facts/how-to-get-access-to-rails-view-helpers-from-rspec-support-files</guid>
    </item>
    <item>
      <title>How to add exceptions to basic authentication with nginx</title>
      <description>&lt;p&gt;In staging environments of our websites we usually want to make everything private, but then external calls to our app, as for example paypal IPN calls, won't be able to reach us.&lt;/p&gt;

&lt;p&gt;The solution is a simple nginx configuration:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
server {
    listen 80;
    server_name staging.myapp.com;
    root /my_app_path/current/public;

    location / {
      auth_basic &quot;Restricted&quot;;
      auth_basic_user_file basic_auths/pwd_file;
      passenger_enabled on;
      rails_env staging;
    }

    location /paypal_ipn {
      auth_basic off;
      passenger_enabled on;
      rails_env staging;
    }
}
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;This will hide everything behind the basic authenticated realm except for the /paypal_ipn url.&lt;/p&gt;
</description>
      <publication>Fri, 09 Dec 2011 18:38:04 +0100</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/how-to-add-exceptions-to-basic-authentication-with-nginx</link>
      <guid>http://how.itnig.net/facts/how-to-add-exceptions-to-basic-authentication-with-nginx</guid>
    </item>
    <item>
      <title>How to cast boolean values manually</title>
      <description>&lt;p&gt;We know each database handles boolean values on its own way. Fortunatelly enough ActiveRecord provides an abstraction layer that handles this for us, but sometimes we want to known in a POST action if the given parameters are true or not before actually save the model.&lt;/p&gt;

&lt;p&gt;This is a simple method hidding in ActiveRecord internals to do that:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This is useful for example if we want to make a virtual boolean attribute, defining this in the model:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;def bool_attr=(value)
  @bool_attr = ActiveRecord::ConnectionAdapters::Column.value_to_boolean value
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And using it in the form as a normal attribute:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;= f.check_box :bool_attr
&lt;/code&gt;&lt;/pre&gt;
</description>
      <publication>Fri, 02 Dec 2011 17:39:48 +0100</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/how-to-cast-boolean-values-manually</link>
      <guid>http://how.itnig.net/facts/how-to-cast-boolean-values-manually</guid>
    </item>
    <item>
      <title>How to do complex expectations with RSpec</title>
      <description>&lt;p&gt;The thing what to do if we can set an expectation for a certain object and get control over what it return on two consecutive calls?&lt;/p&gt;

&lt;p&gt;Well, we can easily do something like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;@object.should_receive(:method_name).twice.and_return([1, 2])
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then the first call to &lt;code&gt;@object.method_name&lt;/code&gt; will return 1 and the second one 2.&lt;/p&gt;

&lt;p&gt;But things can get more complicated if we want, for instance, raise and error on the first call and return '43' on the second one. This is a little more tricky to do, but we can acomplish it with:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;@object.should_receive(:method_name).at_most(1).times.and_raise(ArgumentError)
@object.should_receive(:method_name).once.and_return(43)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The first expectation will last only for 1 call, and then the second expectation we make take place again only for 1 run.&lt;/p&gt;

&lt;p&gt;There is an example in this gist: https://gist.github.com/1389066&lt;/p&gt;
</description>
      <publication>Tue, 29 Nov 2011 11:30:03 +0100</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/how-to-do-complex-expectations-with-rspec</link>
      <guid>http://how.itnig.net/facts/how-to-do-complex-expectations-with-rspec</guid>
    </item>
    <item>
      <title>How to disable asset pipeline log</title>
      <description>&lt;p&gt;Only paste the following code in an initializer:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
# Silence asset logger:
#
# http://stackoverflow.com/questions/6312448/how-to-disable-logging-of-asset-pipeline-sprockets-messages-in-rails-3-1
#
# TODO: This patch should be removed when we could use
#
# config.assets.logger = nil
Rails.application.assets.logger = Logger.new('/dev/null')

Rails::Rack::Logger.class_eval do
  def before_dispatch_with_quiet_assets(env)
    before_dispatch_without_quiet_assets(env) unless env['PATH_INFO'].index(&quot;/assets/&quot;) == 0
  end
  alias_method_chain :before_dispatch, :quiet_assets
end
&lt;/code&gt;&lt;/pre&gt;

</description>
      <publication>Mon, 28 Nov 2011 13:33:11 +0100</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/how-to-disable-asset-pipeline-log</link>
      <guid>http://how.itnig.net/facts/how-to-disable-asset-pipeline-log</guid>
    </item>
    <item>
      <title>How to send devise emails through delayed_job</title>
      <description>&lt;p&gt;Original source: http://danseaver.com/blog/2011/10/18/sending-devise-emails-with-delayed-job/&lt;/p&gt;

&lt;p&gt;Note that this would work probably only for devise versions prior to 1.5&lt;/p&gt;
</description>
      <publication>Thu, 24 Nov 2011 16:50:35 +0100</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/how-to-send-devise-emails-through-delayed-job</link>
      <guid>http://how.itnig.net/facts/how-to-send-devise-emails-through-delayed-job</guid>
    </item>
    <item>
      <title>8 formas efectivas de incrementar el n&#250;mero de fans de tu p&#225;gina de Facebook</title>
      <description>&lt;p&gt;http://bit.ly/up1gx0&lt;/p&gt;
</description>
      <publication>Tue, 22 Nov 2011 15:50:21 +0100</publication>
      <author>Jaume</author>
      <link>http://how.itnig.net/facts/8-formas-efectivas-de-incrementar-el-numero-de-fans-de-tu-pagina-de-facebook</link>
      <guid>http://how.itnig.net/facts/8-formas-efectivas-de-incrementar-el-numero-de-fans-de-tu-pagina-de-facebook</guid>
    </item>
    <item>
      <title>Gu&#237;a B&#225;sica SEO</title>
      <description>&lt;p&gt;Aqu&#237; la reducci&#243;n a un Google Doc de la p&#225;gina http://www.forosdelweb.com con la gu&#237;a espec&#237;fica y b&#225;sica del SEO&lt;/p&gt;

&lt;p&gt;https://docs.google.com/a/itnig.net/document/d/1xHSG-B_7MMovCCdS_trhkOsHQVVOPnPubUHMng-KUHI/edit?hl=es&lt;/p&gt;
</description>
      <publication>Tue, 15 Nov 2011 17:27:06 +0100</publication>
      <author>Jaume</author>
      <link>http://how.itnig.net/facts/guia-basica-seo</link>
      <guid>http://how.itnig.net/facts/guia-basica-seo</guid>
    </item>
    <item>
      <title>How to use capybara matchers on regular strings</title>
      <description>&lt;p&gt;Capybara has excelent matchers to test html, look for a certain text, finders, etc. But you can only use them to check the current page, what if you want to use them to check a HTML email for example?&lt;/p&gt;

&lt;p&gt;You can easily do this building a Capybara Node with your original string, example:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
node = Capybara.string email.body.to_s
node.should have_content(&quot;Check for a text&quot;)
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Awesome!&lt;/p&gt;

&lt;p&gt;Original source &lt;a href=&quot;http://robots.thoughtbot.com/post/8087279685/use-capybara-on-any-html-fragment-or-page&quot;&gt;at this thoughbot post&lt;/a&gt;&lt;/p&gt;
</description>
      <publication>Mon, 14 Nov 2011 11:10:42 +0100</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/how-to-use-capybara-matchers-on-regular-strings</link>
      <guid>http://how.itnig.net/facts/how-to-use-capybara-matchers-on-regular-strings</guid>
    </item>
    <item>
      <title>Solving Mac OS X Lion, XCode 4.2 and Ruby</title>
      <description>&lt;p&gt;The other day, I just decided to setup a fresh install of Mac OS X Lion on my early 2009' steel MacBook. It had Mac OS X Leopard on it when I bought it, then I installed Mac OS X Snow Leopard on it later that very summer, and this July I installed Mac OS X Lion on it.&lt;/p&gt;

&lt;p&gt;As you surely know, installing one OS after another is worst than freshly installing it, because some unuseful items are left, the migration process may use workarounds instead of going just on a straight installation, and all provokes a remarkable ralentization of both time and disk space.&lt;/p&gt;

&lt;p&gt;I had been percieving so, and I finally got to freshly install Lion. So I put apart my masthodontic collection of iTunes and iPhoto items, I also saved my personal files, and ran the Lion installer.&lt;/p&gt;

&lt;p&gt;After that, I installed XCode 4.2 (as you are told to develop within Mac OS X), then the Ruby Version Manager (RVM), and began installing rubies: 1.8.7, 1.9.2, and so on. Then I began encountering compilation problems. It appears that XCode 4.2, as opposite to its version 4.1, does not include core libraries, compilers and headers for some rubies to get installed.&lt;/p&gt;

&lt;p&gt;I did a lot of research in the Internet, I applied some patches, but nothing work really straight. Finally I came up with a perfect solution, which consists in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Uninstalling XCode 4.2 with the following (more info in &lt;a href=&quot;http://mymacslife.blogspot.com/2011/01/how-to-uninstall-xcode.html&quot;&gt;here&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;


&lt;pre&gt;&lt;code&gt;
sudo /Library/uninstall-devtools --mode=all
&lt;/code&gt;&lt;/pre&gt;


&lt;ul&gt;
&lt;li&gt;Installing the OS X GCC Installer in &lt;a href=&quot;https://github.com/kennethreitz/osx-gcc-installer&quot;&gt;Kenneth Reitz's repository&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Then install your rubies and everything's gonna be ok.&lt;/p&gt;
</description>
      <publication>Wed, 09 Nov 2011 17:06:31 +0100</publication>
      <author>Albert</author>
      <link>http://how.itnig.net/facts/solving-mac-os-x-lion--xcode-4-2-and-ruby</link>
      <guid>http://how.itnig.net/facts/solving-mac-os-x-lion--xcode-4-2-and-ruby</guid>
    </item>
    <item>
      <title>Inspecting the capybara's webrick log</title>
      <description>&lt;p&gt;Capybara runs by default a webrick server to execute your integration tests, but you have no way to inspect that server log for errors in your application during a test.&lt;/p&gt;

&lt;p&gt;To solve that, you can configure capybara to run your own server, for example:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
Capybara.server do |app, port|
  require 'rack/handler/webrick'
  Rack::Handler::WEBrick.run(app, :Port =&gt; port, :AccessLog =&gt; [], :Logger =&gt; WEBrick::Log::new(Rails.root.join(&quot;log/capybara_test.log&quot;).to_s))
end
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;You can put this code in your &quot;spec_helper.rb&quot;. It's just the same thing capybara does in the background, but specyfing a log file.&lt;/p&gt;

&lt;p&gt;Source info: https://github.com/jnicklas/capybara/issues/329&lt;/p&gt;
</description>
      <publication>Thu, 13 Oct 2011 12:48:41 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/inspecting-the-capybara-s-webrick-log</link>
      <guid>http://how.itnig.net/facts/inspecting-the-capybara-s-webrick-log</guid>
    </item>
    <item>
      <title>Testing on different Ruby versions</title>
      <description>&lt;p&gt;It is quite common that you code working with a specific Ruby version, you run the tests, everything is fine, but then you use that code from another Ruby version and all goes to hell due to incompatibilities with a Ruby version different from the one you used.&lt;/p&gt;

&lt;p&gt;So the solution here is test the code against the different Ruby versions with which you could be using that code. But how can we achieve this? When you run tests like&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
rspec spec/
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;you can only do it with a Ruby version!&lt;/p&gt;

&lt;p&gt;And doing something like&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
rvm use 1.8.7;
rspec spec/;
rvm use 1.8.7-ree;
rspec spec/;
rvm use 1.9.2;
rspec spec/;
rvm use 1.9.3-rc1;
rspec spec/;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;is ugly as hell.&lt;/p&gt;

&lt;p&gt;Solution? &lt;a href=&quot;http://travis-ci.org/&quot;&gt;Travis-CI&lt;/a&gt;. Travis CI is basically an automatic, configurable and powerful building platform.&lt;/p&gt;

&lt;p&gt;I'll explain it via an example. Recently, I wanted to make sure that my &lt;a href=&quot;http://github.com/albertbellonch/fb-localizer&quot;&gt;FB-Localizer&lt;/a&gt; gem worked perfectly with Ruby 1.8.7, 1.8.7-ree, 1.9.2 and 1.9.3-rc1 too. So how did I achieve that?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;I registered myself to Travis CI via my GitHub Account.&lt;/li&gt;
&lt;li&gt;I went to the profile section (up right, let the Profile and Logout links to get down).&lt;/li&gt;
&lt;li&gt;I activated the GitHub project I wanted to use with Travis CI.&lt;/li&gt;
&lt;li&gt;And added a simple yet powerful configuration to the root of my project, which runs the tests on Ruby 1.8.7, 1.8.7-ree, 1.9.2 and 1.9.3-rc1. Here it is:&lt;/li&gt;
&lt;/ul&gt;


&lt;pre&gt;&lt;code&gt;
rvm:
  - 1.8.7
  - 1.8.7-ree # (current default)
  - 1.9.2
  - 1.9.3
script: &quot;bundle exec rspec spec/&quot;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;On the following push to the repository, the Travis CI builder will be launched and you will have the results in your e-mail (the one set in GitHub) shortly after.&lt;/p&gt;

&lt;p&gt;You have more info on Travis CI configuration &lt;a href=&quot;http://about.travis-ci.org/docs/user/build-configuration/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
</description>
      <publication>Sat, 08 Oct 2011 17:09:11 +0200</publication>
      <author>Albert</author>
      <link>http://how.itnig.net/facts/testing-on-different-ruby-versions</link>
      <guid>http://how.itnig.net/facts/testing-on-different-ruby-versions</guid>
    </item>
    <item>
      <title>Mapping Wordpress MU's sites to a primary domain</title>
      <description>&lt;p&gt;Very well explained in &lt;a href=&quot;http://ottopress.com/2010/wordpress-3-0-multisite-domain-mapping-tutorial/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
</description>
      <publication>Fri, 16 Sep 2011 16:01:59 +0200</publication>
      <author>Albert</author>
      <link>http://how.itnig.net/facts/mapping-wordpress-mu-s-sites-to-a-primary-domain</link>
      <guid>http://how.itnig.net/facts/mapping-wordpress-mu-s-sites-to-a-primary-domain</guid>
    </item>
    <item>
      <title>How to enable FTPS for Wordpress autoupdate and autoupgrade feature</title>
      <description>&lt;p&gt;Just take a look &lt;a href=&quot;http://www.jamison.org/2010/12/04/how-to-configure-wordpress-for-automatic-ftps-updates-using-vsftp-in-ubuntu/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
</description>
      <publication>Fri, 16 Sep 2011 14:02:56 +0200</publication>
      <author>Albert</author>
      <link>http://how.itnig.net/facts/how-to-enable-ftps-for-wordpress-autoupdate-and-autoupgrade-feature</link>
      <guid>http://how.itnig.net/facts/how-to-enable-ftps-for-wordpress-autoupdate-and-autoupgrade-feature</guid>
    </item>
    <item>
      <title>Google Alerts: la herramienta de monitorizaci&#243;n</title>
      <description>&lt;p&gt;&lt;b&gt;Google Alerts&lt;/b&gt; es una herramienta de monitorizaci&#243;n muy &#250;til que permite hacer un seguimiento exhaustivo de tu marca y de las tem&#225;ticas afines a ella. Con la velocidad que indexa Google las p&#225;ginas hoy en d&#237;a este servicio es una garant&#237;a de monitorizar las  ya sea en blogs, redes sociales, p&#225;ginas de la competencia y cualquier sitio web que coincida con las keywords o url&#8217;s que hayamos determinado.
Si a&#250;n no conoc&#233;is &lt;a href=&quot;http://www.google.es/alerts&quot;&gt;Google Alerts&lt;/a&gt; no dud&#233;is en probarlo.&lt;/p&gt;
</description>
      <publication>Thu, 15 Sep 2011 00:32:13 +0200</publication>
      <author>sergi</author>
      <link>http://how.itnig.net/facts/google-alerts--la-herramienta-de-monitorizacion</link>
      <guid>http://how.itnig.net/facts/google-alerts--la-herramienta-de-monitorizacion</guid>
    </item>
    <item>
      <title>Solve weird problem with Google Maps</title>
      <description>&lt;p&gt;&lt;a href=&quot;https://groups.google.com/forum/embed/?place=forum/google-maps-js-api-v3&amp;amp;showsearch=true&amp;amp;showpopout=true&amp;amp;parenturl=http://code.google.com/intl/ca-ES/apis/maps/documentation/javascript/forum.html?place%3Dforum/google-maps-js-api-v3#!searchin/google-maps-js-api-v3/infowindow/google-maps-js-api-v3/8dOLhjNQzmo/N_NXknZ3SOoJ&quot;&gt;Check it out&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It was a simple conflict with _base.scss, in which there was:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
img{
  max-width: 100%;
}
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The solution was:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
#map_canvas {
  height: 19em;
  img{
    max-width: none;
  }
}
&lt;/code&gt;&lt;/pre&gt;

</description>
      <publication>Wed, 14 Sep 2011 16:18:42 +0200</publication>
      <author>Albert</author>
      <link>http://how.itnig.net/facts/solve-weird-problem-with-google-maps</link>
      <guid>http://how.itnig.net/facts/solve-weird-problem-with-google-maps</guid>
    </item>
    <item>
      <title>Managewp: Administrar m&#225;s de un blog</title>
      <description>&lt;p&gt;Cuando en un proyecto web se debe administrar m&#225;s de un blog, y en algunos casos decenas o centenares, la gesti&#243;n se complica much&#237;simo si no disponemos de un sistema que nos permita modificarlos todos a la vez.
Managewp nos ofrece la posibilidad de gestionar en un mismo dashboard todos los blogs wordpress que necesitemos, ofreciendo m&#250;ltiples posibilidades muy interesantes, como el posteo, o la creaci&#243;n de p&#225;ginas en varios blogs a la vez, la administraci&#243;n compartida de comentarios, la actualizaci&#243;n de todos los blogs simult&#225;neamente, y muchas m&#225;s opciones que hacen de Managewp una herramienta a tener en cuenta. Si dese&#225;is obtener m&#225;s informaci&#243;n pod&#233;is visitar el &lt;a href=&quot;http://managewp.com/&quot; title=&quot;sitio web managewp&quot;&gt;sitio web oficial&lt;/a&gt; y una &lt;a href=&quot;http://managewp.com/user-guide/&quot; title=&quot;guia de usuario managewp&quot;&gt;gu&#237;a de usuario&lt;/a&gt; bastante recomendable.&lt;/p&gt;
</description>
      <publication>Sun, 11 Sep 2011 20:21:25 +0200</publication>
      <author>sergi</author>
      <link>http://how.itnig.net/facts/managewp--administrar-mas-de-un-blog</link>
      <guid>http://how.itnig.net/facts/managewp--administrar-mas-de-un-blog</guid>
    </item>
    <item>
      <title>Attach file in Capybara + Selenium Webdriver</title>
      <description>&lt;p&gt;When we implement integration tests, it is quite normal to use the &quot;attach_file&quot; method in order to upload a mock file in our test case. And this can be perfectly done in Capybara.&lt;/p&gt;

&lt;p&gt;However, when we use a Javascript driver in Capybara, such as Selenium Webdriver, this specific method won't work (in fact, it is not in the Webdriver implementation!) and we won't be able to attach a file this way.&lt;/p&gt;

&lt;p&gt;In Selenium RC, we can do this using the *chrome mode in the Firefox browser, but since we are using Capybara, the Javascript driver is Selenium Webdriver (version 2, not the RC one!) so this doesn't work for us.&lt;/p&gt;

&lt;p&gt;But there is hope for us! We can use the native method &quot;send_keys&quot; in order to indeed send an array of keys (a string) to that file input we want to fill. So assuming the input has the id &quot;panda_input&quot; and the desired file is in the relative route &quot;../../../../awesome.txt&quot; from this test location, we can simply do:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
find(&quot;#panda_input&quot;).native.send_keys(File.expand_path(&quot;../../../../public/awesome.txt&quot;, __FILE__))
&lt;/code&gt;&lt;/pre&gt;

</description>
      <publication>Wed, 07 Sep 2011 11:44:57 +0200</publication>
      <author>Albert</author>
      <link>http://how.itnig.net/facts/attach-file-in-capybara---selenium-webdriver</link>
      <guid>http://how.itnig.net/facts/attach-file-in-capybara---selenium-webdriver</guid>
    </item>
    <item>
      <title>Replace Firefox with Chrome when using Selenium with Capybara</title>
      <description>&lt;p&gt;Simply add to you spec_helper.rb the following:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
Capybara.register_driver :selenium do |app|
  Capybara::Selenium::Driver.new(app, :browser =&gt; :chrome)
end
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Extracted from &lt;a href=&quot;http://makandra.com/notes/1324-run-selenium-tests-in-chrome-instead-of-firefox&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
</description>
      <publication>Tue, 06 Sep 2011 19:24:01 +0200</publication>
      <author>Albert</author>
      <link>http://how.itnig.net/facts/replace-firefox-with-chrome-when-using-selenium-with-capybara</link>
      <guid>http://how.itnig.net/facts/replace-firefox-with-chrome-when-using-selenium-with-capybara</guid>
    </item>
    <item>
      <title>Testing a downloaded file in Capybara</title>
      <description>&lt;p&gt;Sometimes, in Capybara, it may happen that you want to test that a file you download from a certain link is the right one. But how do you do it?&lt;/p&gt;

&lt;p&gt;You can perform that, as @roger thought very wisely, through MD5. Or whatever hash function you'd like. The sequence of steps would be then:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click the link that downloads the file&lt;/li&gt;
&lt;li&gt;Extract the content of that file&lt;/li&gt;
&lt;li&gt;Hash that content via MD5&lt;/li&gt;
&lt;li&gt;Compare that result with the actual MD5 hash&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Here is an example code, assuming there's a link named &quot;Panda&quot; pointing to your file, and assuming also that the hash of that file (that you must calculate before) is &quot;be860f6d2760CUCA906a9180451d799f&quot;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
click_link &quot;Panda&quot;
hash = `md5 -s '#{page.source}'`.split(&quot;=&quot;).last.strip
hash.should == &quot;be860f6d2760CUCA906a9180451d799f&quot;
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;And you're done!&lt;/p&gt;
</description>
      <publication>Tue, 06 Sep 2011 17:25:42 +0200</publication>
      <author>Albert</author>
      <link>http://how.itnig.net/facts/testing-a-downloaded-file-in-capybara</link>
      <guid>http://how.itnig.net/facts/testing-a-downloaded-file-in-capybara</guid>
    </item>
    <item>
      <title>How to use Google Maps in Facebox</title>
      <description>&lt;p&gt;Using Google Maps in a Facebox container can be kind of tricky if using the Google Maps API directly.&lt;/p&gt;

&lt;p&gt;There's a workaround, though, consisting of an iframe. Assuming we have a HAML template with the Google Maps query in a variable named &quot;position&quot;, we can do something like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
= link_to &quot;Show&quot;, &quot;#map&quot;, :rel =&gt; &quot;facebox&quot;
#map{:style =&gt; &quot;display: none; height: 250px; width: 450px&quot;}
  %iframe{:frameborder =&gt; &quot;0&quot;, :height =&gt; &quot;250&quot;, :width =&gt; &quot;450&quot;, :marginheight =&gt; &quot;0&quot;, 
  :marginwidth =&gt; &quot;0&quot;, :scrolling =&gt; &quot;yes&quot;, 
  :src =&gt; &quot;http://maps.google.es/maps?f=q&amp;source=s_q&amp;hl=ca&amp;geocode=&amp;q=  
  #{position}&amp;aq=&amp;sspn=0.010574,0.01929&amp;vpsrc=0&amp;ie=UTF8&amp;hq=&amp;hnear=
  #{position}&amp;ll=41.407845,2.179842&amp;spn=0.016094,0.038538&amp;z=14&amp;iwloc=A&amp;output=embed&quot;}
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The &quot;map&quot; div won't be displayed at the beginning, but will be shown in a Facebox container when pressing the link.&lt;/p&gt;

&lt;p&gt;And that's it!&lt;/p&gt;

&lt;p&gt;Note: we assume 250x450px, you can obviously use what you want!&lt;/p&gt;
</description>
      <publication>Tue, 30 Aug 2011 12:48:27 +0200</publication>
      <author>Albert</author>
      <link>http://how.itnig.net/facts/how-to-use-google-maps-in-facebox</link>
      <guid>http://how.itnig.net/facts/how-to-use-google-maps-in-facebox</guid>
    </item>
    <item>
      <title>how to use a have_errors RSpec matcher</title>
      <description>&lt;p&gt;I've found a very useful post about a rspec matcher that lets you make expectations about a model's errors. The original source is &lt;a href=&quot;http://solnic.eu/2011/01/14/custom-rspec-2-matchers.html&quot;&gt;this&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The matcher is:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
RSpec::Matchers.define :have_errors_on do |attribute|
  chain :with do |message|
    @message = message
  end

  match do |model|
    model.valid?

    @has_errors = model.errors.has_key?(attribute)

    if @message
      @has_errors &amp;&amp; model.errors[attribute].to_s.include?(@message)
    else
      @has_errors
    end
  end

  failure_message_for_should do |model|
    if @message
      &quot;Validation errors #{model.errors[attribute].inspect} should include #{@message.inspect}&quot;
    else
      &quot;#{model.class} should have errors on attribute #{attribute.inspect}&quot;
    end
  end

  failure_message_for_should_not do |model|
    &quot;#{model.class} should not have an error on attribute #{attribute.inspect}&quot;
  end
end
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;And then you can use it with:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;it { should have_errors_on(:name) }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And check for explicit error messages with:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;it { should have_errors_on(:order).with(&quot;is not allowed&quot;) }
&lt;/code&gt;&lt;/pre&gt;
</description>
      <publication>Fri, 26 Aug 2011 11:46:55 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/how-to-use-a-have-errors-rspec-matcher</link>
      <guid>http://how.itnig.net/facts/how-to-use-a-have-errors-rspec-matcher</guid>
    </item>
    <item>
      <title>Association build with STI</title>
      <description>&lt;p&gt;When you have a has_many / belongs_to relation, the right way to instantiate a new record of the &quot;many&quot; part is this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;@post.comments.build { # a comment params }
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;But this don't work if your Comment model has subclasses, and you want to instantiate a new SubComment instead of a regular Comment. Your models might look like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
class Comment &amp;lt; ActiveRecord::Base
end

class SubComment &amp;lt; Comment
  # Some custom logic for subcomments
end

class Post &amp;lt; ActiveRecord::Base
  has_many :comments
end
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Also, you simply can't create the SubComment instance separately and then add it to the collection, because the '&amp;lt;&amp;lt;' operator will save the object:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;@comment = SubComment.new params[:sub_comment]
@post.comments &amp;lt;&amp;lt; @comment
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The solution I finally found is an undocumented way to add that @comment objct into the collection but without saving it. It's simply:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;@comment = SubComment.new params[:sub_comment]
@post.comments[@post.comments.size]= @comment
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Considering the relation directly as an array you can add it any object.&lt;/p&gt;

&lt;p&gt;Original Sources:
- http://www.simple10.com/rails-3-sti/
- http://coderrr.wordpress.com/2008/04/22/building-the-right-class-with-sti-in-rails/&lt;/p&gt;
</description>
      <publication>Wed, 24 Aug 2011 18:50:56 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/association-build-with-sti</link>
      <guid>http://how.itnig.net/facts/association-build-with-sti</guid>
    </item>
    <item>
      <title>polymorphism and to_param with generic finders</title>
      <description>&lt;p&gt;You all know that in rails we could add a &quot;to_param&quot; method in a model and active_record will use it in order to generate the url for that instance.&lt;/p&gt;

&lt;p&gt;But, in the order hand, if we do this for a given model we also need to take care of any controller that expect to find an instance of that model (if we don't want that ugly id prefix in the url).&lt;/p&gt;

&lt;p&gt;For instance, if we have a model &quot;Person&quot; with a &lt;em&gt;name&lt;/em&gt; attribute, we probably want to add a new &lt;em&gt;name_url&lt;/em&gt; attribute that keeps the name in a url-sanitized way,&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
class Person &amp;lt; ActiveRecord::Base
  before_save :set_name_url

  def to_param
    name_url
  end

private
  def set_name_url
    return unless name_changed?

    self.name_url = name.downcase.to_ascii.gsub(/[^[:alnum:]]/,'-')
  end

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


&lt;p&gt;You have more information about this &lt;a href=&quot;http://how.itnig.net/facts/com-fer-urls-maques-sense-la-part-del-id-del-model&quot;&gt;in this other fact&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;But, as you can see, now in the PeopleController we must fetch our records like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Person.find_by_name_url! params[:id]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;insted of:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Person.find params[:id]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The problem this fact is about comes when you want to play with metaprogramming and/or polymorphism along with all of this.&lt;/p&gt;

&lt;p&gt;If you have a situation when a controller have to do some work with an arbitrary class, you don't know how to fetch a record for that class if one of them could have a custom &lt;em&gt;to_param&lt;/em&gt; as we shown before. Something like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
# Generic images controller that can work with images belonging to any other class, in a polymorphic relation.
ImagesController &amp;lt; ApplicationController
  # Some stuff here

  def get_target
    params.each do |name, value|
      if name =~ /(.+)_id$/
        return $1.classify.constantize.find(value)
      end
    end
    nil
  end
end
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;We need to know how to fetch records from a particular class. A simple solution I show you here is define a new method in the class:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
class Person &amp;lt; ActiveRecord::Base
  def self.find_by
    :find_by_name_url!
  end
end
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;And then use it to know how to fetch the records:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    klass = $1.classify.constantize
    if klass.respond_to?(:find_by)
      return klass.send(klass.find_by.to_sym, value)
    else
      return klass.find(value)
    end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This is a sort of &lt;em&gt;to_param&lt;/em&gt; opposite functionality.&lt;/p&gt;
</description>
      <publication>Fri, 12 Aug 2011 13:27:25 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/polymorphism-and-to-param-with-generic-finders</link>
      <guid>http://how.itnig.net/facts/polymorphism-and-to-param-with-generic-finders</guid>
    </item>
    <item>
      <title>How to limit access to a specific bucket un s3</title>
      <description>&lt;p&gt;We got a s3 account with some buckets, and want to use one of them as a place to share with others.&lt;/p&gt;

&lt;p&gt;So first we need to create a new user from the AWS IAM console and be sure to save in a safe place the access key and secret key for that new user. Dot no provide him with a password, otherwise that user will be able to log into the AWS Management Console.&lt;/p&gt;

&lt;p&gt;Then assign that user a new custom policy to setup their permissions, this is the tricky part, but using the following json policy you should be ready to go:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
{
  &quot;Statement&quot;: [
    {
      &quot;Effect&quot;: &quot;Allow&quot;,
      &quot;Action&quot;: [
        &quot;s3:ListBucket&quot;,
        &quot;s3:GetBucketLocation&quot;,
        &quot;s3:ListBucketMultipartUploads&quot;
      ],
      &quot;Resource&quot;: &quot;arn:aws:s3:::itnighq&quot;,
      &quot;Condition&quot;: {}
    },
    {
      &quot;Effect&quot;: &quot;Allow&quot;,
      &quot;Action&quot;: [
        &quot;s3:AbortMultipartUpload&quot;,
        &quot;s3:DeleteObject&quot;,
        &quot;s3:DeleteObjectVersion&quot;,
        &quot;s3:GetObject&quot;,
        &quot;s3:GetObjectAcl&quot;,
        &quot;s3:GetObjectVersion&quot;,
        &quot;s3:GetObjectVersionAcl&quot;,
        &quot;s3:PutObject&quot;,
        &quot;s3:PutObjectAcl&quot;,
        &quot;s3:PutObjectAclVersion&quot;
      ],
      &quot;Resource&quot;: &quot;arn:aws:s3:::itnighq/*&quot;,
      &quot;Condition&quot;: {}
    },
    {
      &quot;Effect&quot;: &quot;Allow&quot;,
      &quot;Action&quot;: &quot;s3:ListAllMyBuckets&quot;,
      &quot;Resource&quot;: &quot;*&quot;,
      &quot;Condition&quot;: {}
    }
  ]
}
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Also you can find this answer in this stackoverflow question:&lt;/p&gt;

&lt;p&gt;http://stackoverflow.com/questions/6615168/s3-policy-limiting-access-to-only-one-bucket-listing-included/6955864#6955864&lt;/p&gt;
</description>
      <publication>Fri, 05 Aug 2011 14:07:18 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/how-to-limit-access-to-a-specific-bucket-un-s3</link>
      <guid>http://how.itnig.net/facts/how-to-limit-access-to-a-specific-bucket-un-s3</guid>
    </item>
    <item>
      <title>Autotest Capybara tests</title>
      <description>&lt;p&gt;The first entry on&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.arailsdemo.com/posts/41&quot;&gt;http://www.arailsdemo.com/posts/41&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;worked on me. I'm on Camaloon, using:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ruby EE 1.8.7&lt;/li&gt;
&lt;li&gt;Rails 3.0.3&lt;/li&gt;
&lt;li&gt;RSpec-Rails 2.5.0&lt;/li&gt;
&lt;li&gt;Capybara 0.4.1.2&lt;/li&gt;
&lt;li&gt;Autotest-rails 4.1.0&lt;/li&gt;
&lt;/ul&gt;

</description>
      <publication>Wed, 03 Aug 2011 11:04:35 +0200</publication>
      <author>Albert</author>
      <link>http://how.itnig.net/facts/autotest-capybara-tests</link>
      <guid>http://how.itnig.net/facts/autotest-capybara-tests</guid>
    </item>
    <item>
      <title>On devise, allow edition without password</title>
      <description>&lt;p&gt;&lt;a href=&quot;https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-account-without-providing-a-password&quot;&gt;https://github.com/plataformatec/devise/wiki/How-To:-Allow-users-to-edit-their-account-without-providing-a-password&lt;/a&gt;&lt;/p&gt;
</description>
      <publication>Tue, 02 Aug 2011 18:44:53 +0200</publication>
      <author>Albert</author>
      <link>http://how.itnig.net/facts/on-devise--allow-edition-without-password</link>
      <guid>http://how.itnig.net/facts/on-devise--allow-edition-without-password</guid>
    </item>
    <item>
      <title>How to test and retrieve mails in testing</title>
      <description>&lt;p&gt;When you set Rails' mails delivery method to test, by doing the following in your environments/[environment].rb:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
config.action_mailer.delivery_method = :test
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;mails are not send but kept in an internal array. So how can you access this array? Just use:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
ActionMailer::Base.deliveries
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;For example, you execute some method that sends a mail and you want to check some data on that mail. ANd how do you do that? Simply:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
awesome_method_that_sends_a_mail
sent_mail = ActionMailer::Base.deliveries.last
&lt;/code&gt;&lt;/pre&gt;

</description>
      <publication>Tue, 02 Aug 2011 17:34:45 +0200</publication>
      <author>Albert</author>
      <link>http://how.itnig.net/facts/how-to-test-and-retrieve-mails-in-testing</link>
      <guid>http://how.itnig.net/facts/how-to-test-and-retrieve-mails-in-testing</guid>
    </item>
    <item>
      <title>When to use reset_column_information in migrations</title>
      <description>&lt;p&gt;Usually when we want to change data from our migrations we can do it directly:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
def self.up
  add_column :products, :name

  Product.all.each do |p|
    p.name = &quot;Default&quot;
    p.save!
  end
end
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The problem comes when you want to skip the default AR setter and use the form &quot;product[:name]&quot;, here is where you must update the column information to avoid this kind of error:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
undefined method `column' for nil:NilClass
/home/roger/.rvm/gems/ruby-1.8.7-p352/gems/activesupport-3.0.3/lib/active_support/whiny_nil.rb:48:in `method_missing'
/home/roger/.rvm/gems/ruby-1.8.7-p352/gems/arel-2.0.9/lib/arel/nodes/unqualified_column.rb:8:in `column'
/home/roger/.rvm/gems/ruby-1.8.7-p352/gems/arel-2.0.9/lib/arel/visitors/to_sql.rb:250:in `visit_Arel_Nodes_Assignment'
/home/roger/.rvm/gems/ruby-1.8.7-p352/gems/arel-2.0.9/lib/arel/visitors/visitor.rb:15:in `send'
/home/roger/.rvm/gems/ruby-1.8.7-p352/gems/arel-2.0.9/lib/arel/visitors/visitor.rb:15:in `visit'
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;The new version looks like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
def self.up
  add_column :products, :name
  Product.reset_column_information

  Product.all.each do |p|
    p[:name] = &quot;Default&quot;
    p.save!
  end
end
&lt;/code&gt;&lt;/pre&gt;

</description>
      <publication>Mon, 01 Aug 2011 13:33:31 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/when-to-use-reset-column-information-in-migrations</link>
      <guid>http://how.itnig.net/facts/when-to-use-reset-column-information-in-migrations</guid>
    </item>
    <item>
      <title>How to get plain text from ckeditor</title>
      <description>&lt;p&gt;If you want to get the raw text written inside a ckeditor, a simple &quot;strip_tags&quot; won't work. We also need to get rid of the entire  tags.&lt;/p&gt;

&lt;p&gt;Here is a helper that will do the trick:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
  def clear_ckeditor(text)
    raw strip_tags text.gsub(/\n/, &quot;&quot;).gsub(//, &quot;&quot;).gsub(//, &quot;&quot;)
  end
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Wait! The previous version is incorrect because of some bugs in knowledge base itself. Here is the correct raw line:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;raw strip_tags text.gsub(/\n/, &quot;&quot;).gsub(/&amp;lt;style.*&amp;lt;\/style&amp;gt;/, &quot;&quot;).gsub(/&amp;lt;javascript.*&amp;lt;\/javascript&amp;gt;/, &quot;&quot;)
&lt;/code&gt;&lt;/pre&gt;
</description>
      <publication>Fri, 29 Jul 2011 13:06:17 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/how-to-get-plain-text-from-ckeditor</link>
      <guid>http://how.itnig.net/facts/how-to-get-plain-text-from-ckeditor</guid>
    </item>
    <item>
      <title>How to disable asset's url timestamps in Rails</title>
      <description>&lt;p&gt;By default, Rails appends a timestamp, like this&lt;/p&gt;

&lt;p&gt;&amp;lt;... src=&quot;/images/supercuca.png?123435233151&quot;/&gt;&lt;/p&gt;

&lt;p&gt;But this practice is not good when we work in production, as intermediate servers doesn't cache assets with a &quot;?&quot; in its URL. If you want Rails not to append the interrogation symbol and the timestamp, just add, in config/environment.rb:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
ENV['RAILS_ASSET_ID'] = ''
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;before initializing the app.&lt;/p&gt;

&lt;p&gt;Seen &lt;a href=&quot;http://blog.patrick-morgan.net/2008/02/how-to-disable-asset-timestamps-in.html&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
</description>
      <publication>Wed, 27 Jul 2011 17:03:11 +0200</publication>
      <author>Albert</author>
      <link>http://how.itnig.net/facts/how-to-disable-asset-s-url-timestamps-in-rails</link>
      <guid>http://how.itnig.net/facts/how-to-disable-asset-s-url-timestamps-in-rails</guid>
    </item>
    <item>
      <title>how to run migrations with no downtime</title>
      <description>&lt;p&gt;Very useful tips about this topic you can find here: http://pedro.herokuapp.com/past/2011/7/13/rails_migrations_with_no_downtime/&lt;/p&gt;
</description>
      <publication>Thu, 14 Jul 2011 20:29:58 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/how-to-run-migrations-with-no-downtime</link>
      <guid>http://how.itnig.net/facts/how-to-run-migrations-with-no-downtime</guid>
    </item>
    <item>
      <title>Com fer servir tsung</title>
      <description>&lt;p&gt;Nota previa: Escric aixo en catala per anar rapid perque no vull perdre massa temps ara, i l'entrada sera escueta. Mes endavant aixo es pot expandir.&lt;/p&gt;

&lt;p&gt;Tsung es un software per fer proves de stress a un servidor, permet provar diferents protocols i serveis com postgres, mysql, xmpp, ldap, pero ara jo l'he fet servir per provar contra un servidor web, per http.&lt;/p&gt;

&lt;p&gt;Esta mantingut (ultima versio del 2010) pero la seva &lt;a href=&quot;http://tsung.erlang-projects.org/user_manual.html&quot;&gt;documentacio&lt;/a&gt; es molt p&#232;ssima. El programa per&#242; esta for&#231;a be aixi que optarem per continuar utilitzant-lo.&lt;/p&gt;

&lt;p&gt;La base del programa es tan facil com tenir un arxiu &quot;tsung.xml&quot; que descriu les accions que es faran, executar la prova, i obtenir-ne despres un arxiu de report.&lt;/p&gt;

&lt;h1&gt;Instalacions&lt;/h1&gt;

&lt;pre&gt;&lt;code&gt;sudo apt-get install tsung gnuplot-nox libtemplate-perl
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;A part del propi tsung, els altres paquets son necesaris per generar els reports amb imatges i amb HTML sota ubuntu. Amb altres plataformes no s&#233; com anira aixo (vease MacOsX). Tamb&#233; ser&#224; necesari tenir perl.&lt;/p&gt;

&lt;h1&gt;Generar l'arxiu de descripcio tsung.xml&lt;/h1&gt;

&lt;p&gt;Quant executes &quot;tsung start&quot; per comen&#231;ar la prova, per defecte es llegeix l'arxiu &lt;em&gt;~/.tsung/tsung.xml&lt;/em&gt; i si es vol un altre, utilitza la opcio -f. A continuacio hi ha un exemple base d'aquest arxiu:&lt;/p&gt;

&lt;p&gt;&amp;lt;?xml version=&quot;1.0&quot;?&gt;
&amp;lt;!DOCTYPE tsung SYSTEM &quot;/usr/share/tsung/tsung-1.0.dtd&quot; [] &gt;

  &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;client host=&quot;localhost&quot; use_controller_vm=&quot;true&quot;/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;  &lt;/p&gt;

&lt;p&gt;  &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;server host=&quot;fasttriatlon.itnig.net&quot; port=&quot;80&quot; type=&quot;tcp&quot;&amp;gt;&amp;lt;/server&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;  &lt;/p&gt;

&lt;p&gt;  &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;monitor host=&quot;fasttriatlon.itnig.net&quot; type=&quot;munin&quot;/&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;  &lt;/p&gt;

&lt;p&gt;  &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;arrivalphase phase=&quot;1&quot; duration=&quot;3&quot; unit=&quot;minute&quot;&amp;gt;
  &amp;lt;users interarrival=&quot;1&quot; unit=&quot;second&quot;/&amp;gt;
&amp;lt;/arrivalphase&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;  &lt;/p&gt;

&lt;p&gt;  &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;// Afegeix aqui la teva sessio
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;  
&lt;/p&gt;

&lt;p&gt;Tsung es distribuit, de manera que pots fer proves molt potents utilitzant 2 o 3 ordinadors a la vegada per fer la prova contra un servidor remot. La part de  defineix aixo, per fero facil nomes el nostre. La part de  defineix l'objectiu de la prova, en pots ficar m&#233;s d'un si la teva app esta distribuida en uns quants.&lt;/p&gt;

&lt;p&gt; es per definir com anir&#224; la prova, pots posar diferents fases amb una duracio per cada un, i quants &quot;usuaris&quot; es generaran i a quin ritme per cada fase. Sempre que es genera un &quot;usuari&quot;, aquest escull una de les sessions que existeixen i l'executa.&lt;/p&gt;

&lt;p&gt;Finalment a  hi ha totes les &quot;sessions&quot; preparades per executar-se. La definicio d'una sessio es algo com aixo:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;session name='rec20110714-10:44' probability='100'  type='ts_http'&amp;gt;
&amp;lt;/session&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;La part de &quot;probability&quot; es la probabilitat que un usuari creat agafi aquesta sessi&#243;. La suma de totes les existents ha de donar 100%.&lt;/p&gt;

&lt;p&gt;Una sessi&#243; es un flux simulat d'un usuari per la p&#224;gina. Cont&#233; un sequit de requests a la url que tu vulguis, i tamb&#233; pot incloure delays per simnular una navegabilitat m&#233;s realista. Si vols, pots escriure la sessio tu mateix per&#242; resulta molt m&#233;s comode utilitzar un software que incorpora Tsung, que et permet generar una sessio a partir de &lt;em&gt;enregistrar&lt;/em&gt; el que tu fas amb el teu navegador habitual.&lt;/p&gt;

&lt;h1&gt;Enregistrament de sesions automatic&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Executa &lt;em&gt;tsung-recorder start&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Ara tindr&#224;s un proxy corrent al pc, per defecte pel port 8090. Obre el navegador que vugluis i configura'l perque es conecti a la xarxa a traves d'aquest proxy.&lt;/li&gt;
&lt;li&gt;Ara navega una mica, i cada request que es faci s'enregistrar&#224; en un arxiu .xml amb el format de sessi&#243; de tsung.&lt;/li&gt;
&lt;li&gt;Ara agafa el contingut de l'arxiu generat i fical dins de l'apartat  que comentavem abans, i ja tindr&#224;s la teva sessio.&lt;/li&gt;
&lt;li&gt;Es recomanable sempre editar una mica l'arxiu enregistrat, que pot contenir coses que no volem.&lt;/li&gt;
&lt;/ul&gt;


&lt;h1&gt;Execuci&#243; de tsung&lt;/h1&gt;

&lt;pre&gt;&lt;code&gt;tsung start -f /path/to/tsung_config.xml
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Quant acabi d'executar-se tot el test, acabar&#224; creant una carpeta que conte tots els seus resultats. Per defecte ho guarda per exemple a: ~/.tsung/log/20110714-12:07 (amb un timestamp).&lt;/p&gt;

&lt;h1&gt;Generacio dels reports&lt;/h1&gt;

&lt;pre&gt;&lt;code&gt;cd ~/.tsung/log/20110714-12:07
/usr/lib/tsung/bin/tsung_stats.pl 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Ves dins la carpeta dels resultats d'un test, i executa aquest script que ve amb tsung. A ubuntu est&#224; situat a /usr/lib/tsung/bin/. Aixo generar&#224; uns quants arxius m&#233;s, imatges, i dos arxius .html amb els resultats. Se fin&#237;!. Si dona algun error, es que et falta alguna llibreria per instalar al teu sistema.&lt;/p&gt;
</description>
      <publication>Thu, 14 Jul 2011 16:19:19 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/com-fer-servir-tsung</link>
      <guid>http://how.itnig.net/facts/com-fer-servir-tsung</guid>
    </item>
    <item>
      <title>How to discover active hosts in a network</title>
      <description>&lt;p&gt;In order to discover the responsive hosts inside a network, run the following nmap command:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;nmap -sP 192.168.0.1-254
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note that some computers may be configured not to respond broadcasts ping's, thus this method will not identify them.&lt;/p&gt;

&lt;p&gt;Original source: http://linuxcommando.blogspot.com/2008/05/ping-or-nmap-to-identify-machines-on.html&lt;/p&gt;
</description>
      <publication>Fri, 08 Jul 2011 09:44:19 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/how-to-discover-active-hosts-in-a-network</link>
      <guid>http://how.itnig.net/facts/how-to-discover-active-hosts-in-a-network</guid>
    </item>
    <item>
      <title>hashtweeps</title>
      <description>&lt;p&gt;Esta es una herramienta muy sencilla de utilizar que te permite encontrar los &#250;ltimos tweets y tweeters de cualquier tema o hashtag. Esta herramienta genera una lista de todos los usuarios que participan en el tema, as&#237; como el n&#250;mero total de tweets que ha recibido.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://hashtweeps.com/&quot;&gt;hashtweeps&lt;/a&gt;&lt;/p&gt;
</description>
      <publication>Fri, 01 Jul 2011 17:07:17 +0200</publication>
      <author>sergi</author>
      <link>http://how.itnig.net/facts/hashtweeps</link>
      <guid>http://how.itnig.net/facts/hashtweeps</guid>
    </item>
    <item>
      <title>How to invite people to Google+</title>
      <description>&lt;p&gt;If you want invite people to test the brand new Google social network, called Google+ or Google Plus, you can do it. But the way to achieve that is kind of... tricky!&lt;/p&gt;

&lt;p&gt;One of the places in which to discover how to achieve that is: &lt;a href=&quot;http://www.omicrono.com/2011/06/truco-como-conseguir-invitaciones-para-google/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You'e welcome!&lt;/p&gt;

&lt;p&gt;Note: You obviously have to be already in Google+ :)&lt;/p&gt;
</description>
      <publication>Thu, 30 Jun 2011 16:34:47 +0200</publication>
      <author>Albert</author>
      <link>http://how.itnig.net/facts/how-to-invite-people-to-google-</link>
      <guid>http://how.itnig.net/facts/how-to-invite-people-to-google-</guid>
    </item>
    <item>
      <title>Herramienta: Seguimiento enlaces salientes y Pr</title>
      <description>&lt;p&gt;La siguiente herramienta online, te permite analizar el n&#250;mero total de enlaces salientes de una p&#225;gina web, as&#237; como te muestra el valor real y actualizado del PageRank de cada p&#225;gina enlazada.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.tools-live.com/enlaces-salientes.html&quot;&gt;herramienta enlaces salientes&lt;/a&gt;&lt;/p&gt;
</description>
      <publication>Thu, 30 Jun 2011 13:03:03 +0200</publication>
      <author>sergi</author>
      <link>http://how.itnig.net/facts/herramienta--seguimiento-enlaces-salientes-y-pr</link>
      <guid>http://how.itnig.net/facts/herramienta--seguimiento-enlaces-salientes-y-pr</guid>
    </item>
    <item>
      <title>How to handle trailing slash redirects</title>
      <description>&lt;p&gt;In order to make our SEO friends happy, we need to take care of the trailing slashes in our app's routes... I know, it's a pain in the ass, but it seems that it matters somehow...&lt;/p&gt;

&lt;p&gt;We need to make these redirects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;/something/ -&gt; /something&lt;/li&gt;
&lt;li&gt;/a/foo///   -&gt; /a/foo&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;A simple solution I've found to handle this in our Rails app (or any Rack app) is to create a rack middleware like this:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
class TrailingSlashes
  def initialize(app)
    @app = app
  end

  def call(env)
    if env['PATH_INFO'] != &quot;&quot; &amp;&amp; env['PATH_INFO'] != &quot;/&quot; &amp;&amp; env['REQUEST_URI'] =~ /(.*[^\/])\/+$/
      [301, {&quot;Location&quot; =&gt; $1}, &quot;&quot;]
    else
      @app.call(env)
    end
  end
end
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;If we are in Rails we can put this into a &quot;trailing_slashes.rb&quot; file and drop it into /lib/middlewares/ for instance. Then, require the file from one of your initializers &lt;code&gt;require 'middlewares/trailing_slashes'&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Lastly, we need to make use of this middleware in our application.rb (since we want this  functionality in all environments):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# application.rb
config.middleware.use &quot;TrailingSlashes&quot;
&lt;/code&gt;&lt;/pre&gt;
</description>
      <publication>Thu, 30 Jun 2011 10:18:50 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/how-to-handle-trailing-slash-redirects</link>
      <guid>http://how.itnig.net/facts/how-to-handle-trailing-slash-redirects</guid>
    </item>
    <item>
      <title>Herramienta para encontrar Hashtags</title>
      <description>&lt;p&gt;Hay una herramienta llamada &lt;a href=&quot;http://whathashtag.circulorojo.es/&quot;&gt;Whathashtag&lt;/a&gt; que permite encontrar los hashtags que nos interesen con m&#225;s participaci&#243;n. Su uso es muy simple ya que funciona como un buscador normal y corriente.&lt;/p&gt;
</description>
      <publication>Wed, 29 Jun 2011 19:29:52 +0200</publication>
      <author>sergi</author>
      <link>http://how.itnig.net/facts/herramienta-para-encontrar-hashtags</link>
      <guid>http://how.itnig.net/facts/herramienta-para-encontrar-hashtags</guid>
    </item>
    <item>
      <title>Traspasar contactos de Facebook a Gmail</title>
      <description>&lt;p&gt;&lt;b&gt;Friends to gmail&lt;/b&gt; permite precisamente esto, poder importar los datos de Facebook a Gmail. Esta aplicaci&#243;n web convierte la informaci&#243;n de los contactos de Facebook en un documento CSV.&lt;/p&gt;

&lt;p&gt;Con un metodo muy sencillo y usable nos permite esta aplicaci&#243;n realizar una migraci&#243;n de distintos datos relevantes a Gmail. Pr&#243;ximamente contaremos como migrar la informaci&#243;n de Facebook a un software de e-news como podr&#237;a ser &lt;b&gt;Mailchimp&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.friendstogmail.com/&quot;&gt;Friends to gmail&lt;/a&gt;&lt;/p&gt;
</description>
      <publication>Tue, 28 Jun 2011 20:14:49 +0200</publication>
      <author>sergi</author>
      <link>http://how.itnig.net/facts/traspasar-contactos-de-facebook-a-gmail</link>
      <guid>http://how.itnig.net/facts/traspasar-contactos-de-facebook-a-gmail</guid>
    </item>
    <item>
      <title>SWIFFY: Convertir archivos SWF Flash en Html5</title>
      <description>&lt;p&gt;Todo empez&#243; el verano pasado, donde un ingeniero llamado &lt;b&gt;Pieter Senster&lt;/b&gt; se uni&#243; al departamento de publicidad m&#243;vil de Google, para explorar c&#243;mo podemos mostrar animaciones Flash en dispositivos que no soportan Adobe Flash Player. Sus progresos fueron tan buenos que montaron un equipo para desarrollar lo que hoy ha nacido bajo el nombre de Swiffy, un nuevo regalo de Google labs.&lt;/p&gt;

&lt;p&gt;Puede cargar un archivo SWF, produciendo una versi&#243;n en HTML 5, que se ejecutar&#225; en los navegadores con un alto nivel de soporte SVG, como son Chrome y Safari. Todav&#237;a es una versi&#243;n embrionaria, por lo que no va a convertir todo el contenido de Flash, pero ya funciona bien en los anuncios y animaciones.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://swiffy.googlelabs.com/&quot; title=&quot;Swiffy para convertir flash en html5&quot;&gt;Swiffy&lt;/a&gt;&lt;/p&gt;
</description>
      <publication>Tue, 28 Jun 2011 19:58:42 +0200</publication>
      <author>sergi</author>
      <link>http://how.itnig.net/facts/swiffy--convertir-archivos-swf-flash-en-html5</link>
      <guid>http://how.itnig.net/facts/swiffy--convertir-archivos-swf-flash-en-html5</guid>
    </item>
    <item>
      <title>Redirecci&#243;n 301 y 302</title>
      <description>&lt;p&gt;Redirecci&#243;n 301: Es una redirecci&#243;n permanente. Google traslada a la nueva URL la autoridad y relevancia que la anterior ten&#237;a.&lt;/p&gt;

&lt;p&gt;Redirecci&#243;n 302: Es una redirecci&#243;n temporal, sin que Google traspase relevancia.&lt;/p&gt;

&lt;p&gt;En el siguiente art&#237;culo se especifican las diferencias entre ellas:&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://www.e-interactive.es/blog/redireccion-301-y-302/&quot;&gt;Redirecci&#243;n 301 y 302&lt;/a&gt;&lt;/p&gt;
</description>
      <publication>Mon, 20 Jun 2011 20:22:51 +0200</publication>
      <author>sergi</author>
      <link>http://how.itnig.net/facts/redireccion-301-y-302</link>
      <guid>http://how.itnig.net/facts/redireccion-301-y-302</guid>
    </item>
    <item>
      <title>Utilitzar CSV amb strings UTF-8</title>
      <description>&lt;p&gt;Quan fas servir la llibreria CSV (per defecte a ruby 1.9.2, o sin&#243; fent servir fastercsv) els strings que genera no estan codificats com a UTF-8, sin&#243; com a #&amp;lt;Encoding:ASCII-8BIT&gt;.&lt;/p&gt;

&lt;p&gt;Per fer la conversi&#243; simplement s'ha d'aplicar el &quot;force_encoding&quot; a tots els strings obtinguts, per exemple:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;PROVINCES[row.last.to_i] = row.first.force_encoding(&quot;utf-8&quot;)
&lt;/code&gt;&lt;/pre&gt;
</description>
      <publication>Mon, 20 Jun 2011 17:27:40 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/utilitzar-csv-amb-strings-utf-8</link>
      <guid>http://how.itnig.net/facts/utilitzar-csv-amb-strings-utf-8</guid>
    </item>
    <item>
      <title>Com treballar directament amb memcached</title>
      <description>&lt;p&gt;Si vols tenir un control m&#233;s real o directe de la info que hi ha a memcached, l'unica interf&#237;cie que dona memcached de per si &#233;s telnet.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;telnet localhost 11211
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Aqu&#237; hi ha &lt;a href=&quot;http://lzone.de/articles/memcached.htm&quot;&gt;una gu&#237;a&lt;/a&gt; que explica alguns dels comandos que tens disponibles, els m&#233;s interesants s&#243;n:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;flush_all: Elimina totes les entrades&lt;/li&gt;
&lt;li&gt;stats [slabs|items]: D&#243;na informaci&#243; estadistica sobre memoria utilitzada, claus, etc.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <publication>Sun, 12 Jun 2011 20:59:26 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/com-treballar-directament-amb-memcached</link>
      <guid>http://how.itnig.net/facts/com-treballar-directament-amb-memcached</guid>
    </item>
    <item>
      <title>Com treure arxius de git que ja est&#224;n a l'index</title>
      <description>&lt;p&gt;A vegades et trobes en que vols afegir algun arxiu al .gitignore que ja est&#224; trackejat. Aleshores encara que l'afegeixis, git el continuar&#224; tenint en compte com si no haguessis fet res.&lt;/p&gt;

&lt;p&gt;La manera &quot;bruta&quot; de resoldre aixo es eliminar l'arxiu, i fer un commit amb l'arxiu eliminat. A partir d'aleshores ja no entrar&#224; a git (perque est&#224; al .gitignore). Per aixo t&#233; el problema de que elimines realment l'arxiu del teu sistema, i aixo no ho vols.&lt;/p&gt;

&lt;p&gt;La soluci&#243; elegant consisteix en aquesta comanda:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;git rm --cached filename
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Elimina l'arxiu de l'index de git (generar&#224;s un commit amb l'arxiu &quot;deleted&quot;) per&#242; te'l mant&#233; al teu disc dur.&lt;/p&gt;
</description>
      <publication>Fri, 10 Jun 2011 16:23:20 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/com-treure-arxius-de-git-que-ja-estan-a-l-index</link>
      <guid>http://how.itnig.net/facts/com-treure-arxius-de-git-que-ja-estan-a-l-index</guid>
    </item>
    <item>
      <title>Com fer urls maques sense la part del id del model</title>
      <description>&lt;p&gt;Ja sabem que el metode &quot;to_param&quot; a un model defineix quina pinta t&#233; la url que genera. La t&#232;cnica m&#233;s facil per crear urls maques es que siguin del tipus aixi:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
def to_param
  &quot;#{id}-#{some_other_preformated_string}&quot;
end
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Ja que el metode &quot;to_i&quot; de ruby s'ho traga tot i interpretar&#224; n&#250;meros fins al primer car&#224;cter no num&#232;ric. Per tant aixo funciona.&lt;/p&gt;

&lt;p&gt;Pero no es gaire maco, perque ning&#250; sap que vol dir aquest numeret aqui davant en la url dels teus models. Lo ideal &#233;s que el metode sigui aix&#237;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
def to_param
  &quot;#{title}&quot;
end
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Pero aleshores s'han de fer algunes coses m&#233;s, no gaires tampoc:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Assegura't de que &quot;title&quot; &#233;s &#250;nic per al teu model! &lt;code&gt;validates_uniqueness_of :title&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Assegura't tamb&#233; que &quot;title&quot; t&#233; un format v&#224;lid per formar part d'una URL. Nom&#233;s s'accepten caracters ASCII i el guio mig. No guions baixos, ni espais, ni accents, ni res UTF-8. B&#233;, de fet si s'accepten (si ho escapes b&#233;), pero la url quedar&#224; lletja i generalment ning&#250; ho vol aixo. Per exemple:&lt;/p&gt;

&lt;p&gt;  http://fr.wikipedia.org/wiki/%C3%89l%C3%A9phant&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Els navegadors moderns t'ho interpreten i et mostren els car&#224;cters UTF-8 correctes, pero &quot;de veritat&quot; el sistema de urls no funciona pas aix&#237; (copia i pega la url del navegador i veuras que, un cop enganxada, et mostra la versi&#243; escapada).&lt;/p&gt;

&lt;p&gt;El que faig jo per fer aquesta conversi&#243; s&#243;n dos passos, per una banda convertir accents i car&#224;cters utf-8 a ascii (aixo es pot fer amb aquest &lt;a href=&quot;http://how.itnig.net/facts/6&quot;&gt;fact&lt;/a&gt;). I despr&#233;s passar-ho a downcase, i convertir tot caracter no alfanum&#232;ric a &quot;-&quot;. En resum, per una banda extenem String:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
class String
  def to_ascii
    Unicode.normalize_KD(self).unpack('U*').select{ |cp| cp &amp;lt; 127 }.pack('U*')
  end
end
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Atenci&#243; que per fer servir &quot;Unicode&quot; necesites definir la gem en el Gemfile &quot;gem 'unicode'&quot;. Despr&#233;s la funci&#243; to_param:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
  def to_param
    &quot;#{title.downcase.to_ascii.gsub(/[^[:alnum:]]/,'-')}&quot;
  end
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;Tingues en compte per&#242; que l'exemple anterior no funcionar&#224; b&#233;! Si vols identificar el model per el camp title, el que posis com a url ha de ser &quot;buscable&quot; per una query SQL. No pots modificar el que renderitzes com a SQL i que no sigui el mateix a bd. Si has de fer conversions, les has de fer modificant l'atribut &quot;title&quot;. I sin&#243;, afegeix un atribut nou &quot;title_url&quot; que sigui la versi&#243; &quot;url-itzada&quot;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Finalment has de fer que els controladors busquin aquest model per el nou atribut &quot;title_url&quot; en comptes de per &quot;id&quot;.&lt;/p&gt;

&lt;p&gt;  Model.find_by_title! params[:id]&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Nota que el nom del par&#224;metre continua sent :id. El bang! t'asegura que si no es troba es llan&#231;ar&#224; una excepci&#243; i es renderitzar&#224; el 404 normalment.&lt;/p&gt;

&lt;p&gt;Nota per cancan: Si estas fent servir cancan per carregar el teu resource, has d'utilitzar algo semblant a:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
load_resource :find_by =&gt; :title_url
authorize_resource
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;No pots fer servir &quot;load_and_authorize_resource&quot; ja que aquesta funci&#243; no te parametres.&lt;/p&gt;
</description>
      <publication>Fri, 10 Jun 2011 16:18:57 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/com-fer-urls-maques-sense-la-part-del-id-del-model</link>
      <guid>http://how.itnig.net/facts/com-fer-urls-maques-sense-la-part-del-id-del-model</guid>
    </item>
    <item>
      <title>Provar subdominis en local</title>
      <description>&lt;p&gt;Simplement, editar el fitxer &lt;em&gt;/etc/hosts&lt;/em&gt; i afagir un domini fictici amb wildcard (&lt;em&gt;lvh.me&lt;/em&gt;, de &lt;em&gt;local virtual host&lt;/em&gt;, per exemple) que resolgui per 127.0.0.1:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
...
127.0.0.1 localhost
127.0.0.1 *.lvh.me
...
&lt;/code&gt;&lt;/pre&gt;



</description>
      <publication>Fri, 10 Jun 2011 12:35:03 +0200</publication>
      <author>Albert</author>
      <link>http://how.itnig.net/facts/provar-subdominis-en-local</link>
      <guid>http://how.itnig.net/facts/provar-subdominis-en-local</guid>
    </item>
    <item>
      <title>Com utilitzar memcache com a cache store a Rails</title>
      <description>&lt;p&gt;La cosa es bastant facil. Primer s'ha d'instalar memcached al servidor, a ubuntu es tan facil com:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;sudo apt-get install memcached
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Despr&#233;s l'aplicaci&#243; que vulguis que utilitzi memcached ha de tenir la seguent gem definida al Gemfile:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gem &quot;memcache-client&quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I finalment declarar que vols utilitzar-ho a l'arxiu config/environments/production.rb:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;config.action_controller.cache_store = :mem_cache_store
&lt;/code&gt;&lt;/pre&gt;
</description>
      <publication>Thu, 09 Jun 2011 22:08:04 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/com-utilitzar-memcache-com-a-cache-store-a-rails</link>
      <guid>http://how.itnig.net/facts/com-utilitzar-memcache-com-a-cache-store-a-rails</guid>
    </item>
    <item>
      <title>Com utilitzar expiracions de cache desde models</title>
      <description>&lt;p&gt;Aquest un trending topic sens dubte! A must read!!&lt;/p&gt;

&lt;p&gt;El funcionament de caching amb rails t&#233; un greu defecte, i es que totes les operacionsq ue et dona per expirar caches estan vinculades a un contolador. Osigui, nom&#233;s es poden executar desde els controladors. Aixo es un greu error, quant tens expiracions complexes la logica sempre va associada als models i hauries d epoder fer expiracions desde qualsevol lloc, rake tasks, etc.&lt;/p&gt;

&lt;p&gt;Amb el mecanisme que es presenta a continuaci&#243; s'habilita l'expiraci&#243; de cache desde observadors normals, lo qual encara &#233;s millor ja que fiques la logica d'expiraci&#243; no directament al model que la dispara sin&#243; en un observador extern. El &quot;trick&quot; consisteix simplement en crear una instancia nova de &quot;@controller&quot; que no existeix desde els models.&lt;/p&gt;

&lt;p&gt;La clase sweeper vindria a ser aixo:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
class EventSweeper &amp;lt; ActionController::Caching::Sweeper
  observe Event

  def sweep(event)
    @controller ||= ActionController::Base.new
    expire_fragment(&quot;events_for_#{event.subject.class}.#{event.subject.id}&quot;)
  end

  alias_method :after_save, :sweep
  alias_method :after_destroy, :sweep
end
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;I recorda d'habilitar el observador desde &lt;code&gt;application.rb&lt;/code&gt;.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;config.active_record.observers = [:event_sweeper, :comment_sweeper]
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Font original de la info:&lt;/p&gt;

&lt;p&gt;http://stevencummings.name/2010/09/07/expire_fragment-with-rake-and-as-a-model-only-observer&lt;/p&gt;
</description>
      <publication>Thu, 09 Jun 2011 16:53:29 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/com-utilitzar-expiracions-de-cache-desde-models</link>
      <guid>http://how.itnig.net/facts/com-utilitzar-expiracions-de-cache-desde-models</guid>
    </item>
    <item>
      <title>Neteja d'arxius innecesaris</title>
      <description>&lt;p&gt;Hi ha una aplicaci&#243; que es diu &lt;em&gt;bleachbit&lt;/em&gt; que va de puta mare per netejar el filesystem d'arxius basura. Suporta tot tipus de coses:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;arxius de backup&lt;/li&gt;
&lt;li&gt;.DS_Store&lt;/li&gt;
&lt;li&gt;Thumbs.db&lt;/li&gt;
&lt;li&gt;System: apt-get clean, arxius de log de sistema, esborrar arxius de traduccions no usats, ...&lt;/li&gt;
&lt;li&gt;Comportament especific per aplicacions: nautilus, chrome, firefox, skype, ...&lt;/li&gt;
&lt;/ul&gt;

</description>
      <publication>Mon, 06 Jun 2011 21:18:19 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/neteja-d-arxius-innecesaris</link>
      <guid>http://how.itnig.net/facts/neteja-d-arxius-innecesaris</guid>
    </item>
    <item>
      <title>Com treballar correctament amb Gems</title>
      <description>&lt;p&gt;Una extensa guia de bones practiques per a desenvolupadors de Gems.&lt;/p&gt;

&lt;p&gt;http://guides.rubygems.org/patterns/&lt;/p&gt;
</description>
      <publication>Thu, 26 May 2011 22:01:28 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/com-treballar-correctament-amb-gems</link>
      <guid>http://how.itnig.net/facts/com-treballar-correctament-amb-gems</guid>
    </item>
    <item>
      <title>Com ordenar strings UTF-8 (amb accents, etc: &#225; == a)</title>
      <description>&lt;pre&gt;&lt;code&gt;provincies = [&quot;&#193;lava&quot;, &quot;C&#225;ceres&quot;, &quot;C&#225;diz&quot;, &quot;Castell&#243;n&quot;, &quot;Ciudad Real&quot;, &quot;C&#243;rdoba&quot;, &quot;Coru&#241;a&quot;, &quot;Cuenca&quot;, &quot;Girona&quot;, &quot;Granada&quot;, &quot;Guadalajara&quot;, &quot;Albacete&quot;, &quot;Guipuzcoa&quot;, &quot;Huelva&quot;, &quot;Huesca&quot;, &quot;Ja&#233;n&quot;, &quot;Le&#243;n&quot;, &quot;Lleida&quot;, &quot;La Rioja&quot;, &quot;Lugo&quot;, &quot;Madrid&quot;, &quot;M&#225;laga&quot;, &quot;Alicante&quot;, &quot;Murcia&quot;, &quot;Navarra&quot;, &quot;Ourense&quot;, &quot;Asturias&quot;, &quot;Palencia&quot;, &quot;Las Palmas&quot;, &quot;Pontevedra&quot;, &quot;Salamanca&quot;, &quot;S.C. Tenerife&quot;, &quot;Cantabria&quot;, &quot;Almer&#237;a&quot;, &quot;Segovia&quot;, &quot;Sevilla&quot;, &quot;Soria&quot;, &quot;Tarragona&quot;, &quot;Teruel&quot;, &quot;Toledo&quot;, &quot;Valencia&quot;, &quot;Valladolid&quot;, &quot;Vizcaya&quot;, &quot;Zamora&quot;, &quot;&#193;vila&quot;, &quot;Zaragoza&quot;, &quot;Ceuta&quot;, &quot;Melilla&quot;, &quot;Badajoz&quot;, &quot;Illes Balears&quot;, &quot;Barcelona&quot;, &quot;Burgos&quot;]


provincies.sort do |a,b|
  val_a = a.split(//).collect { |x| x.unpack('U').to_s }.join
  val_b = b.split(//).collect { |x| x.unpack('U').to_s }.join
  val_a &amp;lt;=&amp;gt; val_b
end
&lt;/code&gt;&lt;/pre&gt;
</description>
      <publication>Tue, 17 May 2011 11:39:19 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/com-ordenar-strings-utf-8--amb-accents--etc--a----a-</link>
      <guid>http://how.itnig.net/facts/com-ordenar-strings-utf-8--amb-accents--etc--a----a-</guid>
    </item>
    <item>
      <title>Com guardar arxius amb carrierwave directament desde memoria</title>
      <description>&lt;p&gt;A vegades et pots trobar en la situacio de voler guardar algun arxiu amb carrierwave que has obtingut directament, que has generat t&#250;. Per exemple, generant un pdf, o potser agafant el attachment d'un email parsejat.&lt;/p&gt;

&lt;p&gt;Carrierwave accepta que li passis File, Tempfile o StringIO i en aquests casos hem de fer servir l'ultima opci&#243;. El problema &#233;s que a partir de rails3 StringIO no respon a &lt;code&gt;original_filename&lt;/code&gt;, i per tant peta. S'ha de monkey patchejar perque vagi tot b&#233;. Te logica, carrierwae necesita saber quin &#233;s el nom de l'arxiu i aqui no li estem donant aquesta informaci&#243;. El que hem de fer es afegir el metode &quot;original_filename&quot; sobre l'objecte StringIO, i fer que retorni el nom que nosaltres volguem.&lt;/p&gt;

&lt;p&gt;A continuaci&#243; hi ha un exemple que guarda attachments rebuts per email:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;        tmp = StringIO.new(attach.read)
        tmp.instance_eval &amp;lt;&amp;lt;-RUBY, __FILE__, __LINE__+1
          def original_filename
            &quot;#{attach.filename}&quot;
          end
        RUBY

        a = Attachment.create :attach =&amp;gt; tmp,
                              :description =&amp;gt; &quot;File sended via email by #{email.from}&quot;,
                              :project =&amp;gt; project,
                              :employee =&amp;gt; emp,
                              :author =&amp;gt; from.nil? ? email.from.to_s : from.to_s
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;En aquest exemple &lt;code&gt;attach&lt;/code&gt; &#233;s un attachment d'un email, i &lt;code&gt;attach.read&lt;/code&gt; retorna un string. El model &lt;code&gt;Attachment&lt;/code&gt; t&#233; carrierwave muntat sobre l'atribut &lt;code&gt;attach&lt;/code&gt;.&lt;/p&gt;
</description>
      <publication>Sat, 14 May 2011 15:42:37 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/com-guardar-arxius-amb-carrierwave-directament-desde-memoria</link>
      <guid>http://how.itnig.net/facts/com-guardar-arxius-amb-carrierwave-directament-desde-memoria</guid>
    </item>
    <item>
      <title>Autoritzacions de ip's i/o dominis per Nginx</title>
      <description>&lt;p&gt;Pots dir que un vhost de nginx nom&#233;s accepti conexions de certes ips o reds, creant llistes blanques. O rebutjar conexions de certes ips o reds, creant llistes negres:&lt;/p&gt;

&lt;p&gt;http://wiki.nginx.org/HttpAccessModule&lt;/p&gt;
</description>
      <publication>Wed, 11 May 2011 16:46:36 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/autoritzacions-de-ip-s-i-o-dominis-per-nginx</link>
      <guid>http://how.itnig.net/facts/autoritzacions-de-ip-s-i-o-dominis-per-nginx</guid>
    </item>
    <item>
      <title>Com crear un nou certificat SSL signat</title>
      <description>&lt;p&gt;Un cop comprat, la teva entitat certificadora (com goddady) et demanara que li donguis un CSR (Certificate Signing Request). Aquest arxiu es pot generar amb la seguent instruccio:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;openssl req -out gestionapro.csr -new -newkey rsa:2048 -nodes -keyout gestionapro.key
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Aixo utilitzara 2048 bits per a les claus. Generar&#224; dos arxius, una clau privada (.key) i una peticio de signatura de certificat (csr).&lt;/p&gt;

&lt;p&gt;IMPORTANT!!: D'entre totes les preguntes que et fa, la important &#233;s la que diu: &quot;Common Name&quot; alla has de ficar el domini pel qual &#233;s aquest certificat. Per exemple:&lt;/p&gt;

&lt;pre&gt;
roger@Invernalia:/etc/ssl/localcerts$ sudo openssl req -out gestionapro.csr -new -newkey rsa:2048 -nodes -keyout gestionapro.key
[sudo] password for roger: 
Generating a 2048 bit RSA private key
.......................................................+++
.........................+++
writing new private key to 'gestionapro.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:ES
State or Province Name (full name) [Some-State]:.
Locality Name (eg, city) []:.
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Itnig Solutions S.L.
Organizational Unit Name (eg, section) []:.
Common Name (eg, YOUR name) []:*.gestiona.pro
Email Address []:.           

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
roger@Invernalia:/etc/ssl/localcerts$ ls
gestionapro.csr  gestionapro.key  server.crt  server.key
roger@Invernalia:/etc/ssl/localcerts$ more gestionapro.csr
-----BEGIN CERTIFICATE REQUEST-----

-----END CERTIFICATE REQUEST-----
&lt;/pre&gt;


&lt;p&gt;El carro aquest es el que has d'enganxar a la web de Goddady quan et demana per el &quot;CSR&quot;.&lt;/p&gt;

&lt;p&gt;A partir d'aqui, ve tota la burocr&#224;cia que pot tardar dos o tres dies, fins que reps un email que et confirma el tema. Aleshores vas a la web de goddady (o similar) i ja et pots baixar el certificat, demana'l pel servidor &quot;Apache&quot;. Obtindr&#224;s dos arxius .crt, el certificat propi que has demanat i l'altre arxiu cont&#233; alguns altres certificats de goddady, pero que tamb&#233; es necesiten.&lt;/p&gt;

&lt;p&gt;S'han de combinar els dos amb algo com:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;cat gestiona.pro.crt gd_bundle.crt &amp;gt; gestionapro_combined.crt
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;La configuraci&#243; final de nginx quedar&#224;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ssl                      on;
ssl_certificate         /etc/ssl/localcerts/gestionapro_combined.crt;
ssl_certificate_key     /etc/ssl/localcerts/gestionapro.key;
&lt;/code&gt;&lt;/pre&gt;
</description>
      <publication>Wed, 11 May 2011 15:35:34 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/com-crear-un-nou-certificat-ssl-signat</link>
      <guid>http://how.itnig.net/facts/com-crear-un-nou-certificat-ssl-signat</guid>
    </item>
    <item>
      <title>Certificats SSL autosignats amb Nginx</title>
      <description>&lt;p&gt;http://dracoblue.net/dev/https-nginx-with-self-signed-ssl-certificate/188/&lt;/p&gt;

&lt;p&gt;Es bastant senzill&lt;/p&gt;
</description>
      <publication>Wed, 11 May 2011 12:03:47 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/certificats-ssl-autosignats-amb-nginx</link>
      <guid>http://how.itnig.net/facts/certificats-ssl-autosignats-amb-nginx</guid>
    </item>
    <item>
      <title>Com veure el log de ActiveRecord desde consola rails</title>
      <description>&lt;p&gt;Executa aquesta instrucci&#243;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;ActiveRecord::Base.logger = Logger.new(STDOUT) 
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I veuras per la pantalla totes les crides sql que es fan (igual com si fos un rails server) pero amb les coses que fas a la consola.&lt;/p&gt;
</description>
      <publication>Mon, 09 May 2011 20:17:57 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/com-veure-el-log-de-activerecord-desde-consola-rails</link>
      <guid>http://how.itnig.net/facts/com-veure-el-log-de-activerecord-desde-consola-rails</guid>
    </item>
    <item>
      <title>Com treballar amb Date i ActiveRecord, mostrar i guardar.</title>
      <description>&lt;h1&gt;Sortida&lt;/h1&gt;

&lt;p&gt;Per mostrar dates no hi ha cap problema.&lt;/p&gt;

&lt;p&gt;1) Si tens una situacio simple on nom&#233;s vols formatar la manera com es mostraran sempre les dates, el millor es crear un nou initializer i a dins ficar-hi algo com aixo:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Date::DATE_FORMATS[:default] = '%d/%m/%Y'
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Aixi estableixes el format per defecte amb el que es mostren els atributs &quot;Date&quot;. La sintaxi &#233;s la mateixa que per al m&#232;tode .strftime() de tota la vida. Nota que aix&#242; nom&#233;s funciona amb Dates, no amb DateTimes. Hi ha l'equivalent:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Time::DATE_FORMATS[:default] = '%d/%m/%Y %H:%M:%S'
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Per fer el mateix amb els atributs de datetime.&lt;/p&gt;

&lt;p&gt;2) Si vols que les dates es mostrin diferent segons l'idioma, ergo, localitzades, aleshores has de fer servir el helper &quot;l&quot;. Utilitza el mecanisme I18n per defecte de Rails, i el format que utilitza el defineixes en l'arxiu yml de traduccions de rails. Mes info disponible a google!.&lt;/p&gt;

&lt;h1&gt;Entrada&lt;/h1&gt;

&lt;p&gt;Aqui venen m&#233;s problemes. Estem parlant d'assignar un string a un atribut d'un model definit com a Date, que es exactament el que pasa en els controladors, que reben un string. Perque aixo funcioni s'ha de parsejar el string i convertir-ho en una data normal, i aixo Rails ja t'ho fa per defecte. El que pasa es que tuilitza un parser propi del Date de ruby (no se si modificat) que es for&#231;a inteligent i tal per&#242; ho fa a la seva manera. No et dona un mecanisme, Rails, per configurar de quina manera s'han d'interpretar els string-dates. El comportament per defecte accepta diferents formats, per exemple:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;dd-mm-yyyy
yyyy-mm-dd
mm/dd/yyyy
...
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Per&#242; com veieu el format &quot;dd/mm/yyyy&quot; no es un d'ells!! Aquesta info l'he tret d'una pregunta a stackoverflow, pero ara buscant no l'he tornat a trobar. Us n'haureu de refiar. Aquest tema est&#224; poc documentat i no es trivial trobar respostes, aixi que aquest FACT te molt valor!&lt;/p&gt;

&lt;p&gt;Per parsejar dates pots utilitzar:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Date.strptime(&quot;3/1/2011&quot;, &quot;%d/%m/%Y&quot;) # =&amp;gt; 3 de Gener de 2011
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Aixi doncs que fer? Doncs pots sobreescriure els setters dels atributs date, o algo semblant, el fet &#233;s que has de modificar algo. Tamb&#233; podries monckey-patchejar el parser de Date, pero es lleig.&lt;/p&gt;
</description>
      <publication>Wed, 04 May 2011 22:16:47 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/com-treballar-amb-date-i-activerecord--mostrar-i-guardar-</link>
      <guid>http://how.itnig.net/facts/com-treballar-amb-date-i-activerecord--mostrar-i-guardar-</guid>
    </item>
    <item>
      <title>Com utilitzar rcov</title>
      <description>&lt;p&gt;Rcov es una eina per mesurar quin codi ruby s'executa i quin no quan executes la teva suite de tests, d'aquesta manera pots saber quin codi et queda per testejar.&lt;/p&gt;

&lt;p&gt;Per fer-lo servir en una aplicacio rails es molt f&#224;cil, afegeit &quot;rcov&quot; al gemfile i executa aixo:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;rake spec:rcov
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Per fer-lo servir en una gem, has de fer algo una mica m&#233;s custom:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
require 'bundler'
Bundler::GemHelper.install_tasks

require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec)

task :default =&gt; :spec

desc &quot;Run all specs with rcov&quot;
RSpec::Core::RakeTask.new(&quot;spec:coverage&quot;) do |t|
  t.rcov = true
  t.rcov_opts = %w{--rails --include views -Ispec --exclude gems\/,spec\/,features\/,seeds\/}
  t.rspec_opts = [&quot;-c&quot;]
end
&lt;/code&gt;&lt;/pre&gt;


&lt;p&gt;L'anterior es un exemple t&#237;pic de Rakefile per una gem, la tasca &#250;ltima es la que dona el coverage. Aleshores pots executar:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;rake spec:coverage
&lt;/code&gt;&lt;/pre&gt;
</description>
      <publication>Wed, 04 May 2011 11:39:32 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/com-utilitzar-rcov</link>
      <guid>http://how.itnig.net/facts/com-utilitzar-rcov</guid>
    </item>
    <item>
      <title>click en todo el boton. No solo en link</title>
      <description>&lt;p&gt;Darle el estilo a la propiedad &quot;a&quot; :&lt;/p&gt;

&lt;p&gt; Ejemplo:&lt;/p&gt;

&lt;p&gt; boton a {
   display: block; ----------------&gt; se mostrara el contenido como un bloque, con espacios en blcos . a su alrededor, no aceptara nada a su lado ( a&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;                                                      menos que ponga un &quot;float-left o right &quot; al elemento que se desea poner a lado.)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;   background-color: blue;
   color: red;
   padding: 1em;
 }&lt;/p&gt;

&lt;p&gt;Ojo con la diferencia :&lt;/p&gt;

&lt;p&gt; boton{
  background-color: blue;
  a{&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;color: red;
padding: 1em;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;  }
}&lt;/p&gt;
</description>
      <publication>Mon, 02 May 2011 17:26:50 +0200</publication>
      <author>Dulce D' La Rosa</author>
      <link>http://how.itnig.net/facts/click-en-todo-el-boton--no-solo-en-link</link>
      <guid>http://how.itnig.net/facts/click-en-todo-el-boton--no-solo-en-link</guid>
    </item>
    <item>
      <title>Reproduir MP3 des de command line</title>
      <description>&lt;p&gt;Simplement, instal&#183;lar el binari &quot;mpg123&quot;&lt;/p&gt;

&lt;p&gt;http://www.go2linux.org/mpg123-linux-command-line-play-mp3-files&lt;/p&gt;

&lt;p&gt;Amb:&lt;/p&gt;

&lt;p&gt;sudo apt-get install mpg123 (ubuntu)&lt;/p&gt;

&lt;p&gt;sudo port install mpg123 (mac os x)&lt;/p&gt;
</description>
      <publication>Wed, 20 Apr 2011 10:51:08 +0200</publication>
      <author>Albert</author>
      <link>http://how.itnig.net/facts/reproduir-mp3-des-de-command-line</link>
      <guid>http://how.itnig.net/facts/reproduir-mp3-des-de-command-line</guid>
    </item>
    <item>
      <title>Com fer extensions (plugins) ben fetes amb ActiveSupport::Concern</title>
      <description>&lt;p&gt;Quan estem en la situacio de voler afegir funcinoalitat de forma DRY a una classe ruby, hem d'utilitzar moduls, un mecanisme del propi llenguatge Ruby. El problema ve quan volem expandir la funcionalitat a diferents nivells, definir metodes nous de clase i d'inst&#224;ncia, i potser cridar a noves funcions desde dins la clase.&lt;/p&gt;

&lt;p&gt;Fins ara el mecanisme per solventar aix&#242; era la t&#237;pica estructura de sobreescriure el metode .include perque fes ell sol un include (de veritat) i un extend. Pero aixo no es una bona pr&#224;ctica, i Rails dona un petit modul per ajudar a fer aix&#242;, el Concern. Llegir &lt;a href=&quot;http://yehudakatz.com/2009/11/12/better-ruby-idioms/&quot;&gt;aquest&lt;/a&gt; article de Yehuda Katz sobre el perqu&#232; de tot aixo, i tamb&#233; &lt;a href=&quot;http://www.strictlyuntyped.com/2010/05/tweaking-on-rails-30-2.html&quot;&gt;aquest&lt;/a&gt; article explicant de forma pr&#224;ctica com utilitzar-ho.&lt;/p&gt;

&lt;p&gt;Aixo es rails avan&#231;at, i s'ha de coneixer.&lt;/p&gt;
</description>
      <publication>Sat, 09 Apr 2011 21:05:49 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/com-fer-extensions--plugins--ben-fetes-amb-activesupport--concern</link>
      <guid>http://how.itnig.net/facts/com-fer-extensions--plugins--ben-fetes-amb-activesupport--concern</guid>
    </item>
    <item>
      <title>Generador de passwords i claus en ruby</title>
      <description>&lt;p&gt;Diferents metodes per generar claus desde ruby amb poques linies. Ara no em posare a redactar un a epxlicacio mes llarga, encara que podria!, per el link el teniu aqui:&lt;/p&gt;

&lt;p&gt;http://stackoverflow.com/questions/88311/how-best-to-generate-a-random-string-in-ruby&lt;/p&gt;
</description>
      <publication>Fri, 01 Apr 2011 19:23:01 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/generador-de-passwords-i-claus-en-ruby</link>
      <guid>http://how.itnig.net/facts/generador-de-passwords-i-claus-en-ruby</guid>
    </item>
    <item>
      <title>Com renderitzar partials de rails dins de vistes javascript</title>
      <description>&lt;p&gt;Com sabeu podem crear vistes que responguin al format &quot;js&quot;, que directament s'interpreten com javascript i s'executen.&lt;/p&gt;

&lt;p&gt;En aquests casos podriem tenir l'arxiu seguent:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# toggle.js.erb
alert(&quot;HOLA&quot;);
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I quant executesim l'accio &quot;toggle&quot; del controlador que sigui s'executaria aquest script.&lt;/p&gt;

&lt;p&gt;Seguint aquest paradigme, ara be, voldriem poder generar el string &quot;HOLA&quot; a partir del render d'un partial o alguna cosa semblant. Si ho fem directament ens PETARA JAVASCRIPT! Perque hem d'escapar la sortida. El codi bo seria aquest:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;# toogle.js.erb
alert(&quot;&amp;lt;%= escape_javascript(render &quot;algun_partial&quot;) %&amp;gt;&quot;);
&lt;/code&gt;&lt;/pre&gt;
</description>
      <publication>Wed, 30 Mar 2011 15:53:35 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/com-renderitzar-partials-de-rails-dins-de-vistes-javascript</link>
      <guid>http://how.itnig.net/facts/com-renderitzar-partials-de-rails-dins-de-vistes-javascript</guid>
    </item>
    <item>
      <title>Com crear diagrames de models d'una aplicaci&#243;</title>
      <description>&lt;p&gt;Per crear diagrames de models d'una app pots utilitzar el seguent software que ho fa for&#231;a be.&lt;/p&gt;

&lt;p&gt;http://railroad.rubyforge.org/&lt;/p&gt;
</description>
      <publication>Tue, 29 Mar 2011 18:00:20 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/com-crear-diagrames-de-models-d-una-aplicacio</link>
      <guid>http://how.itnig.net/facts/com-crear-diagrames-de-models-d-una-aplicacio</guid>
    </item>
    <item>
      <title>com funciona el bloc rescue d'excepcions per defecte</title>
      <description>&lt;p&gt;Per capturar una excepcio amb ruby es fa servir begin; rescue; end;. El que pasa, es que quan utilitzes aquesta sintaxi amb un &quot;rescue&quot; sense res m&#233;s, per defecte nom&#233;s et captura excepcions a partir de StandardError, que no es la excepcio root absoluta. Per tant, pot ser que alguna excepcio se t'escapi. Per solventaro, nomes has d'especificar rescue Exception de forma explicita.&lt;/p&gt;

&lt;p&gt;http://rubylearning.com/satishtalim/ruby_exceptions.html&lt;/p&gt;
</description>
      <publication>Tue, 29 Mar 2011 10:53:02 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/com-funciona-el-bloc-rescue-d-excepcions-per-defecte</link>
      <guid>http://how.itnig.net/facts/com-funciona-el-bloc-rescue-d-excepcions-per-defecte</guid>
    </item>
    <item>
      <title>Com fer busquedas d'strings amb sql amb utf-8</title>
      <description>&lt;p&gt;Per fer busquedas amb SQL tipicament podem fer servir el mecanisme d'interpolaci&#243; de strings que tota implementacio de SQL t&#233;, algo com aixo:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;t = Interpret::Translation.arel_table
Interpret::Translation.where(t[:value].matches(&quot;%posici&#243;n%&quot;))
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Pero aixo falla quan utilitzes caracters no ascii! La linea de sota no trobar&#224; res perque has posat &quot;&#243;&quot;.&lt;/p&gt;

&lt;p&gt;Per solventar aixo, has de llan&#231;ar la busqueda amb els caracters escapats utilitzant el modul CGI. La seguent instrcci&#243; si funciona:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Interpret::Translation.where(t[:value].matches(&quot;%#{CGI.escape(&quot;posici&#243;n&quot;)}%&quot;))
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Aixo si, si fent aixo falla, asegura't que la resta d'elements involucrats estan ben configurats. La base de dades ha de fer servir una codificaci&#243; utf8, el codi ruby tamb&#233;, etc.&lt;/p&gt;
</description>
      <publication>Mon, 28 Mar 2011 19:13:15 +0200</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/com-fer-busquedas-d-strings-amb-sql-amb-utf-8</link>
      <guid>http://how.itnig.net/facts/com-fer-busquedas-d-strings-amb-sql-amb-utf-8</guid>
    </item>
    <item>
      <title>core_ext a apps rails</title>
      <description>&lt;p&gt;La pregunta de stackoverflow amb una bona resposta es la seguent:&lt;/p&gt;

&lt;p&gt;http://stackoverflow.com/questions/3874148/best-practice-for-adding-a-ruby-extension-methods-to-rails-3&lt;/p&gt;

&lt;p&gt;B&#224;sciament es tracta de crear una carpeta core_ext dins de lib, i despres requerir tots els arxius que hi hagui aqui desde un initializer.&lt;/p&gt;
</description>
      <publication>Tue, 22 Mar 2011 11:53:12 +0100</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/core-ext-a-apps-rails</link>
      <guid>http://how.itnig.net/facts/core-ext-a-apps-rails</guid>
    </item>
    <item>
      <title>Eliminar accents i caracters no-ascii d'un string</title>
      <description>&lt;p&gt;El seguent codi serveix per convertir qualsevol caracter no ascii a la seva representacio ascii:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;Unicode.normalize_KD(&quot;ol&#225;&#236;&#242;&#249;&#224;&#226;&#228;&quot;).unpack('U*').select{ |cp| cp &amp;lt; 127 }.pack('U*') #=&amp;gt; &quot;olaiouaaa&quot;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Es requereix fer servir la gem 'unicode', aixi que recorda de afegir-la al teu Gemfile.&lt;/p&gt;

&lt;p&gt;Una bona opcio es crear una extensio de String amb un metode que faci aquesta operacio, hi ha un altre FACT explicant com fer aixo i la millor manera.&lt;/p&gt;

&lt;p&gt;Una manera f&#224;cil de implementar aix&#242; ser&#237;a extenent String:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
class String
  def to_ascii
    Unicode.normalize_KD(self).unpack('U*').select{ |cp| cp &amp;lt; 127 }.pack('U*')
  end
end
&lt;/code&gt;&lt;/pre&gt;

</description>
      <publication>Tue, 22 Mar 2011 11:22:12 +0100</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/eliminar-accents-i-caracters-no-ascii-d-un-string</link>
      <guid>http://how.itnig.net/facts/eliminar-accents-i-caracters-no-ascii-d-un-string</guid>
    </item>
    <item>
      <title>Nested layouts</title>
      <description>&lt;p&gt;Una funcionalitat que feia temps que buscava, el poder construir layouts anidats.&lt;/p&gt;

&lt;p&gt;http://m.onkey.org/nested-layouts-in-rails-3&lt;/p&gt;

&lt;p&gt;Update: Nom&#233;s funciona quan el template pare &#233;s en format ERB !!!&lt;/p&gt;
</description>
      <publication>Sun, 20 Mar 2011 13:20:04 +0100</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/nested-layouts</link>
      <guid>http://how.itnig.net/facts/nested-layouts</guid>
    </item>
    <item>
      <title>debugar expresions amb Object#tap</title>
      <description>&lt;p&gt;Una tecnica for&#231;a util que acabo de coneixer que pot ajudar o simplificar la feina de fer &quot;chivatos&quot; quant vols comprovar la situacio que hi ha enmig d'una expresio comeplexe, sense haberla de modificar expressament.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;http://moonbase.rydia.net/mental/blog/programming/eavesdropping-on-expressions.html&quot;&gt;link&lt;/a&gt;&lt;/p&gt;
</description>
      <publication>Fri, 18 Mar 2011 21:22:36 +0100</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/debugar-expresions-amb-object-tap</link>
      <guid>http://how.itnig.net/facts/debugar-expresions-amb-object-tap</guid>
    </item>
    <item>
      <title>Quan utilitzar self en un model</title>
      <description>&lt;p&gt;En un model de ruby pots triar entre fer servir o no &quot;self&quot; en els metodes d'instancia.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;def metode
  self.name = &quot;cucamonga&quot;
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Quan has de fer servir self i quan no?&lt;/p&gt;

&lt;p&gt;1- Per evitar ambiguitats: Si tens un parametre d'entrada, per exemple, que es diu igual que un atribut has de fer servir self. per dir que et vols referir a l'atribut.&lt;/p&gt;

&lt;p&gt;2- En general, no cal fer servir self. Es mes comode perque has d'escriure menys.&lt;/p&gt;

&lt;p&gt;3- L'unic cas en que es obligatori fer servir self es per fer escriptures de l'atribut:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;def asignacio
  name = &quot;ola&quot;
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Si tens un before_filter que executa l'anterior metode, el atribut &quot;name&quot; del model NO s'actualitzar&#224;. Es obligatori fer servir self.name = &quot;ola&quot;.&lt;/p&gt;
</description>
      <publication>Thu, 17 Mar 2011 19:59:34 +0100</publication>
      <author>Roger Campos</author>
      <link>http://how.itnig.net/facts/quan-utilitzar-self-en-un-model</link>
      <guid>http://how.itnig.net/facts/quan-utilitzar-self-en-un-model</guid>
    </item>
    <item>
      <title>First fact</title>
      <description>&lt;p&gt;Aquest &#233;s el primer fet, hist&#242;ric sens dubte!&lt;/p&gt;
</description>
      <publication>Tue, 15 Mar 2011 16:43:33 +0100</publication>
      <author>Albert</author>
      <link>http://how.itnig.net/facts/first-fact</link>
      <guid>http://how.itnig.net/facts/first-fact</guid>
    </item>
  </channel>
</rss>
