Skip to content

Instantly share code, notes, and snippets.

View perezd's full-sized avatar
🦾
More Perfect Protobuf

Derek Perez perezd

🦾
More Perfect Protobuf
View GitHub Profile
require 'rubygems'
require 'activerecord'
ActiveRecord::Base.establish_connection(
:adapter => 'mysql',
:host => 'localhost',
:username => 'root',
:database => 'craigslist'
)
Christmas:
when: "December 25th"
"My Important Date":
when: "March 12th, 2009"
"Pay Day":
when: "first and last friday"
"Weekly Meetings":
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
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.
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
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
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));
}
require 'java'
require 'scala-library.jar'
require 'myjar.jar'
include_class 'Book'
book = Book.new('my book')
book.getBook
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>}
@perezd
perezd / gist:98892
Created April 21, 2009 02:17
Hackish Prototype of a JavaScript-esque Class/Object
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"