Skip to content

Instantly share code, notes, and snippets.

View krasio's full-sized avatar
🎣
Gone fishing

Krasimir Angelov krasio

🎣
Gone fishing
View GitHub Profile
@krasio
krasio / rspec.rake
Created April 26, 2012 13:51
lib/tasks/rspec.rake
require 'rake'
require 'rspec/core/rake_task'
task :noop do; end
spec_prereq = Rails.configuration.generators.options[:rails][:orm] == :active_record ? "db:test:prepare" : :noop
namespace :spec do
RSpec::Core::RakeTask.new(:lite) do |t|
t.pattern = "spec/{models,presenters}/**/*_spec.rb"
end
@krasio
krasio / nulldb.rb
Created April 10, 2012 14:30
spec/support/lite/nulldb.rb
require 'nulldb'
module NullDB
class << self
def nullify(options={})
begin
@prev_connection = ActiveRecord::Base.connection_pool.try(:spec)
rescue
end
ActiveRecord::Base.establish_connection(options.merge(:adapter => :nulldb))
@krasio
krasio / ruby_gc.sh
Created February 28, 2012 10:02 — forked from mikhailov/ruby_gc.sh
Ruby’s GC Configuration
- http://www.coffeepowered.net/2009/06/13/fine-tuning-your-garbage-collector/
- http://snaprails.tumblr.com/post/241746095/rubys-gc-configuration
article’s settings: ("spec spec" took 17-23!sec)
export RUBY_HEAP_MIN_SLOTS=1250000
export RUBY_HEAP_SLOTS_INCREMENT=100000
export RUBY_HEAP_SLOTS_GROWTH_FACTOR=1
export RUBY_GC_MALLOC_LIMIT=30000000
export RUBY_HEAP_FREE_MIN=12500
1.9.3
-------------------------
$ ruby -v
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.3.0]
$ time ruby script/rails runner "puts 1"
1
real 0m9.731s
user 0m8.595s
@krasio
krasio / gist:1560639
Created January 4, 2012 15:51 — forked from tjl2/gist:1330498
Changing the count and memory limit of Passenger processes on Engine Yard Cloud

This was going to go into a blog post, but was removed after discussion around it being a Bad Thing for customers to do.

Changing the count and memory limit of Passenger processes

To stop applications that are prone to bloating quickly exhausting all the memory on an application instance, we have a script called passenger_monitor that checks for runaway Passenger processes every minute via a cron job. By default, this script is going to look for Passenger workers that are using over 215MB of memory and kill them. Passenger will restart them when needed. We tune the number of workers that run by default on your application instances, based on the memory specifications so that the memory is sensibly utilized. However, if your application legitimately requires more memory than this (i.e. it isn’t bloating) then it may be advantageous for you to reduce the worker count, and allow the lower number of workers to use more memory.

Doing this involves two areas of customization; modifying the Nginx configuratio

@krasio
krasio / new-vm.textile
Created December 29, 2011 19:25 — forked from petyosi/new-vm.textile
Instructions on setting up new work VM.

Installation

  • Update your VirtualBox
  • Download ubuntu LTS server (64 bit)
  • name “garmz-dev”
  • Run default installation from the downloaded iso in new VM
    • hostname “garmz-dev”
    • Don’t encrypt home
    • No automatic updates
    • Pick OpenSSH server and PostgreSQL server
@krasio
krasio / excon benchmark
Created December 15, 2011 14:23 — forked from phiggins/excon benchmark
excon benchmark vs google
$ ruby benchmarks/excon_vs_google.rb
[em-http-request, HTTParty, Net::HTTP, Net::HTTP (persistent), open-uri, RestClient, StreamlyFFI (persistent), Typhoeus, Excon, Excon (persistent)]
+--------------------------+-----------+
| tach | total |
+--------------------------+-----------+
| Excon | 7.614298 |
+--------------------------+-----------+
| Typhoeus | 7.723362 |
@krasio
krasio / new-vm.textile
Created December 14, 2011 14:03 — forked from petyosi/new-vm.textile
Instructions on setting up new work VM.

Installation

  • Update your VirtualBox
  • Download ubuntu LTS server (64 bit)
  • name “garmz-dev”
  • Run default installation from the downloaded iso in new VM
    • hostname “garmz-dev”
    • Don’t encrypt home
    • No automatic updates
    • Pick OpenSSH server and PostgreSQL server
@krasio
krasio / passenger_process.rb
Created December 2, 2011 14:31 — forked from leejones/passenger_process.rb
Remove orphaned passenger processes.
require 'chronic'
class PassengerProcess
attr_accessor :pid, :uptime
def initialize(passenger_status_line)
values = passenger_status_line.match(/PID:\s(\d*).*Uptime:\s*(.*)$/)
@pid = values[1].to_i
@uptime = values[2]
end
@krasio
krasio / authentication_macros.rb
Created November 18, 2011 08:38
Rails controller specs with Devise
# spec/support/macros/authentication_macros.rb
module AuthenticationMacros
def sign_in_user
let(:current_user) { Factory.stub(:user) }
before do
sign_in current_user
warden.stub(:authenticate => current_user)
warden.stub(:authenticate! => current_user)
end