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 'stemmer' | |
require 'classifier' | |
class LedeClassifier | |
attr :classifier | |
def initialize(sections, n) | |
@classifier = Classifier::Bayes.new(*sections) |
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 MischaTime < Struct.new(:hours, :minutes, :seconds); end | |
def time_diff(t1, t2) | |
if seconds(t1) > seconds(t2) | |
(one_day - t1.seconds) + seconds(t2) | |
else | |
seconds(t2) - seconds(t1) | |
end | |
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
(define-struct time (hours minutes seconds)) | |
(define (time-point hours minutes seconds) | |
(make-time hours minutes seconds)) | |
(define (time-diff t1 t2) | |
(cond | |
[(> (seconds t1) (seconds t2)) ((- one-day (seconds t1)) + (seconds t2))] | |
[else (- (seconds t2) (seconds t1))])) | |
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
# CLOSURES IN RUBY Paul Cantrell http://innig.net | |
# Email: username "cantrell", domain name "pobox.com" | |
# I recommend executing this file, then reading it alongside its output. | |
# | |
# Alteratively, you can give yourself a sort of Ruby test by deleting all the comments, | |
# then trying to guess the output of the code! | |
# A closure is a block of code which meets three criteria: | |
# |
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
# Any Model | |
def to_s | |
name | |
end | |
def to_param | |
"#{id}-#{to_s.parameterize}" | |
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
def link_to(*args, &block) | |
if block_given? | |
options = args.first || {} | |
html_options = args.second | |
concat(link_to(capture(&block), options, html_options)) | |
else | |
name = args.first | |
options = args.second || {} | |
html_options = args.third | |
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
#app/views/users/index.rb | |
<% @users.each do |user| %> | |
<%= link_to user, user %> | |
<% end %> | |
# app/models/user.rb | |
def to_s |
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
module FlashHelper | |
def flashes | |
{:partial => '/forms/flashes', :object => flash} | |
end | |
def flash_names | |
[:notice, :error, :message, :success] | |
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
#(Thanks to Thomas Ritz, http://www.galaxy-ritz.de ,for the code.) | |
namespace :doc do | |
namespace :diagram do | |
task :models do | |
sh "railroad -i -l -a -m -M | dot -Tsvg | sed 's/font-size:14.00/font-size:11.00/g' > doc/models.svg" | |
end | |
task :controllers do | |
sh "railroad -i -l -C | neato -Tsvg | sed 's/font-size:14.00/font-size:11.00/g' > doc/controllers.svg" |
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
if [child, parent, grandpa, president, food, ink].all{|e| e.valid?} | |
... #do stuff | |
end | |
>> %w{foo, bar, baz}.all?{|e| e.is_a?(String)} | |
=> true | |
>> ["foo", "bar", 1].all?{|e| e.is_a?(String)} | |
=> false |