Skip to content

Instantly share code, notes, and snippets.

mikhailov /
Created Oct 13, 2012
Fight with TCP Slow Start
ip route |grep default # default via dev eth0
ip route change default via `ip route| awk '/^def/{print $3}'` dev eth0 initcwnd 16
ip route |grep default # default via dev eth0 initcwnd 16
sysctl -w net.ipv4.tcp_slow_start_after_idle=0
sysctl -a |grep net.ipv4.tcp_slow_start_after_idle
mikhailov / deploy.rb
Created Jul 26, 2012
capistrano prettify
View deploy.rb
# standard capistrano config goes here....
# Put the maintenance screen if DB migrations take in place only
before "deploy", "deploy:delayed_job:stop"
before "deploy:migrations", "deploy:delayed_job:stop"
after "deploy:update_code", "deploy:symlink_shared", "deploy:assets_compress"
before "deploy:migrate", "deploy:web:disable", "deploy:db:backup"
after "deploy", "newrelic:notice_deployment", "deploy:cleanup", "deploy:delayed_job:restart"
mikhailov / 0.
Last active Sep 14, 2021
Nginx + secure pseudo-streaming
View 0.
# Nginx can serve FLV/MP4 files by pseudo-streaming way without any specific media-server software.
# To do the custom build we use 2 modules: --with-http_secure_link_module --with-http_flv_module
# This module "secure-link" helps you to protect links from stealing away.
# NOTE: see more details at coderwall:
cd /usr/src
tar xzvf ./nginx-1.5.13.tar.gz && rm -f ./nginx-1.5.13.tar.gz
mikhailov / 0.
Last active Jan 14, 2021
NGINX+SPDY with Unicorn. True Zero-Downtime unless migrations. Best practices.
View 0.
# Nginx+Unicorn best-practices congifuration guide. Heartbleed fixed.
# We use latest stable nginx with fresh **openssl**, **zlib** and **pcre** dependencies.
# Some extra handy modules to use: --with-http_stub_status_module --with-http_gzip_static_module
# Deployment structure
# /etc/init.d/nginx (1. nginx)
# /home/app/public_html/app_production/current (Capistrano directory)
mikhailov / mysql_strict.rb
Created Jul 2, 2012
Rails 3.2 monkey-patch to enable Mysql strict mode by default
View mysql_strict.rb
class ActiveRecord::ConnectionAdapters::Mysql2Adapter
alias_method :configure_connection_without_strict_mode, :configure_connection
def configure_connection
strict_mode = "SQL_MODE='STRICT_ALL_TABLES'"
execute("SET #{strict_mode}", :skip_logging)
View capistrano_log_recipes.rb
namespace :log do
desc "A pinch of tail"
task :tailf, :roles => :app do
run "tail -n 10000 -f #{shared_path}/log/#{rails_env}.log" do |channel, stream, data|
puts "#{data}"
break if stream == :err
mikhailov /
Created Mar 11, 2011
Ruby’s GC Configuration
article’s settings: ("spec spec" took 17-23!sec)
export RUBY_HEAP_MIN_SLOTS=1250000
export RUBY_GC_MALLOC_LIMIT=30000000
export RUBY_HEAP_FREE_MIN=12500
mikhailov /
Created Nov 23, 2010
nginx+passenger (real production config)
# NOTICE: to get Nginx+Unicorn best-practices configuration see the gist
$ cd /usr/src
$ wget
$ tar xzvf ./nginx-1.2.1.tar.gz && rm -f ./nginx-1.2.1.tar.gz
$ wget
$ tar xzvf pcre-8.30.tar.gz && rm -f ./pcre-8.30.tar.gz
$ wget
mikhailov / gist:706275
Created Nov 19, 2010
nginx native ssl redirection without ssl_requirement
View gist:706275
server {
listen 80;
server_name *;
rewrite ^(.*) https://$host$1 permanent;
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');
}).ajaxStop(function() {