Skip to content

Instantly share code, notes, and snippets.

@fxn
fxn / gist:274219
Created January 11, 2010 13:05
seach for STI grandchildren who are leaves
# Computes STI models who are grandchildren or more.
#
# In a STI the root class and its subclasses work normally, but if there are
# grandchildren we need to preload them. Reason is, given A < B < C, if you
# for example compute B.count without loading A, only B records are taken into
# account in the query (where a clause about the type column intervenes). This
# is not a bug, Active Record is simply not aware of A. Once it is, the clause
# becomes an OR with all relevant types.
#
# I used this script to compute them.
@solnic
solnic / dm_property_2.0.rb
Created January 18, 2011 12:12
An introduction to DataMapper Property API v. 2.0 (draft)
##
#
# The most important aspect of the new Property API is that
# property inheritance should not be used to instruct
# adapters how to persist data. It means, for example, that
# you should not use Integer as the base class for your custom
# property just because it is persisted as an integer. Right now
# Enum inherits from Integer because it is stored as an integer.
# It is a mistake, because a value of Enum property can be either
# a string or a symbol, not integer. The fact that it is persisted
@solnic
solnic / TODO.markdown
Created March 25, 2011 13:02
This gist shows the status of EmbeddedValue development in dm-core and my notes
  • Integration Model shared specs for Resource/EV:

    • DataMapper::Model::Core
    • DataMapper::Model::Property
    • DataMapper::Model::Hook
    • DataMapper::Model::Relationship
  • Integration Resource shared specs for Resource/EV:

  • DataMapper::Resource::Attributes
| AR 3.0.7 | DM 1.1.1 | SQ 3.22.0 | DIFF_AR_VS_DM | DIFF_SQ_VS_DM |
--------------------------------------------------------------------------------------------------------------------------
Model#id x1000 | 0.004 | 0.000 | 0.000 | 13.79x | 0.64x |
Model.new (instantiation) x10 | 0.000 | 0.000 | 0.000 | 26.88x | 31.38x |
Model.new (setting attributes) x10 | 0.001 | 0.000 | 0.000 | 2.54x | 0.54x |
Model.get specific (not cached) x10 | 0.004 | 0.006 | 0.004 | 0.77x | 0.70x |
Model.get specific (cached) x10 | 0.004 | 0.001 | 0.004 | 5.70x | 4.77x |
Model.first x10 | 0.021 | 0.005 | 0.004 | 4.35x | 0.79x |
Model.all limit(100)
@solnic
solnic / dm-commits-report-2011-03-17.markdown
Created May 23, 2011 11:14
DataMapper commits between 1.1.0 and 1.1.1
@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
# Untested, mind dump
class Document < ActiveRecord::Base
include Virtus
before_save :dump_attributes
after_initialize :load_attributes
private
@dkubb
dkubb / .rvmrc
Created August 10, 2011 22:44
Web framework Spike
rvm use @$(basename `pwd`) --create
@dkubb
dkubb / gist:1294429
Created October 18, 2011 01:57
Reflect on a PostgreSQL Database
# gem install backports veritas veritas-optimizer veritas-do-adapter do_postgres
require 'pp'
require 'rational'
require 'rubygems'
require 'backports'
require 'backports/basic_object'
require 'veritas'
require 'veritas-optimizer'

Since Obie Fernandez posted his demands as a consultant I thought I would post mine too.

  • I will be paid $10,000 per day, in $50 bills, in a titanium briefcase that you will purchase for the sole purpose of providing a container for my money. You may not re-use the briefcase for the next day's payment.
  • The $50 bills must have been printed in the last three months and handled by no more than 2 people.
  • Anybody handling the money must do so with clean white gloves that must be placed on the hand immediately before touching the briefcase. If the hand leaves the briefcase, the white gloves must be replaced with new ones before the briefcase is touched again.
  • I will arrive in your city by a private jet. Fuel and any other costs incurred by this trip will be paid by you, and is not included in the $10k/day fee.
  • Transportation from my jet to your workplace must be performed by a driver who is between the ages of 50