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 quick(a) | |
return a if a.min == a.max | |
m = a[rand(a.size)] | |
quick( a.select { |i| i <= m } ) + quick( a.select { |i| i > m } ) | |
end | |
describe "Quicksort" do | |
it "should sort an empty array" do | |
quick([]).should == [] | |
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
#pragma once | |
#include "../console/console.h" | |
#include <stdlib.h> | |
#include <stdio.h> | |
namespace MDS | |
{ | |
#pragma pack(push, 1) |
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
3.times do | |
puts "Hello, world!" | |
end | |
puts "Tomorrow will be " + 24.hours.from_now |
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
default_run_options[:pty] = true | |
set :application, "embplay" | |
set :user, "deployer" | |
set :deploy_to, "/home/deployer/#{application}" | |
set :use_sudo, false | |
set :scm, "git" |
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 UserSession < Authlogic::Session::Base | |
acts_as_translatable_model | |
login_blank_message "не должен быть пустым" | |
login_not_found_message "не найден" | |
password_blank_message "не должен быть пустым" | |
password_invalid_message "неверный" | |
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
a = [3, 4, 5] | |
b = %w{a b c} # b = ['a', 'b', 'c'] - быстрая инициализация строковых массивов | |
a.each do |digit| | |
puts digit.to_s # конвертируем в строку (хотя тут это необязательно) | |
end | |
# поиграй с этим в irb - интерактивная консоль для ruby | |
a + b | |
a - b |
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 Rate < ActiveRecord::Base | |
belongs_to :user | |
belongs_to :book | |
validates_presence_of :user, :book, :value | |
validates_numericality_of :value, | |
:only_integer => true | |
validates_inclusion_of :value, | |
:in => 1..10, | |
:message => "should be from 1 to 10" |
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
Note that the object option is applied to all of the roles you specify in the argument list. As such, | |
allow :devil, :son, :of => God | |
is equivalent to | |
allow :devil, :of => God | |
allow :son, :of => God |
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
set nocompatible | |
set backspace=indent,eol,start | |
set history=50 " keep 50 lines of command line history | |
set ruler " show the cursor position all the time | |
set showcmd " display incomplete commands | |
set incsearch " do incremental searching | |
set mouse=a | |
syntax on | |
set hlsearch | |
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 ListNode | |
attr_accessor :prev, :next, :value | |
def initialize(prev, next, value) | |
@prev = prev | |
@next = next | |
@value = value | |
end | |
end | |
OlderNewer