Skip to content

Instantly share code, notes, and snippets.

(rdb:1) e
#<NoMethodError: undefined method `product_id' for #<Shirt:0x3eafc60>>
(rdb:1) Shirt.properties
#<PropertySet:{#<Property:Shirt:id>,#<Property:Shirt:type>,#<Property:Shirt:code>,#<Property:Shirt:name>,#<Property:Shirt:description>,#<Property:Shirt:unit_price>,#<Property:Shirt:available_on>,#<Property:Shirt:is_discontinued>,#<Property:Shirt:slug>,#<Property:Shirt:vote_mean>,#<Property:Shirt:available>,#<Property:Shirt:designer_id>,#<Property:Shirt:created_by>,#<Property:Shirt:user_id>}>
(rdb:1) pp e.backtrace
["/opt/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.3/lib/dm-validations/numeric_validator.rb:17:in `send'",
"/opt/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.3/lib/dm-validations/numeric_validator.rb:17:in `call'",
"/opt/local/lib/ruby/gems/1.8/gems/dm-validations-0.9.3/lib/dm-validations/contextual_validators.rb:48:in `execute'",
@dieseltravis
dieseltravis / gist:2247
Created July 24, 2008 18:57
Getting a unique random item in a collection
private string GetRandomRelatedViewID(string viewIDList)
{
BaseGenericList<BrandEnsemble.Framework.RelatedItems.Components.RelatedItem> riList = BrandEnsemble.Framework.RelatedItems.RelatedItems.GetAllRelatedItems();
riList.Filter(new string[] { "Caption" }, string.Empty, FilterOperand.NotEquals);
BrandEnsemble.Framework.RelatedItems.Components.RelatedItem rri = riList.RandomItem();
while (viewIDList.IndexOf(rri.ViewID) >= 0)
{
rri = riList.RandomItem();
}
return rri.ViewID;
class Whatever < ActiveRecord::Base
class << self
def find_with_awesome(*args)
opts = args.extract_options!
if opts.has_key?(:awesome)
awesome = opts.delete(:awesome)
# process something here....
end
find_without_awesome(*(args << opts))
public T RandomItem()
{
int randomRI = 0;
Random random = new Random();
lock (random)
{
randomRI = random.Next(0, this.Count - 1);
}
return this[randomRI];
}
@anthonylewis
anthonylewis / gist:2257
Created July 24, 2008 19:22
A Ruby Generator for prime numbers
require 'generator'
g = Generator.new do |g|
n = 2
p = []
while true
if p.all? { |f| n % f != 0 }
g.yield n
p << n
for i in 1..25
puts g.next
end
require 'rubygems'
require 'mq'
EM.run do
def log(*args)
p args
end
amq = MQ.new
require 'pathname'
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
if HAS_SQLITE3 || HAS_MYSQL || HAS_POSTGRES
describe "STI Resources" do
before do
class Product
include DataMapper::Resource
property :id, Integer, :serial => true
class Array
def to_json(options = {}, &block) #:nodoc:
"[#{map { |value| ActiveSupport::JSON.encode(value, options, &block) } * ', '}]"
end
end
module ActiveSupport
module JSON
> git status
# On branch cpp
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
#
# modified: external_libs/llvm/Makefile
# modified: external_libs/llvm/Makefile.common
# modified: external_libs/llvm/bindings/Makefile
# modified: external_libs/llvm/bindings/ocaml/Makefile.ocaml
# modified: external_libs/llvm/examples/Makefile