This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'activerecord' | |
ActiveRecord::Base.establish_connection( | |
:adapter => 'mysql', | |
:host => 'localhost', | |
:username => 'root', | |
:database => 'craigslist' | |
) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Christmas: | |
when: "December 25th" | |
"My Important Date": | |
when: "March 12th, 2009" | |
"Pay Day": | |
when: "first and last friday" | |
"Weekly Meetings": |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'smart_month' | |
SmartMonth::Rulesets.load_file("/path/to/rulsets.yml") | |
Month.december.christmas #=> Date object containing December 25th of the current year. | |
Month.december(2010).christmas #=> Date object containing December 25th, 2010. | |
Month.december.each do |day| | |
if day.is_christmas? | |
puts "yay!" | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'smart_month' | |
SmartMonth::Rulesets.add_rule('Christmas','December 25th') | |
Month.december.christmas #=> Date object containing December 25th of this year. | |
SmartMonth::Rulesets.add_rule('Weekly Meetings','every friday') | |
Month.march.weekly_meetings #=> array of corresponding Date objects. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'smart_month' | |
# an example of the simple to use syntax | |
Time.now.month.first_and_third_friday #=> array of corresponding date objects | |
# access month as an array | |
Month[1] #=> Jan Object | |
Month[12] #=> Dec Object | |
# access month as hash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'smart_month' | |
Month.december.each do |day| | |
day.to_day #=> returns day of week | |
day.to_i #=> returns the date as an integer | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ScalaFib extends Application { | |
def fibo(n:Int) : Int = { | |
if (!(n>2)) n else fibo(n-1)+fibo(n-2); | |
} | |
for (i <- 0 until 30) { | |
println(fibo(i)); | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'java' | |
require 'scala-library.jar' | |
require 'myjar.jar' | |
include_class 'Book' | |
book = Book.new('my book') | |
book.getBook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person < Comfy::Base | |
property :name | |
property :address | |
property :friends | |
property :moods | |
end | |
{:name=>#<Comfy::Property::Base:0x58dc84 @casting_type="Person::Name", @master_class=Person, @property_type="Person::Name", @name=:name>, :address=>#<Comfy::Property::Base:0x58d5f4 @casting_type="Person::Address", @master_class=Person, @property_type="Person::Address", @name=:address>, :friends=>#<Comfy::Property::Base:0x58c640 @casting_type="Person::Friend", @master_class=Person, @property_type=:array, @name=:friends>, :moods=>#<Comfy::Property::Base:0x58bc04 @casting_type="Person::Mood", @master_class=Person, @property_type=:array, @name=:moods>} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hash | |
def method_missing(meth,*args) | |
self[meth].is_a?(Proc) ? self[meth].call(*args) : self[meth] | |
end | |
end | |
MyClass = { | |
:some_method => lambda { |arg| | |
puts "#{arg} was recieved" |
OlderNewer