Skip to content

Instantly share code, notes, and snippets.

View mbj's full-sized avatar

Markus Schirp mbj

View GitHub Profile
@mbj
mbj / embedded_items.rb
Created June 6, 2011 13:50
Using veritas as a pseudo EV replacement in datamapper
# this is full of bad metaprogramming
class EmbeddedItems < DataMapper::Mongo::Property::Array
def load(value)
if value.nil?
nil
elsif value.is_a? ::Array
value.map { |item| embedded_item_class.load item }.extend collection
else
raise ArgumentError.new "+value+ of a property of #{self.class} type must be ::Array was: #{value.class}"
end
@mbj
mbj / validation_set.rb
Created August 15, 2011 22:18
dm-validations proposal for a better command query seperation

Traditional

resource = Resource.new attributes
resource.valid?                  # => true | false
resource.save                    # => true | false Will raise adapter errors in case of Inconsistency
resource.errors                  # => ErrorSet (cached) will not reflect adapter errors
resource.attribute=invalid_value
resource.errors                  # Same error Set as above, will not reflect attribute change
property :id, Serial
property :name, String, required: true
property :size, Integer
property :type, String
property :content, Binary, lazy: true, length: 1..209715200
property :uri, URI
property :created_at, DateTime
property :updated_at, DateTime
belongs_to :folder, model: Filemanager::Folder
@mbj
mbj / ruby-1.8.7-p352 make.log
Created October 10, 2011 10:34
--trace failing install of ruby-1.8.7 on archlinux. Exitstatus of rvm command was zero, expected nonzero
[2011-10-10 17:45:24] make -j2
gcc -g -O2 -fPIC -DRUBY_EXPORT -D_GNU_SOURCE=1 -I. -I. -c array.c
gcc -g -O2 -fPIC -DRUBY_EXPORT -D_GNU_SOURCE=1 -I. -I. -c bignum.c
gcc -g -O2 -fPIC -DRUBY_EXPORT -D_GNU_SOURCE=1 -I. -I. -c class.c
gcc -g -O2 -fPIC -DRUBY_EXPORT -D_GNU_SOURCE=1 -I. -I. -c compar.c
gcc -g -O2 -fPIC -DRUBY_EXPORT -D_GNU_SOURCE=1 -I. -I. -c dir.c
gcc -g -O2 -fPIC -DRUBY_EXPORT -D_GNU_SOURCE=1 -I. -I. -c dln.c
gcc -g -O2 -fPIC -DRUBY_EXPORT -D_GNU_SOURCE=1 -I. -I. -c enum.c
gcc -g -O2 -fPIC -DRUBY_EXPORT -D_GNU_SOURCE=1 -I. -I. -c enumerator.c
gcc -g -O2 -fPIC -DRUBY_EXPORT -D_GNU_SOURCE=1 -I. -I. -c error.c
@mbj
mbj / crash.log
Created October 25, 2011 15:34
Crashing spree / nokogiri @ ruby-1.9.3-rc1q
/home/mbj/.rvm/gems/ruby-1.9.3-rc1/gems/nokogiri-1.5.0/lib/nokogiri/html/document_fragment.rb:23: [BUG] Segmentation fault
ruby 1.9.3dev (2011-09-23 revision 33323) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0139 p:0091 s:0720 b:0719 l:000718 d:000718 METHOD /home/mbj/.rvm/gems/ruby-1.9.3-rc1/gems/nokogiri-1.5.0/lib/nokogiri/html/document_fragment.rb:23
c:0138 p:---- s:0709 b:0709 l:000708 d:000708 FINISH
c:0137 p:---- s:0707 b:0707 l:000706 d:000706 CFUNC :new
c:0136 p:0063 s:0701 b:0701 l:000700 d:000700 METHOD /home/mbj/.rvm/gems/ruby-1.9.3-rc1/gems/nokogiri-1.5.0/lib/nokogiri/xml/node.rb:498
c:0135 p:0094 s:0696 b:0696 l:000695 d:000695 METHOD /home/mbj/.rvm/gems/ruby-1.9.3-rc1/gems/nokogiri-1.5.0/lib/nokogiri/xml/node.rb:894
c:0134 p:0013 s:0692 b:0692 l:000691 d:000691 METHOD /home/mbj/.rvm/gems/ruby-1.9.3-rc1/gems/nokogiri-1.5.0/lib/nokogiri/xml/node.rb:396
@mbj
mbj / stacktrace
Created December 1, 2011 22:33
dm validates far to much records
/home/mbj/devel/foobar/vendor/ruby/1.9.1/gems/bson-1.5.1/lib/bson/bson_c.rb:28:in `new': Interrupt
from /home/mbj/devel/foobar/vendor/ruby/1.9.1/gems/bson-1.5.1/lib/bson/bson_c.rb:28:in `deserialize'
from /home/mbj/devel/foobar/vendor/ruby/1.9.1/gems/mongo-1.5.1/lib/mongo/networking.rb:211:in `read_documents'
from /home/mbj/devel/foobar/vendor/ruby/1.9.1/gems/mongo-1.5.1/lib/mongo/networking.rb:158:in `receive'
from /home/mbj/devel/foobar/vendor/ruby/1.9.1/gems/mongo-1.5.1/lib/mongo/networking.rb:123:in `receive_message'
from /home/mbj/devel/foobar/vendor/ruby/1.9.1/gems/mongo-1.5.1/lib/mongo/cursor.rb:508:in `send_get_more'
from /home/mbj/devel/foobar/vendor/ruby/1.9.1/gems/mongo-1.5.1/lib/mongo/cursor.rb:460:in `refresh'
from /home/mbj/devel/foobar/vendor/ruby/1.9.1/gems/mongo-1.5.1/lib/mongo/cursor.rb:128:in `next'
from /home/mbj/devel/foobar/vendor/ruby/1.9.1/gems/mongo-1.5.1/lib/mongo/cursor.rb:290:in `each'
from /home/mbj/devel/foob
@mbj
mbj / Gemfile
Created December 2, 2011 19:14
DataMapper loads far to much records when saving a child with multiple parents.
DM_VERSION = '1.3.0.beta'
%w(core migrations types aggregates timestamps validations sqlite-adapter do-adapter).each do |name|
if name == 'validations' && ENV['WITHOUT_BREAKING_COMMIT']
gem 'dm-validations', DM_VERSION, :git => 'git://github.com/mbj/dm-validations', :branch => 'test/without-breaking-commit'
else
gem "dm-#{name}", DM_VERSION, :git => "git://github.com/datamapper/dm-#{name}.git"
end
end
@mbj
mbj / gist:1438874
Created December 6, 2011 16:39
export dovecot auth socket
service auth {
unix_listener auth-userdb {
mode = 0660
group = vmail
}
unix_listener /var/spool/postfix/private/auth {
mode = 0666
}
}
@mbj
mbj / rules.txt
Created December 7, 2011 22:34
Our company rules to run batch jobs on a mongodb replica set
Steps before running a batch job on any production mongo cluster:
#1 If you are not the operator, ask him before.
#2 Test the batch on a copy of the dataset before. If the dataset is big, make a representational slice.
#3 Ensure you have a recent backup (or a write behind slave). Bad batches can destroy the company.
#4 Run the batch on "low traffic" times.
#5 Ensure you limit the batch rate using consistent writes to at least one slave.
#6 Notify support, staff, and all possible related personnel before and after the batch.
#7 If you cause any problem, add a solution rule to this document.
@mbj
mbj / embedded_coument.rb
Created December 20, 2011 17:30
DataMapper embedded document for mongodb
module DataMapper
class Property
class EmbeddedDocument < Property
coercion_method nil
dump_as Hash
accept_options :document_class
protected