Skip to content

Instantly share code, notes, and snippets.

View dkubb's full-sized avatar
🏠
Working from home

Dan Kubb dkubb

🏠
Working from home
  • Betterment
  • Mission, BC, Canada
  • X @dkubb
View GitHub Profile
include 'dm-is-list'
class Node
include DataMapper::Resource
property :id, Serial
# other properties...
has n, :parts
end
header = nil
FasterCSV.foreach(FILE) do |row|
row.map! { |v| v.strip!; v == 'NULL' || v.blank? ? nil : v }
unless header
header = row.freeze
next
end
# As an exercise, come up with a ruby-way to specify
# a set of search conditions for this SQL:
# simple or
# WHERE name = 'Dan' OR name = 'Paul'
# nested or, plus duplicating field names
# WHERE name = 'Paul' AND ( age < 18 OR age > 21 )
# not ( and don't say != )
# limit/offset using Enumerable#slice
collection[0, 20] # LIMIT 0, 20
collection[0..20] # LIMIT 0, 20
# ordering using Enumerable#sort_by (will not require ParseTree)
collection.sort_by { |o| o.name } # ORDER BY name
collection.sort_by { |o| -o.name } # ORDER BY name DESC
This repository has moved to http://github.com/dkubb/dm-ambition
require 'pp'
require 'rubygems'
gem 'dm-core', '0.10.0' # http://github.com/datamapper/dm-core (next branch)
require 'dm-core'
gem 'dm-ambition', '0.10.0' # http://github.com/dkubb/dm-ambition (master branch)
require 'dm-ambition'
DataMapper::Logger.new($stdout, :debug)
@dkubb
dkubb / gist:62293
Created February 11, 2009 21:58
Update DataMapper sake tasks
NOTE: run all the commands prefixed with "$" from the command-line.
0) Make sure sake is installed:
$ sudo gem install sake
1) Make sure you've applied this patch to sake:
http://err.lighthouseapp.com/attachments/50325/sake_rake_0.8.2.patch
# Here is a list of all the dm-core runtime deps.
$ gem dep dm-core --remote
Gem dm-core-0.9.10
data_objects (~> 0.9.11, runtime)
extlib (~> 0.9.10, runtime)
addressable (~> 2.0.1, runtime)
[dankubb@laptop.autopilot] extlib (next) % rake spec --trace
(in /Users/dankubb/Programming/ruby/open-source/dm/extlib)
rake aborted!
unknown marshal code: 1
kernel/compiler/compile.rb:211:in `single_load {}'
kernel/compiler/compile.rb:142:in `compile_feature'
kernel/compiler/compile.rb:210:in `single_load'
kernel/compiler/compile.rb:131:in `unified_load {}'
kernel/bootstrap/array.rb:49:in `each'
kernel/compiler/compile.rb:95:in `unified_load'
rake spec results:
MySQL
102 examples, 1 failure, 1 pending
Postgres
114 examples, 10 failures, 1 pending
SQLite3
SQlite3 -- database locked