Skip to content

Instantly share code, notes, and snippets.

View mikhailov's full-sized avatar

Anatoly Mikhaylov mikhailov

View GitHub Profile
@mikhailov
mikhailov / capistrano_log_recipes.rb
Created March 25, 2011 06:24
Capistrano extra recipes
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
end
end
@mikhailov
mikhailov / mysql_strict.rb
Created July 2, 2012 08:32
Rails 3.2 monkey-patch to enable Mysql strict mode by default
class ActiveRecord::ConnectionAdapters::Mysql2Adapter
private
alias_method :configure_connection_without_strict_mode, :configure_connection
def configure_connection
configure_connection_without_strict_mode
strict_mode = "SQL_MODE='STRICT_ALL_TABLES'"
execute("SET #{strict_mode}", :skip_logging)
end
@mikhailov
mikhailov / 0. nginx_setup.sh
Last active April 2, 2024 14:57
NGINX+SPDY with Unicorn. True Zero-Downtime unless migrations. Best practices.
# 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
#
# SERVER:
# /etc/init.d/nginx (1. nginx)
# /home/app/public_html/app_production/current (Capistrano directory)
#
@mikhailov
mikhailov / 0. nginx_setup.sh
Last active December 26, 2022 19:30
Nginx + secure pseudo-streaming
# 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: http://coderwall.com/p/3hksyg
cd /usr/src
wget http://nginx.org/download/nginx-1.5.13.tar.gz
tar xzvf ./nginx-1.5.13.tar.gz && rm -f ./nginx-1.5.13.tar.gz
@mikhailov
mikhailov / deploy.rb
Created July 26, 2012 09:14
capistrano prettify
# 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
mikhailov / script.sh
Created October 13, 2012 09:22
Fight with TCP Slow Start
#!/bin/sh
ip route |grep default # default via 10.235.9.1 dev eth0
ip route change default via `ip route| awk '/^def/{print $3}'` dev eth0 initcwnd 16
ip route |grep default # default via 10.235.9.1 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
mikhailov / Vagrantless
Last active October 15, 2017 09:37
Vagrantless (draft), tested on OS X only.
# This the bash script to handle up-and-runnig VM created through Vagrant
#!/usr/bin/env bash
# PRIVATE: error level message
error_message () {
echo "$(tput setaf 1)ERROR: $1$(tput sgr0)"
}
@mikhailov
mikhailov / sysctl.conf
Last active January 3, 2016 19:09
OS X Server TCP/IP tuning
net.inet.tcp.sack=1
net.inet.tcp.rfc1323=1
net.inet.tcp.recvspace=1048576
net.inet.udp.recvspace=1048576
net.inet.tcp.sendspace=1048576
net.inet.tcp.mssdflt=1460
net.inet.tcp.win_scale_factor=8
@mikhailov
mikhailov / nginx.conf
Last active October 7, 2018 10:15
Jira connection optimised (Nio enabled, gzip disabled on Tomcat, but enabled on Reverse proxy side, Proxy with HTTP 1.1 keep-alive, SSL offload, SPDY). Nginx 1.5.10+ recommended.
echo 'events {
worker_connections 1024;
}
error_log /usr/local/Cellar/nginx/1.5.8/error.log;
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
@mikhailov
mikhailov / gist:9639593
Last active November 10, 2023 22:04
Nginx S3 Proxy with caching
events {
worker_connections 1024;
}
http {
default_type text/html;
access_log /dev/stdout;
sendfile on;
keepalive_timeout 65;