<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><atom:link rel="hub" href="http://tumblr.superfeedr.com/" xmlns:atom="http://www.w3.org/2005/Atom"/><description>

  var _gaq = _gaq || [];
  _gaq.push([‘_setAccount’, ‘UA-9394692-2’]);
  _gaq.push([‘_trackPageview’]);

  (function() {
    var ga = document.createElement(‘script’); ga.type = ‘text/javascript’; ga.async = true;
    ga.src = (‘https:’ == document.location.protocol ? ‘https://ssl’ : ‘http://www’) + ‘.google-analytics.com/ga.js’;
    (document.getElementsByTagName(‘head’)[0] || document.getElementsByTagName(‘body’)[0]).appendChild(ga);
  })();</description><title>Paul Bowsher's Engineering Blog</title><generator>Tumblr (3.0; @boffbowsh)</generator><link>http://blog.boffbowsh.co.uk/</link><item><title>Storing IP addresses the smarter way</title><description>&lt;p&gt;If you need to store an IP address in a database, it’s possibly because you’re logging web requests or similar. This means the table can get very large, very quickly. If you’re storing the addresses in a VARCHAR, you will use up a lot of space in your table and make indexing a nightmare. A lot of people don’t know that you can represent these as an INT which is much more db-friendly.&lt;/p&gt;
&lt;p&gt;IPv4 addresses are just 32-bit integers. In most languages (including in MySQL itself, useful for Sphinx indexes) you can use the equivalent of &lt;a href="http://linuxmanpages.com/man3/inet_ntoa.3.php"&gt;inet_ntoa(3)&lt;/a&gt; to convert to string and &lt;a href="http://linuxmanpages.com/man3/inet_aton.3.php"&gt;inet_aton(3)&lt;/a&gt; to convert to an int. In Ruby  however this is hidden inside the &lt;a href="http://www.ruby-doc.org/stdlib-1.9.3/libdoc/ipaddr/rdoc/IPAddr.html"&gt;IPAddr&lt;/a&gt; class. This instantiation can be quite expensive for what is really a simple conversion, so you can use the following:&lt;/p&gt;
&lt;pre&gt;&lt;code class="ruby"&gt;def inet_aton ip
  ip.split(/\./).map{|c| c.to_i}.pack("C*").unpack("N").first
end


def inet_ntoa n
  [n].pack("N").unpack("C*").join "."
end&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Storing these correctly can save huge performance headaches later.&lt;/p&gt;</description><link>http://blog.boffbowsh.co.uk/post/14083552819</link><guid>http://blog.boffbowsh.co.uk/post/14083552819</guid><pubDate>Sun, 11 Dec 2011 21:41:10 +0000</pubDate></item><item><title>Running Goliath on a UNIX domain socket</title><description>&lt;p&gt;EventMachine supports listening on UNIX domain sockets, therefore &lt;a href="http://goliath.io/"&gt;Goliath&lt;/a&gt; does too.&lt;/p&gt;
&lt;p&gt;Simply create a config file as per the &lt;a href="https://github.com/postrank-labs/goliath/wiki/Configuration"&gt;instructions&lt;/a&gt; on the wiki with the following:&lt;/p&gt;
&lt;pre&gt;@port = nil&lt;/pre&gt;
&lt;p&gt;This makes EventMachine take the address parameter as a unix socket, so simply run your server in the following way:&lt;/p&gt;
&lt;pre&gt;ruby hello_world.rb -sva hello_world.sock&lt;/pre&gt;
&lt;p&gt;You can then serve it up using nginx:&lt;/p&gt;
&lt;pre&gt;http {
  server {
    listen 80 default;
    
    location / {
      proxy_pass http://unix:///Users/boffbowsh/code/hello_world/hello_world.sock;
    }
  }
}&lt;/pre&gt;</description><link>http://blog.boffbowsh.co.uk/post/6262622757</link><guid>http://blog.boffbowsh.co.uk/post/6262622757</guid><pubDate>Mon, 06 Jun 2011 23:27:13 +0100</pubDate></item><item><title>Rails 3: Shoulda failing to load</title><description>&lt;p&gt;If you’re trying to test a Rails 3 gem/plugin/engine and you’re using Bundler, you’re likely to run into an error like the following:&lt;/p&gt;
&lt;pre&gt;DEPRECATION WARNING: RAILS_ROOT is deprecated! Use Rails.root instead. 
/Library/Ruby/Gems/1.8/gems/shoulda-2.10.3/lib/shoulda/autoload_macros.rb:40:in `join': can't convert # into String (TypeError)
from /Library/Ruby/Gems/1.8/gems/shoulda-2.10.3/lib/shoulda/autoload_macros.rb:40:in `autoload_macros'&lt;/pre&gt;
&lt;p&gt;You can easily fix this by making the autoload of macros a no-op, and loading them later once the app is defined:&lt;/p&gt;
&lt;pre&gt;$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'precious'

require 'test/unit'

# No-op the auto load
require 'shoulda/autoload_macros'
module Shoulda; class &lt;&lt;self; alias :original_autoload_macros :autoload_macros; def autoload_macros *a; end; end; end
require 'shoulda'

class Test::Unit::TestCase
  def app_factory &amp;blk
    klass = Class.new Rails::Application
    klass.class_eval(&amp;blk) if block_given?
    Shoulda.original_autoload_macros File.dirname(__FILE__)
    klass
  end 
end&lt;/pre&gt;</description><link>http://blog.boffbowsh.co.uk/post/463879601</link><guid>http://blog.boffbowsh.co.uk/post/463879601</guid><pubDate>Sun, 21 Mar 2010 19:57:00 +0000</pubDate><category>rails 3</category><category>shoulda</category><category>bundler</category></item><item><title>Rails 3: no such file to load -- thor/group</title><description>&lt;p&gt;If you’re getting errors about loading thor when trying to run the Rails 3 binary, try the following:&lt;/p&gt;
&lt;pre&gt;ruby -r'rubygems' railties/bin/rails&lt;/pre&gt;
&lt;p&gt;You can also alias this in your .profile or .bashrc for fun and profit:&lt;/p&gt;
&lt;pre&gt;alias rails3="ruby -r'rubygems' ~/gems/rails/railties/bin/rails"&lt;/pre&gt;</description><link>http://blog.boffbowsh.co.uk/post/399252983</link><guid>http://blog.boffbowsh.co.uk/post/399252983</guid><pubDate>Fri, 19 Feb 2010 22:26:00 +0000</pubDate></item><item><title>Routing in Rails 3 Engines</title><description>&lt;p&gt;If you’re creating a new Engine in Rails 3 (or upgrading one from Rails 2), you’re probably wondering how to do the routing. This is how:&lt;/p&gt;
&lt;pre&gt;Rails.application.routes.draw do
  namespace :admin do
    resources     :users
    resource      :session
    match         'login'  =&gt; 'admin/sessions#new', :as =&gt; 'login'
    match         'logout' =&gt; 'admin/sessions#destroy', :as =&gt; 'logout'
    root          :to =&gt; 'admin/home#index'
  end
end&lt;/pre&gt;
&lt;p&gt;Note that in Rails 3, non-resource routes (like root, login and logout above) don’t obey the namespace context when selecting the controller. This requires you to match specifically to admin/sessions rather than simply sessions.&lt;/p&gt;</description><link>http://blog.boffbowsh.co.uk/post/389538223</link><guid>http://blog.boffbowsh.co.uk/post/389538223</guid><pubDate>Sun, 14 Feb 2010 21:23:00 +0000</pubDate></item><item><title>Rubinius dependencies on Ubuntu</title><description>&lt;p&gt;If you’re trying to build Rubinius on a blank Ubuntu install, you’ll likely hit missing dependancies such as readline, ossl_typ.h and readline. When you run ./configure, it’ll also says that backtrace isn’t found.&lt;/p&gt;
&lt;p&gt;Make sure you’ve got the following packages installed, and all will be well:&lt;/p&gt;
&lt;pre&gt;ruby-dev
zlib1g-dev
libssl-dev
libreadline-dev&lt;/pre&gt;</description><link>http://blog.boffbowsh.co.uk/post/252307026</link><guid>http://blog.boffbowsh.co.uk/post/252307026</guid><pubDate>Sat, 21 Nov 2009 22:34:00 +0000</pubDate></item></channel></rss>

