Skip to content

Instantly share code, notes, and snippets.

View thibaudgg's full-sized avatar

Thibaud Guillaume-Gentil thibaudgg

View GitHub Profile
@cpuguy83
cpuguy83 / mongoid_conn_pool.rb
Last active December 19, 2015 11:09
Working out connection pooling for Mongoid. Right now in Mongoid every thread gets a new connection, and is not closing those connections when the thread is complete.
require 'thread'
require 'thread_safe'
require 'monitor'
module Mongoid
def with_session(&block)
Sessions.with_session(&block)
end
module Config
option :session_pool_size, :default => 5
@ahoward
ahoward / kew.rb
Created April 23, 2013 22:49
portable (jruby / ruby) queue that should work in ruby 2.0, planning to use handling signals pushed via trap(sig){ ... }
class Kew
require 'thread'
require 'socket'
def initialize
@pipes = UNIXSocket.pair(:STREAM, 0)
@mutex = Mutex.new
end
def pipe
@ryanb
ryanb / spec_helper.rb
Created September 12, 2011 21:37
Use RSpec tags to add behavior around specs.
# Add this to your spec_helper.rb
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.around(:each, :vcr) do |example|
name = example.metadata[:full_description].downcase.gsub(/\W+/, "_").split("_", 2).join("/")
VCR.use_cassette(name, :record => :new_episodes) do
example.call
end
end
end
@ryanb
ryanb / spec_helper.rb
Created September 12, 2011 21:29
Focus on specific specs in RSpec
# add this to your spec helper
RSpec.configure do |config|
config.treat_symbols_as_metadata_keys_with_true_values = true
config.filter_run :focus => true
config.run_all_when_everything_filtered = true
end
# and then use the :focus tag in your specs
it "does something awesome", :focus do
@dhh
dhh / gist:1014971
Created June 8, 2011 18:09
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@mislav
mislav / _notes.md
Created July 21, 2010 18:25
"livereload" server replacement for working with Rails

A replacement for "livereload" gem on OS X

This script is a replacement for livereload server component designed for working with Rails. It watches the filesystem with FS Events (Mac OS X) rather than with EventMachine. This is better for large projects for wich EventMachine fails with "too many open files" exception.

Sass is supported; .sass files can also be stored in "app/styles/" directory. Compass is detected if "config/compass.rb" file exists.

Installation:

Download this script to somewhere in your PATH and make it executable. You can name it something different than "livereload" if you want to try this and the official gem executable in parallel.

@cimm
cimm / gist:463765
Created July 4, 2010 21:10
Creates an Heroku bundle and downloads the result, removing the old local backup if needed.
#!/usr/bin/env ruby
app = "your-heroku-app"
STDOUT.sync = true
start_time = Time.now
# Prepare old backup for rotate if needed
if File.exist?("#{app}.tar.gz.backup")
puts "\e[31mThe previous backup did not end well, check manually.\e[0m"
#!/usr/bin/ruby
if ARGV.size < 1 || ARGV.size > 2
puts "Usage: #{__FILE__} PATH_TO_PROJECT [CIJOE_URL]"
exit 1
end
##############################
JABBER_USERNAME = "example@gmail.com"
JABBER_PASSWORD = "secret"
@georgebrock
georgebrock / Rakefile
Created February 18, 2010 23:32
Rake tasks to manage Heroku deploys
namespace :deploy do
PRODUCTION_APP = 'myapp'
STAGING_APP = 'myapp-staging'
def run(*cmd)
system(*cmd)
raise "Command #{cmd.inspect} failed!" unless $?.success?
end
def confirm(message)