Skip to content

Instantly share code, notes, and snippets.

View morgoth's full-sized avatar

Wojciech Wnętrzak morgoth

View GitHub Profile
# hack for the chef - we cannot read file in http_request resource
ruby_block "Set attributes for http request for #{database[:name]} #{database[:kind]}" do
block do
request = resources(:http_request => "Create backup record for #{database[:name]} #{database[:kind]}")
request.message({:backup => {:filename => compressed_file_name, :kind => database[:kind], :size => File.size(compressed_file_path)}})
end
end
http_request "Create backup record for #{database[:name]} #{database[:kind]}" do
url "http://some-url/backups"
# attributes/default.rb
default[:my_attribute] = false
# on some machine:
chef-client -j example.json
# example.json
{"run_list": "recipe[example]", "my_attribute": true}
value used in recipe is now true
script "Install rvm" do
interpreter "bash"
user node[:app][:name]
code <<-EOH
export
rvm_path="${rvm_path:-$HOME/.rvm}"
mkdir -p $rvm_path/src/
builtin cd $rvm_path/src
rm -rf ./rvm/
git clone --depth 1 git://github.com/wayneeseguin/rvm.git
@morgoth
morgoth / gist:498149
Created July 29, 2010 13:39
chef recipe error
# rvm is installed into /usr/local/rvm
# all users added to group rvm can manage rubies
package "curl"
package "libreadline5-dev" # for ruby ree
template "/etc/gemrc" do
source "gemrc.erb"
end
/home/wojtek/Ruby/libre/config/initializers/haml.rb:1:in `<top (required)>': uninitialized constant Haml::Template (NameError)
from /home/wojtek/.rvm/gems/ruby-1.9.1-p378/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/engine.rb:199:in `block (2 levels) in <class:Engine>'
from /home/wojtek/.rvm/gems/ruby-1.9.1-p378/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/engine.rb:198:in `each'
from /home/wojtek/.rvm/gems/ruby-1.9.1-p378/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/engine.rb:198:in `block in <class:Engine>'
from /home/wojtek/.rvm/gems/ruby-1.9.1-p378/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/initializable.rb:25:in `instance_exec'
from /home/wojtek/.rvm/gems/ruby-1.9.1-p378/bundler/gems/rails-16a5e918a06649ffac24fd5873b875daf66212ad-master/railties/lib/rails/initializable.rb:25:in `run'
from /home/wojtek/.rvm/gems/ruby-1.9.1-p378/bundler/
/home/slugs/143697_fd755c5_8ed7/mnt/.bundle/gems/gems/bundler-0.9.19/lib/bundler/environment.rb:83:in `initialize': Read-only file system - /disk1/home/slugs/143697_fd755c5_8ed7/mnt/.bundle/environment.rb - Heroku has a read-only filesystem. See http://docs.heroku.com/constraints#read-only-filesystem (Errno::EROFS)
from /home/slugs/143697_fd755c5_8ed7/mnt/.bundle/gems/gems/bundler-0.9.19/lib/bundler/environment.rb:83:in `open'
from /home/slugs/143697_fd755c5_8ed7/mnt/.bundle/gems/gems/bundler-0.9.19/lib/bundler/environment.rb:83:in `write_rb_lock'
from /home/slugs/143697_fd755c5_8ed7/mnt/.bundle/gems/gems/bundler-0.9.19/lib/bundler/runtime.rb:10:in `initialize'
from /home/slugs/143697_fd755c5_8ed7/mnt/.bundle/gems/gems/bundler-0.9.19/lib/bundler.rb:102:in `new'
from /home/slugs/143697_fd755c5_8ed7/mnt/.bundle/gems/gems/bundler-0.9.19/lib/bundler.rb:102:in `runtime'
from /home/slugs/143697_fd755c5_8ed7/mnt/.bundle/gems/gems/bundler-0.9.19/lib/bundler.rb:96:in `load'
from /home/slugs/143697_fd755c5_8ed7
# config/initializers/i18n_ascii_8bit.rb
module I18n
module Backend
class Simple
def load_yml(filename)
traverse(YAML::load(IO.read(filename))) { |o| o.force_encoding(Encoding::ASCII_8BIT) if o.respond_to?(:force_encoding) }
end
def traverse(object, &block)
# encoding: ASCII-8BIT
require 'test_helper'
class SearchTest < ActiveSupport::TestCase
self.use_transactional_fixtures = false
def self.startup
start_sphinx do
us_country = Factory(:us_country)
# Semantic error messages for is used with formtastic and it will generate error messages for attributes you
# are passing including base.
# You can use it like this:
# - semantic_form_for (...)
# = semantic_error_messages_for @model, :attribute, :another_one
def semantic_error_messages_for(object, *methods)
full_errors = methods.inject([]) do |array, method|
attribute = object.class.human_attribute_name(method)
errors = Array(object.errors.on(method)).to_sentence