Skip to content

Instantly share code, notes, and snippets.

View mperham's full-sized avatar

Mike Perham mperham

View GitHub Profile
task :logrotate do
require 'erb'
upload_path = "#{shared_path}/system/logrotate"
template = File.read("deploy/logrotate.erb")
file = ERB.new(template).result(binding)
put file, upload_path, :mode => 0644
run "if [ -e /etc/logrotate.d ]; then sudo cp #{shared_path}/system/logrotate /etc/logrotate.d/#{name}; fi"
end
after 'deploy:symlink', 'deploy:logrotate'
EM.run do
Fiber.new do
# Do everything with Bunny in here
# it will use Fibers + EM
b = Bunny.new(...)
b...
end.resume
end
# Out here, it will use standard Socket-based, synchronous Bunny
~> rvm 1.9.1
~> gem -v
1.3.5
~> gem update --system
Updating RubyGems
Updating rubygems-update
Successfully installed rubygems-update-1.3.6
Updating RubyGems to 1.3.6
Installing RubyGems 1.3.6
RubyGems 1.3.6 installed
@mperham
mperham / README
Created March 25, 2010 12:26 — forked from qrush/README
There's got to be a faster way. This is with a production db dump from a few days ago.
% time rake gemcutter:migrate:downloads
> gemcutter (0.5.0) 131783
>> 0.5.0 19314
>> 15
>> 0.5.0.pre.2 64
>> 15
>> 0.5.0.pre 45
>> 14
# Don't query each rubygem version separately
rows = AR::Base.connection.select_rows "select count(*), version_id, date(created_at) from downloads group by version_id, date(created_at)"
rows.each do |(count, version_id, date)|
# do stuff
end
# \u00A0 is a Unicode non-breaking space and \s should match it if everything is Unicode-# enabled.
> irb
>> RUBY_VERSION
=> "1.9.1"
>> "\u00A0"
=> " "
>> s = _
=> " "
>> s.bytes.to_a
# After rvm upgrade --head...
~> rvm install rbx
Installing pre-requisites
Extracting rubinius-1.0.0-20100514.tar.gz ...
Configuring rbx
Compiling rbx
Installing gems for rbx-1.0.0-p20100514.
Installing rdoc to /Users/mike/.rvm/gems/rbx-1.0.0-p20100514@global
Installing rdoc to /Users/mike/.rvm/gems/rbx-1.0.0-p20100514
Installing rake to /Users/mike/.rvm/gems/rbx-1.0.0-p20100514@global
require 'sanitize'
STRIPPERS = %w(br p).freeze
def cleaner
lambda do |env|
return nil if !STRIPPERS.include?(env[:node_name])
n = env[:node]
txt = Nokogiri::XML::Text.new(' ', n.document)
n.children.each do |c|
# encoding: utf-8
# AR adapter for using a fibered mysql2 connection with EM
# This adapter should be used within Thin or Unicorn with the rack-fiber_pool middleware.
# Just update your database.yml's adapter to be 'em_mysql2'
module ActiveRecord
class Base
def self.em_mysql2_connection(config)
client = ::Mysql2::Fibered::Client.new(config.symbolize_keys)
task :test do
puts `knife cookbook test -a -u foo -c test_config.rb`
end