Skip to content

Instantly share code, notes, and snippets.

View alg's full-sized avatar

Aleksey Gureiev alg

View GitHub Profile
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
@alg
alg / maze.rb
Created December 28, 2009 13:16
class Maze
WALL = '#'
EMPTY = ' '
attr_reader :steps
def initialize(spec)
@spec = spec.split("\n").map { |line| line.split('') }
solve
@alg
alg / db.rb
Created January 18, 2010 09:51
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"
class GlobalRESTController < ApplicationController
def index
@objects = model_class.all
respond_to do |format|
format.html
format.xml { render :xml => @objects }
end
end
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
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
@alg
alg / routes_rb
Created February 13, 2010 00:03
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
@alg
alg / application.html.haml
Created February 25, 2010 23:46
JS embedding
!!!
%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
@alg
alg / footer.html.erb
Created February 25, 2010 23:50
Inlining JS
module ActionDispatch
module Routing
class Mapper
module HttpHelpers
def any(*args, &block)
map_method([ :get, :post, :put, :delete ], *args, &block)
end
end
end
end