Skip to content

Instantly share code, notes, and snippets.

View vladvinnikov's full-sized avatar

Vladimir Vinnikov vladvinnikov

View GitHub Profile
after "deploy:symlink", "deploy:restart_workers"
##
# Rake helper task.
# http://pastie.org/255489
# http://geminstallthat.wordpress.com/2008/01/27/rake-tasks-through-capistrano/
# http://ananelson.com/said/on/2007/12/30/remote-rake-tasks-with-capistrano/
def run_remote_rake(rake_cmd)
rake_args = ENV['RAKE_ARGS'].to_s.split(',')
cmd = "cd #{fetch(:latest_release)} && #{fetch(:rake, "rake")} RAILS_ENV=#{fetch(:rails_env, "production")} #{rake_cmd}"
module RedisHelper
# decode Redis value back to Ruby object
def self.decode(json)
self.new(ActiveSupport::JSON.decode(json)["#{self.name.downcase}"])
end
# encode Ruby object for Redis
def encoded
self.updated_at = nil
self.to_json
@vladvinnikov
vladvinnikov / indexes
Last active December 15, 2015 03:29
Mysql indexes
Индексы – допуск к высокой производительности MySQL, их необходимость и важность увеличивается пропорционально росту объема данных в базе. Индексы необходимо создавать для столбцов, по которым:
- происходит поиск в части WHERE
- идет соединение таблиц при JOIN
- выполняется сортировка и группировка записи при GROUP BY и ORDER BY
- осуществляется поиск MIN() и MAX()
Индексы бывают составными, в этом случае очень важен порядок столбцов.
Разбирая вывод EXPLAIN, стоит обратить внимание на столбцы:
Попробуйте http://nginx.org/en/docs/http/ngx_http_upstream_module.html#least_conn
Ну или haproxy с "balance leastconn".
Конфиги типа таких
на сервере, где стоит nginx, который распределяет запросы
upstream myserv_production {
ip_hash;
class MyModel < ActiveRecord::Base
has_attached_file :photo,
:styles => { :original => "1024x1024>", :thumb => "150x150>" }
end
RSpec.configure do |config|
config.around do |example|
# For examples using capybara-webkit for example.
# Remove this if you don't use it or anything similar
if example.metadata[:js]
example.run
ActiveRecord::Base.connection.execute("TRUNCATE #{ActiveRecord::Base.connection.tables.join(',')} RESTART IDENTITY")
else
ActiveRecord::Base.transaction do
@vladvinnikov
vladvinnikov / install_ruby_debug.sh
Created March 24, 2012 15:27 — forked from janv/install_ruby_debug.sh
Install Ruby-debug with RVM using Ruby 1.9.3-p0-falcon
#!/bin/sh
curl -LO http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
curl -LO http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
gem install linecache19-0.5.13.gem
gem install ruby-debug-base19-0.11.26.gem -- --with-ruby-include=$HOME/.rvm/rubies/ruby-1.9.3-p0-falcon/include/ruby-1.9.1/ruby-1.9.3-p0/
rm linecache19-0.5.13.gem
rm ruby-debug-base19-0.11.26.gem
@vladvinnikov
vladvinnikov / gist:2183518
Created March 24, 2012 14:29
Ruby 1.9.3 ruby-debug19
#!/bin/sh
rvm_current=`rvm current`
echo "Installing ruby-debug with $rvm_current ..."
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
gem install linecache19-0.5.13.gem ruby-debug-base19-0.11.26.gem ruby-debug19 -- --with-ruby-include=$rvm_path/src/$rvm_current
@vladvinnikov
vladvinnikov / gist:2063777
Created March 17, 2012 18:18
Rails rspec speedup
http://blog.carbonfive.com/2011/02/02/crank-your-specs/
https://makandracards.com/makandra/950-speed-up-rspec-by-deferring-garbage-collection
https://github.com/tmm1/perftools.rb
RUBY_HEAP_MIN_SLOTS=500000
RUBY_HEAP_SLOTS_INCREMENT=500000
RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
RUBY_GC_MALLOC_LIMIT=100000000
RUBY_HEAP_FREE_MIN=500000
@vladvinnikov
vladvinnikov / gist:1979167
Created March 5, 2012 16:35
Fucking ImageMagick
wget ftp://ftp.imagemagick.org/pub/ImageMagick/ImageMagick.tar.gz
> tar -xzvf ImageMagick.tar.gz
> ./configure --prefix=/usr/local --with-x=no --disable-static --with-modules --without-perl --without-magick-plus-plus --with-quantum-depth=8 --disable-openmp
> make
> sudo make install
> sudo /sbin/ldconfig /usr/local
> sudo ln -f /usr/local/bin/Magick-config /usr/bin/Magick-config
> sudo PKG_CONFIG_PATH=/usr/local/lib/pkgconfig/ gem install rmagick