Skip to content

Instantly share code, notes, and snippets.

View mbj's full-sized avatar

Markus Schirp mbj

View GitHub Profile
@mbj
mbj / a_model.rb
Created December 20, 2011 17:50
my custom unit implementation with datamapper_load and datamapper_dump methods
class AModel
include DataMapper::Mongo::Resource
property :id,ObjectId
property :unit, EmbeddedDocument, :document_class => MyUnits::Unit
end
@mbj
mbj / config
Created January 13, 2012 12:35
systemctl status check
radon# cat /etc/systemd/system/mongodb.service
[Unit]
Description=MongoDB Server
Wants=network.target
After=network.target
[Service]
Type=simple
ExecStart=/usr/bin/mongod --config /etc/mongodb.conf
User=mongodb
@mbj
mbj / evenstorm.rb
Created February 4, 2012 20:11
simple evenstorm client interface
# Simple evenstorm client library from brain
# Wo any testing, ZMQ API consultation etc
class Evenstorm
def initialize(connect_str)
@context = ZMQ::Context.new
@socket = @context.socket(::ZMQ::PUB)
@socket.connect(connect_str)
@socket.setsockopt(ZMQ::Linger,0)
at_exit do
@mbj
mbj / mapper.rb
Created May 22, 2012 18:41
Experimental mapper, with much to verbose setup.
# This is a mapper I created when I was in hurry/spiking using:
# github.com/mbj/mapper (a stupid try-to-be-most-generic mapper implementation, to be rewritten)
# github.com/mbj/session (a database session/IdentityMap that can possibly work with any (document) mapper)
# the Session thing is more or less stable, and I like it!
# This code is not used anymore, it was replaced by a non generic application specific mapper to elasticsearch.
# Also this code never went to production.
# The whole point of this literal mess was to transform a tree of objects into a document that could be stored within mongo.
# The virtus object tree should be reconstructed 1:1.
@mbj
mbj / external_aequitas_validator.rb
Created July 20, 2012 10:34
Use aequitas as external validator
module ExternalValidator
def self.included(descendant)
descendant.class_eval do
InstanceMethods
end
end
module InstanceMethods
def initialize(object)
@object = object
@mbj
mbj / session-uow-middleware-arguments.rb
Created October 1, 2012 19:18
UoW as middleware between session and mapper arguments
# Without any UoW session <=> mapper
session = DataMapper.session
user = session.get(User, 1)
user.mutate
session.sync(user) # Update on db happens
session.all(User) # => [MutatedUser, OtherUser]
# With UoW as middleware
session = DatAMapper.session
user = session.get(User, 1)
@mbj
mbj / extend_module_with_context.rb
Created October 21, 2012 20:26
Ruby imperfectness?
module ModuleWithMethod
def the_method
end
end
class ModuleWithContext < ::Module
def initialize(context)
@context = context
end
@mbj
mbj / name.rb
Created November 6, 2012 20:32
Anonymous ruby class names?
klass = Class.new # an anonymous class
klass.name # => "" does not have a name
Foo = klass # but when assigned to a constant:
p klass.name # => "Foo" it has a name! Magic! *happy*
Bar = klass # Again?
p klass.name # => "Foo" no magic :(
p Bar.name # => "Foo" still...
# Really like ruby outside of unavoidable edge cases!
# The assumption Class.new.name == nil can also be broken far far away from Class.new!
@mbj
mbj / tree_walker.rb
Created November 6, 2012 22:12
dm-1 associated records external tree walker
class TreeWalker
def initialize(customer, &block)
@customer, @block = customer, blocj
end
def emit(resource)
@block.call(resource)
end
def customer(customer)
@mbj
mbj / foo.rb
Created November 6, 2012 23:33
dm-2 heckle spec style helper
class Foo
def bar
:baz
end
end