Skip to content

Instantly share code, notes, and snippets.

View Bregor's full-sized avatar

Maxim Filatov Bregor

View GitHub Profile
@yas375
yas375 / README
Created December 30, 2010 12:24
Контролируемое скачивание файлов на rails 2 с nginx
Контролируемое скачивание файлов через rails 2 в связке с nginx.
Используется заголовок X-Accel-Redirect nginx'а, который делает так,
что файл отдаёт не приложение, а сам сервер, таким образом на приложение
меньше нагрузки.
Ссылки по теме:
http://groups.google.com/group/ror2ru/browse_thread/thread/1733088704f9278e -
обсуждение в группе ror2ru
http://wiki.nginx.org/XSendfile
class Fixnum
def seconds
self
end
def minutes
self * 60
end
def hours
@mikhailov
mikhailov / installation.sh
Created November 23, 2010 15:18
nginx+passenger (real production config)
# NOTICE: to get Nginx+Unicorn best-practices configuration see the gist https://gist.github.com/3052776
$ cd /usr/src
$ wget http://nginx.org/download/nginx-1.2.1.tar.gz
$ tar xzvf ./nginx-1.2.1.tar.gz && rm -f ./nginx-1.2.1.tar.gz
$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.30.tar.gz
$ tar xzvf pcre-8.30.tar.gz && rm -f ./pcre-8.30.tar.gz
$ wget http://www.openssl.org/source/openssl-1.0.1c.tar.gz
@DmitrySoshnikov
DmitrySoshnikov / python-closures.py
Created November 15, 2010 12:03
Understanding Python's closures
# "Understanding Python's closures".
#
# Tested in Python 3.1.2
#
# General points:
#
# 1. Closured lexical environments are stored
# in the property __closure__ of a function
#
# 2. If a function does not use free variables
preload_app true
GC.respond_to?(:copy_on_write_friendly=) and
GC.copy_on_write_friendly = true
before_fork do |server, worker|
# the following is highly recomended for Rails + "preload_app true"
# as there's no need for the master process to hold a connection
defined?(ActiveRecord::Base) and
ActiveRecord::Base.connection.disconnect!
@dnagir
dnagir / rspec-syntax-cheat-sheet.rb
Created November 5, 2010 09:29
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@sax
sax / nginx.conf
Created September 7, 2010 22:49
unicorn + nginx on launchd
user sax staff;
worker_processes 1;
daemon off;
error_log /var/log/nginx/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
pid /var/run/nginx.pid;
# In your test_helper.rb
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || retrieve_connection
end
end