Skip to content

Instantly share code, notes, and snippets.

simplejson==3.8.1
requests==2.6.0
robotframework==2.9.2
robotframework-selenium2library==1.7.4
robotframework-pabot==0.20

Keybase proof

I hereby claim:

  • I am vipulnsward on github.
  • I am vipulnsward (https://keybase.io/vipulnsward) on keybase.
  • I have a public key ASDZmmQCKw8hgS-vLO6etlbk41-Og9OjEN3c1u5fMv6B4Qo

To claim this, I am signing this object:

(main)> price_greater_than_200 = NSPredicate.predicateWithFormat("price > 200")
=> #<NSComparisonPredicate:0x1293bc50>
(main)> products.filteredArrayUsingPredicate(price_greater_than_200)
=> [#<Product:0x9b4f780 @name="iPad Mini" @price=329 @launched_on=2012-11-02 00:00:00 +0530>, #<Product:0x9b4fac0 @name="MacBook Pro" @price=1699 @launched_on=2012-06-11 00:00:00 +0530>, #<Product:0x9b4fe00 @name="iMac" @price=1299 @launched_on=2012-11-02 00:00:00 +0530>]
(main)> price_greater_than_equal = NSPredicate.predicateWithFormat("price >= 1299")
=> #<NSComparisonPredicate:0x9b1b740>
(main)> products.filteredArrayUsingPredicate(price_greater_than_equal)
=> [#<Product:0x9b4fac0 @name="MacBook Pro" @price=1699 @launched_on=2012-06-11 00:00:00 +0530>, #<Product:0x9b4fe00 @name="iMac" @price=1299 @launched_on=2012-11-02 00:00:00 +0530>]
(main)>> price_between = NSPredicate.predicateWithFormat("price BETWEEN {100 , 2000}")
=> #<NSComparisonPredicate:0x1293f3e0>
(main)> iPadMiniPredicate = NSPredicate.predicateWithFormat("name = 'iPad Mini'")
=> #<NSComparisonPredicate:0x9d27250>
(main)> products.filteredArrayUsingPredicate(iPadMiniPredicate)
=> [#<Product:0x9b4f780 @name="iPad Mini" @price=329 @launched_on=2012-11-02 00:00:00 +0530>]
(main)> macbookProPredicate = NSPredicate.predicateWithFormat("name = 'MacBook Pro'")
=> #<NSComparisonPredicate:0x9d24d70>
(main)> products.filteredArrayUsingPredicate(macbookProPredicate)
=> [#<Product:0x9b4fac0 @name="MacBook Pro" @price=1699 @launched_on=2012-06-11 00:00:00 +0530>]
(main)> products.valueForKeyPath("@count")
=> 4
(main)> products.valueForKeyPath("@sum.price")
=> 3526.0
(nil)? products.valueForKeyPath("@avg.price")
=> 881.5
(nil)? products.valueForKeyPath("@max.price")
=> 1699
(main)> products.valueForKeyPath("@min.launched_on")
=> 2012-06-11 00:00:00 +0530
df = NSDateFormatter.alloc.init # Date Formatter
df.dateFormat = "yyyy-MM-dd"
Product.new("iPhone 5", 199, df.dateFromString("2012-09-21")).price
products = [Product.new("iPhone 5", 199, df.dateFromString("2012-09-21")),Product.new("iPad Mini", 329, df.dateFromString("2012-11-02")),Product.new("MacBook Pro",1699, df.dateFromString("2012-06-11")),Product.new("iMac", 1299, df.dateFromString("2012-11-02"))]
class Product
def initialize(name, price, launched_on)
@name, @price, @launched_on = name, price, launched_on
end
def name
@name
end
# Object Counter for use in example on vipulnsward.com about Frozen
# Strings in Ruby
module ObjectCounter
def self.count
GC.disable
before_count = ObjectSpace.count_objects
yield
after_count = ObjectSpace.count_objects
after_count.each do |k,v|
after_count[k] = v.to_i - before_count[k].to_i
@vipulnsward
vipulnsward / make test
Created October 29, 2012 11:24
Potion Test
OS: Mac OSX Mountain Lion
make test
running API tests
............
OK (12 tests)
running GC tests
@vipulnsward
vipulnsward / CollectionProxy.rb
Created October 21, 2012 18:56
Override exists?
def exists?(conditions = :none)
return false if @association.owner.new_record?
super(conditions)
end