Skip to content

Instantly share code, notes, and snippets.

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 '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'
@mikhailov
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
end
end
# app/models/post.rb
Class Post
View rcov.rake
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
View Percona-XtraDB.sh
#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/
View Gemfile
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'
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 preinitializer.rb
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."
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?
preinitialize
@mikhailov
mikhailov / ajax_defaults.js
Created Aug 25, 2010
automatically show/hide ajax-spinner + disable/enable submit buttons
View ajax_defaults.js
var spinner = $('#ajax-spinner');
$(document).ajaxSend(function() {
$('input[type=submit]').attr('disabled', 'disabled');
$('#warningBox').hide();
spinner.show()
}).ajaxStop(function() {
$('input[type=submit]').removeAttr('disabled');
spinner.hide()
});
@mikhailov
mikhailov / uf.rb
Last active Sep 20, 2015
union find
View uf.rb
class UF
attr_reader :array
def initialize(array)
@array = array
end
def union(p,q)
return if p == q