Skip to content

Instantly share code, notes, and snippets.

View preinitializer.rb
require "rubygems"
require "bundler"
rescue LoadError
raise "Could not load the bundler gem. Install it with `gem install bundler`."
if <="0.9.24")
raise RuntimeError, "Your bundler version is too old." +
"Run `gem install bundler` to upgrade."
View boot.rb
# Don't change this file!
# Configure your app in config/environment.rb and config/environments/*.rb
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
module Rails
class << self
def boot!
unless booted?
View environment.rb
require "bundler"
Bundler.require(:default, :development)
# ENV['RAILS_ENV'] ||= 'production'
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
View Gemfile
source ""
gem 'rails', '2.3.5'
gem 'aasm', '2.1.5'
gem 'acts-as-taggable-on', '2.0.4'
gem 'activemerchant', '1.5.1'
gem 'authlogic', '2.1.5'
gem 'aws-s3', '0.6.2'
gem 'configatron', '2.6.0'
#Percona-XtraDB obsoletes mysql-server packages, so upgrade is pretty straightforward.
#Instead of updating currently installed packages Percona-XtraDB should be installed. It will replace currently #installed mysql-server, mysql-client, etc.
# Dont's do it straight on production server, let's try on the staging one
#!/bin/bash -e
cat<<EOF> /etc/yum.repos.d/Percona.repo
name=CentOS-$releasever - Percona
View rcov.rake
require 'cucumber/rake/task'
require 'spec/rake/spectask'
require 'database_cleaner'
namespace :rcov do do |t|
t.rcov = true
t.rcov_opts = %w{--rails --exclude osx\/objc,gems\/,spec\/,features\/ --aggregate}
t.rcov_opts << %[-o "coverage"]
mikhailov / redis_usage.rb
Created Jan 18, 2010
Rails on Redis - is all about high performance
View redis_usage.rb
# app/controllers/posts_controller.rb
class PostsController < ApplicationController
def index
@posts.all_cached # Retrive only at once by every 5 minutes
expires_in 5.minutes, :private => false, :public => true
# app/models/post.rb
Class Post
View Benchmarks.rb
script/performance/benchmarker 50 "Banner.within_street('М').collect(&:street)"
user system total real
#1 20.300000 0.030000 20.330000 ( 25.248899)
script/performance/benchmarker 50 '"^М*", :per_page => 10000).collect(&:street)'
user system total real
#1 107.010000 0.100000 107.110000 (109.985505)
script/performance/benchmarker 1000 'BannerFormat.all'
View environment.rb
Checking the memcached & sphinx running
if $0 == 'script/server'
# Check for memcached
# check if memcached is running; if it is, use that instead of the default memory cache
Timeout.timeout(0.5) {"localhost", 11211) { } }
config.cache_store = :mem_cache_store, %w(localhost:11211), { :namespace => 'zimaletto', :timeout => 60 }
$stderr.puts "\033[0;32mUsing memcached on localhost:11211\033[0;34m"
rescue StandardError
View circumcircle
A = d2[0] - d1[0];
B = d2[1] - d1[1];
C = d3[0] - d1[0];
D = d3[1] - d1[1];