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 Polynomial | |
def initialize(coefs) | |
if coefs.nil? || !coefs.kind_of?(Array) || coefs.size < 2 | |
raise ArgumentError, "Need at least 2 coefficients." | |
end | |
@coefs = coefs | |
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
class Maze | |
WALL = '#' | |
EMPTY = ' ' | |
attr_reader :steps | |
def initialize(spec) | |
@spec = spec.split("\n").map { |line| line.split('') } | |
solve |
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
namespace :db do | |
desc 'Seed database from db/seed.sql file instead of the traditional db/seed.rb' | |
namespace :seed do | |
config = Rails::Configuration.new.database_configuration[RAILS_ENV] | |
seed_sql = File.expand_path(File.dirname(__FILE__) + '/../../db/seed.sql') | |
if !File.exists?(seed_sql) | |
puts "Missing RAILS_ROOT/db/seed.sql" |
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 GlobalRESTController < ApplicationController | |
def index | |
@objects = model_class.all | |
respond_to do |format| | |
format.html | |
format.xml { render :xml => @objects } | |
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
require 'utils' | |
require 'swap' | |
# A very simple algorithm based on incremental balancing of job queues. | |
# Initially, the first queue has all the jobs that are gradually distributed | |
# across available queues. The algorithm doesn't take much memory since it | |
# does not involve the recursive traversing of the options tree and | |
# doesn't store lots of intermediate data. | |
class FairDistribution | |
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 'test_helper' | |
class StaticPagesControllerTest < ActionController::TestCase | |
%w( faq about privacy terms_and_conditions ).each do |page| | |
should_route :get, "/#{page}", :controller => :static_pages, :action => page.to_sym | |
context "Accessing #{page} page" do | |
setup { get page } | |
should_respond_with :success |
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
ActionController::Routing::Routes.draw do |map| | |
map.with_options :controller => "static_pages" do |pages| | |
%w( faq about privacy terms_and_conditions ).each do |page| | |
pages.send(page, page, :action => page) | |
end | |
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
!!! | |
%html{ "xmlns" => "http://www.w3.org/1999/xhtml", "xml:lang" => "en", "lang" => "en" } | |
%head | |
%meta{ "http-equiv" => "content-type", "content" => "text/html;charset=UTF-8" } | |
-# snip | |
= stylesheet_link_tag @additional_styles if @additional_styles | |
= javascript_include_tag @additional_scripts if @additional_scripts |
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 ActionDispatch | |
module Routing | |
class Mapper | |
module HttpHelpers | |
def any(*args, &block) | |
map_method([ :get, :post, :put, :delete ], *args, &block) | |
end | |
end | |
end | |
end |
OlderNewer