Skip to content

Instantly share code, notes, and snippets.

View mikhailov's full-sized avatar

Anatoly Mikhaylov mikhailov

View GitHub Profile
begin
require "rubygems"
require "bundler"
rescue LoadError
raise "Could not load the bundler gem. Install it with `gem install bundler`."
end
if Gem::Version.new(Bundler::VERSION) <= Gem::Version.new("0.9.24")
raise RuntimeError, "Your bundler version is too old." +
"Run `gem install bundler` to upgrade."
# 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?
preinitialize
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')
source "http://rubygems.org"
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
[percona]
name=CentOS-$releasever - Percona
baseurl=http://repo.percona.com/centos/5Server/os/i386/
require 'cucumber/rake/task'
require 'spec/rake/spectask'
require 'database_cleaner'
namespace :rcov do
Cucumber::Rake::Task.new(:cucumber) do |t|
t.rcov = true
t.rcov_opts = %w{--rails --exclude osx\/objc,gems\/,spec\/,features\/ --aggregate coverage.data}
t.rcov_opts << %[-o "coverage"]
end
@mikhailov
mikhailov / redis_usage.rb
Created January 18, 2010 06:52
Rails on Redis - is all about high performance
# 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
end
end
# app/models/post.rb
Class Post
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 'Banner.search("^М*", :per_page => 10000).collect(&:street)'
user system total real
#1 107.010000 0.100000 107.110000 (109.985505)
script/performance/benchmarker 1000 'BannerFormat.all'
Checking the memcached & sphinx running
if $0 == 'script/server'
# Check for memcached
begin
# check if memcached is running; if it is, use that instead of the default memory cache
Timeout.timeout(0.5) { TCPSocket.open("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
#!/usr/local/bin/ruby
d1=[83,51]
d2=[85,31]
d3=[18,137]
A = d2[0] - d1[0];
B = d2[1] - d1[1];
C = d3[0] - d1[0];
D = d3[1] - d1[1];