GeoPlanet data with ancestor chain cache imported in 10 minutes

Yahoo! provides its GeoPlanet data as three separate TSV files, available for download here.

That's a database with some 17 million records:

  • 5.7 million records: locations (aka places).
  • 2.2 million records: alternative names for each place (aka aliases).
  • 9.6 million records: matrix of neighbourhoods per place (aka adjacencies).
View registrations_controller.rb
class Api::RegistrationsController < Api::BaseController
respond_to :json
def create
user =[:user])
render :json=> user.as_json(:auth_token=>user.authentication_token, :email=>, :status=>201
View spec_features_samplefeature.rb
require 'spec_helper'
feature "Login" do
scenario "remembered user" do
password = "12345678"
user = create(:user, password: password)
current_path.should eq login_path

My summary of


Rails has a library, ActiveSupport, which adds methods to Ruby core classes. One of those methods is String#blank?, which returns a boolean (sometimes I miss this convention in Rust, the ?) if the whole string is whitespace or not. It looks like this:

It's pretty slow. So Discourse (which you may know from {users,internals} uses the fast_blank gem, which provides this method via a C implementation instead. It looks like this:

For fun, Yehuda tried to re-write fast_blank in Rust. Which looks like this:

View bm_throw_raise.rb
require 'benchmark/ips'
Benchmark.ips do |x| do
raise ArgumentError
rescue ArgumentError
View fix_n_plus_one_queries_on_accepts_nested_attributes.rb
# We noticed that adding `accepts_nested_attributes_for :comments, allow_destroy: true`
# caused extra queries to be run when serializing comments in a post
# and including the post name in each comment resource object (this is JSON API, names changed):
# blog_id = params.permit(:id)[:id]
# Blog = Blog.where(id: blog_id).includes(posts: [:comments]).first
# comments = blog.posts.flat_map(&:comments)
# comment_fields = {comments: [:id, :title, :body, :post], posts: [:name]}
# comment_includes = [:post]
View rails_rendering_stack.txt
#<Class:ActionController::Parameters>#always_permitted_parameters=:126 ([[:req, :obj]])
ActionDispatch::Http::ParameterFilter#initialize:6 ([[:opt, :filters]])
ActionDispatch::Http::ParameterFilter#initialize:6 ([[:opt, :filters]])
ActiveSupport::Callbacks::ClassMethods#normalize_callback_params:594 ([[:req, :filters], [:req, :block]])
ActiveSupport::Callbacks::ClassMethods#normalize_callback_params:594 ([[:req, :filters], [:req, :block]])
ActiveSupport::Callbacks::ClassMethods#normalize_callback_params:594 ([[:req, :filters], [:req, :block]])
#<Class:ActiveModelSerializers::SerializableResource>#_render_callbacks=:83 ([[:req, :val]])
ActiveModelSerializers::Logging::ClassMethods#instrument_rendering:18 ([])
ActiveModelSerializers::Callbacks::ClassMethods#around_render:50 ([[:rest, :filters], [:block, :blk]])
ActiveSupport::Callbacks::ClassMethods#normalize_callback_params:594 ([[:req, :filters], [:req, :block]])
View irb3.rb
#!/usr/bin/env ruby
# encoding: utf-8
# irb3 - Runs an IRB-esque prompt (but it's NOT really IRB!) over multiple
# versions of Ruby at once (using RVM)
# By Peter Cooper, BSD licensed
# Main dependency is term-ansicolor for each impl:
# rvm exec gem install term-ansicolor
#/usr/bin/env bash
json_url() {
local base=""
local day="$1"
local url="${base}&start_time__day=${day}"
echo -e "$url"
for day in 4 5 6; do
curl -XGET $(eval "json_url $day") -o "may_${day}.json"
View autodoc_config.diff
diff --git a/Gemfile b/Gemfile
index f34a069..cb26600 100644
--- a/Gemfile
+++ b/Gemfile
@@ -100,6 +100,8 @@ group :test do
gem 'rspec', '~> 3.3'
gem 'rspec_junit_formatter', '~> 0.2' # per
gem 'rspec-rails', group: :development
+ gem 'autodoc', require: false
+ gem 'redcarpet', require: false