Skip to content

Instantly share code, notes, and snippets.

Aleksey Gureiev alg

Block or report user

Report or block alg

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View polynomial.rb
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
View maze.rb
class Maze
WALL = '#'
EMPTY = ' '
attr_reader :steps
def initialize(spec)
@spec = spec.split("\n").map { |line| line.split('') }
solve
View db.rb
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"
View global_rest_controller.rb
class GlobalRESTController < ApplicationController
def index
@objects = model_class.all
respond_to do |format|
format.html
format.xml { render :xml => @objects }
end
end
View fair_distribution.rb
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
View static_pages_controller_test.rb
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
View routes_rb
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
View application.html.haml
!!!
%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
View footer.html.erb
View routes.rb
module ActionDispatch
module Routing
class Mapper
module HttpHelpers
def any(*args, &block)
map_method([ :get, :post, :put, :delete ], *args, &block)
end
end
end
end
You can’t perform that action at this time.