Skip to content

Instantly share code, notes, and snippets.

View jodosha's full-sized avatar

Luca Guidi jodosha

View GitHub Profile
From 837ab30d309d44511429cf58b24fe72cb6250474 Mon Sep 17 00:00:00 2001
From: Luca Guidi <guidi.luca@gmail.com>
Date: Fri, 29 Aug 2008 16:05:01 +0200
Subject: [PATCH] Speed up for Backend::Simple#interpolate
---
lib/i18n/backend/simple.rb | 37 ++++++++++++++++++++-----------------
1 files changed, 20 insertions(+), 17 deletions(-)
diff --git a/lib/i18n/backend/simple.rb b/lib/i18n/backend/simple.rb
@jodosha
jodosha / controllers.rb
Created September 11, 2008 10:07
Benchmarks for CachedModels
class AuthorsController < ApplicationController
# GET /authors/1
def show
@author = Author.find(params[:id])
end
end
class CachedAuthorsController < ApplicationController
# GET /cached_authors/1
def show
# SQLite 3
SELECT * FROM "articles" INNER JOIN "articles_categories" ON "articles".id = "articles_categories".article_id WHERE ("articles_categories".category_id = 1 )
+-----+-----------------+---------------------+---------------------+----+------------+-------------+
| id2 | title | created_at | updated_at | id | article_id | category_id |
+-----+-----------------+---------------------+---------------------+----+------------+-------------+
| 2 | Cached Models | 2008-11-05 10:28:10 | 2008-11-05 10:28:10 | 1 | 2 | 1 |
| 1 | Rails Conf 2009 | 2008-11-05 10:28:10 | 2008-11-05 10:28:10 | 2 | 1 | 1 |
+-----+-----------------+---------------------+---------------------+----+------------+-------------+
@jodosha
jodosha / hash.rb
Created February 4, 2009 18:37
Ruby's Hash deep search
class Hash
def deep_has_key?(key)
self.has_key?(key) || any? {|k, v| v.deep_has_key?(key) if v.is_a? Hash}
end
alias :deep_include? :deep_has_key?
alias :deep_key? :deep_has_key?
alias :deep_member? :deep_has_key?
def deep_has_value?(value)
self.has_value?(value) || any? {|k,v| v.deep_has_value?(value) if v.is_a? Hash}
@jodosha
jodosha / bench_results.txt
Created February 6, 2009 21:58
Lightweight implementation of ActiveSupport::Callbacks (no backward compatibilities)
ruby 1.8.6 (2008-03-03 patchlevel 114) [universal-darwin9.0]
test | old | new | boost
SymbolCallbackPerson | 0.418285131454468 | 0.198039770126343 | 2.11x
ProcCallbackPerson | 0.478709936141968 | 0.309146881103516 | 1.55x
MethodCallbackPerson | 0.298830032348633 | 0.114556074142456 | 2.60x
StringCallbackPerson | 0.782155990600586 | 0.653557062149048 | 1.97x
ObjectCallbackPerson | 0.49412202835083 | 0.30273699760437 | 1.63x
ConditionalPerson | 5.81794190406799 | 5.45951700210571 | 1.07x
<!-- Show colored Flickr logo without any inline style -->
<style type="text/css" media="screen">
#flickr-badge h3 {
color: #0063DC;
}
#flickr-badge h3:after {
content: "r";
color: #FF0084;
}
</style>
class SessionController < ApplicationController
def read
render :text => session[:user_id], :status => :ok
end
def write
render :text => session[:user_id] = 23, :status => :ok
end
end
module Autotest::Growl
Autotest.add_hook :ran_command do |at|
output = at.results.last.slice(/(\d+).*(failure|error)/).gsub(/31m/, "")
if output !~ /\s0\s/
status, priority = "fail", "High"
else
status, priority = "pass", "Normal"
end
image_dir = "~/Library/autotest"
growl_notify status, "Test Results", output, "#{image_dir}/rails_#{status}.p
# Allow the metal piece to run in isolation
require(File.dirname(__FILE__) + "/../../config/environment") unless defined?(Rails)
class LegacyRoutes
class << self
def call(env)
if env["PATH_INFO"] =~ /^\/pages\//
[301, {"Location" => "/projects", "Content-Type" => "text/html"}, ["Moved Permanently"]]
else
[404, {"Content-Type" => "text/html"}, ["Not Found"]]
devel:redis-store luca$ rake --trace
(in /Users/luca/Projects/redis-store)
** Invoke default (first_time)
** Invoke spec (first_time)
** Execute spec
/Users/luca/ruby19/lib/ruby/gems/1.9.1/gems/merb-core-1.0.11/lib/merb-core/dispatch/router/behavior.rb:18: warning: undefining `object_id' may cause serious problem
/Users/luca/ruby19/lib/ruby/gems/1.9.1/gems/merb-core-1.0.11/lib/merb-core/dispatch/router/behavior.rb:18: warning: undefining `__send__' may cause serious problem
/Users/luca/ruby19/lib/ruby/gems/1.9.1/gems/ParseTree-3.0.3/lib/parse_tree.rb:3:in `<top (required)>': ParseTree doesn't work with ruby 1.9.1 (LoadError)
from /Users/luca/ruby19/lib/ruby/gems/1.9.1/gems/merb-action-args-1.0.11/lib/merb-action-args/get_args.rb:2:in `require'
from /Users/luca/ruby19/lib/ruby/gems/1.9.1/gems/merb-action-args-1.0.11/lib/merb-action-args/get_args.rb:2:in `<top (required)>'