Skip to content

Instantly share code, notes, and snippets.

View gist:106549
class Exits
include Garb::Resource
metrics :exits, :exit_rate
dimensions :request_uri
end
View gist:106552
Exits.results(profile, :limit => 10,
:offset => 20,
:start_date => (Date.today - 30),
:end_date => Date.today)
# With Filtering and Sorting
Exits.results(profile) do
filter :request_uri.contains => 'fun', :exits.gte => 1000
sort :exit_rate
View gist:106554
report = Garb::Report.new(profile)
report.metrics :exits, :exit_rate
report.dimensions :request_uri
# With Filtering and Sort
report.filter :request_uri.contains => 'fun', :exits.gte => 1000
report.sort :exit_rate.desc
# Getting Results
View gist:114839
class Search
include DataMapper::Resource
property :id, Serial
end
class Result
include DataMapper::Resource
property :id, Serial
belongs_to :search
end
View gist:114857
#!/usr/bin/env ruby
#
# A one file test to show ...
require 'rubygems'
require 'dm-core'
# setup the logger
DataMapper::Logger.new(STDOUT, :debug)
View gist:114964
class GameMode
include DataMapper::Resource
property :id, Serial
property :title, String
property :description, Text
property :max_players, Integer
has n :games, :through => Resource
has n, :types, :through => Resource
View gist:124989
SELECT "items"."id", "items"."item_code", "items"."item_number", "items"."description", "items"."size", "items"."retail", "items"."vintage"
FROM "items"
INNER JOIN "sale_items" ON "items"."id" = "sale_items"."item_id"
INNER JOIN "sales" ON "sale_items"."sale_id" = "sales"."id" AND "sale_items"."sale_sale_time" = "sales"."sale_time"
WHERE "sale_items"."sale_id" IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 58)
GROUP BY "items"."id", "items"."item_code", "items"."item_number", "items"."description", "items"."size", "items"."retail", "items"."vintage"
ORDER BY "items"."id"
View gist:125200
require 'rubygems'
gem 'dm-core', '0.10.0'
require 'dm-core'
DataMapper.setup(:default, 'postgres://tpitale@localhost/test_through')
# DataObjects::Postgres.logger = DataObjects::Logger.new(STDOUT, :debug)
class Retailer
include DataMapper::Resource
View gist:127474
INSERT INTO "sales" ("sale_time", "retailer_id", "user_id") VALUES ('2009-05-14 12:44:46.474-04', 1, 1364) RETURNING "id"
Wed, 10 Jun 2009 20:22:09 GMT ~ debug ~ (0.006935) SELECT "id", "retail", "points", "sale_id", "item_id" FROM "sale_items" WHERE "sale_id" IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 17
View gist:128133
> ratings = (1..21).to_a
=> [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21]
> ratings.map { ratings.slice!(0,2) }
=> [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14]]
> ratings
=> [15, 16, 17, 18, 19, 20, 21]
# why are those left over?
You can’t perform that action at this time.