Skip to content

Instantly share code, notes, and snippets.

View jodosha's full-sized avatar

Luca Guidi jodosha

View GitHub Profile
source :gemcutter
gem "redis", ">= 2.0.0"
group :development do
gem "jeweler"
gem "git"
end
group :development, :test, :rails3 do
gem "rack"
source :gemcutter
group :development do
gem "jeweler"
gem "git"
gem "sqlite3-ruby"
end
group :test do
gem "hanoi"
source :gemcutter
gem "sinatra"
gem "redis", "2.0.1"
gem "dm-core"
gem "dm-validations"
gem "data_objects"
gem "do_sqlite3"
gem "eventmachine"
source 'http://rubygems.org'
gem 'rails', '2.3.5'
gem 'mysql'
gem 'authlogic', '2.1.3'
gem 'bitly', '0.4.0'
gem 'delayed_job'
gem 'paperclip', '2.3.1.1'
gem 'delayed_paperclip', '0.5.1'
abstract (1.0.0)
actionmailer (3.0.0.rc, 3.0.0.beta4, 3.0.0.beta3, 2.3.8, 2.3.5, 2.3.4)
actionpack (3.0.0.rc, 3.0.0.beta4, 3.0.0.beta3, 2.3.8, 2.3.5, 2.3.4)
activemodel (3.0.0.rc, 3.0.0.beta4, 3.0.0.beta3)
activerecord (3.0.0.rc, 3.0.0.beta4, 3.0.0.beta3, 2.3.8, 2.3.5, 2.3.4)
activeresource (3.0.0.rc, 3.0.0.beta4, 3.0.0.beta3, 2.3.8, 2.3.5, 2.3.4)
activesupport (3.0.0.rc, 3.0.0.beta4, 3.0.0.beta3, 2.3.8, 2.3.5, 2.3.4)
addressable (2.1.2)
after_commit (1.0.7, 1.0.5)
arel (0.4.0, 0.3.3)
ActionController::Base.session = {
:key => '123abc',
:secret => 'xxx',
:key_prefix => 'prefix',
:expire_after => 1.hour
}
ActionController::Base.session_store = :redis_session_store
Capybara.app = Rack::Builder.parse_file(::File.join(Rails.root, 'config.ru')).first
@jodosha
jodosha / pagination.sql
Created February 16, 2011 01:26
Efficient pagination which avoids the use of offsets
-- Let's say we want to paginate bands, ordered by name.
--
-- The main problem with the use of offsets is the waste of loaded records.
-- Math: If you want to load the 7th page (30 artists per page) you will load
-- 210 records (30 * 7), to just use 30 of them. As you can imagine this is
-- more inefficient as the page number grows.
--
-- The alternative is to use the order column(s) as condition, in order to
-- exclude the already loaded records.
--
# config/initializers/assets.rb
AssetsPackager.configure do |config|
config.root_path = ::Rails.public_path
config.file_path = ::Rails.root.join('config', 'assets.yml')
end
@jodosha
jodosha / array.rb
Created April 9, 2011 17:27
Benchmark for Array#empty? vs Array#any?
#!/usr/bin/env ruby -w
require 'benchmark'
TIMES = 10_000_000
EMPTY_ARRAY = [ ]
FILLED_ARRAY = [ 1 ]
Benchmark.bm(30) do |b|
b.report "! Array#empty? with empty array" do