Skip to content

Instantly share code, notes, and snippets.

View snusnu's full-sized avatar

Martin Gamsjaeger snusnu

View GitHub Profile

Keybase proof

I hereby claim:

  • I am snusnu on github.
  • I am snusnu (https://keybase.io/snusnu) on keybase.
  • I have a public key ASCeI7S7w8ue_uXin09T3QyJEqTsv0Jc6ugaGxiDTktOago

To claim this, I am signing this object:

require 'mom'
entities = Mom::Registry.build do # build models using :anima
register :user do
map :id
map :name
group :tasks
end
register :task do
class MethodObject < Module
DEFAULT_NAME = :call
def initialize(name = DEFAULT_NAME)
@name = name
end
def self.included(host)
host.instance_exec(@name) do |name|
define_method :call do |*args|
@snusnu
snusnu / iterator.rb
Last active December 31, 2015 21:39
require 'concord'
class Iterator < Module
include Concord.new(:collection)
private
def included(host)
enumerable = collection
host.class_eval do
require 'axiom-schema'
# A schema (definition) is pure RA, no RDMBS
# concepts are in the mix. Those are only
# added with Axiom::Database objects shown
# further below. Even renaming of attributes
# is not done at this level. It's database
# business. Internally, this is implemented
# by performing a #rename op on an axiom
# relation tho.
@snusnu
snusnu / path_object.rb
Created November 24, 2013 22:30
Path.new.foo.bar.baz.to_a # => [:foo, :bar, :baz]
class Path < BasicObject
def initialize(path = [])
@path = path
end
def to_a
@path.dup
end
require 'ducktrap'
# Very simple ducktrap without any real world use
#
# Not transforming.
#
string = Ducktrap.build do
primitive(String)
end
@snusnu
snusnu / mutant-bug.rb
Created August 3, 2013 02:34
Possible bug in mutant
require 'concord'
class Request
include Concord.new(:input)
end
class Response
include Concord.new(:input, :output)
def to_request(new_input = output)
@snusnu
snusnu / vimrc
Created June 6, 2013 14:49
vimrc snippet to automatically strip trailing whitespace in code files
" a function that preserves the state
" see http://technotales.wordpress.com/2010/03/31/preserve-a-vim-function-that-keeps-your-state/
function! Preserve(command)
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
execute a:command
" Clean up: restore previous search history, and cursor position

Graph::Node only exists because of our pimped jersey header that supports renaming the attributes during a join (and currently only a join, i.e. no support for other binary ops). If axiom would support Relation#join(other, join_definition) there would be no need for Graph::Node. The graph's nodes would be Axiom::Relation instances and the (directed) edges would continue to be composed of a name, a JoinDefinition instance and pointers to both source and target nodes.

ROM::Relation instances should be composed of an Axiom::Relation and a Mapper. Pushing the mapper to the tuple level renders our current AttributeSet useless, or rather, i suspect that its functionality will be subsumed in Mapper. If axiom would support an injectable EvaluatorContext for operations that accept a block (like #join etc), we should be able to come up with a context that is composed of the axiom relation and the mapper, thus allowing us to use "object land" attribute names inside the block, while still const