Skip to content

Instantly share code, notes, and snippets.

@ilyakrasnov
ilyakrasnov / obstruction.rb
Created April 16, 2018 05:21
Some notes on is_obstructed? method
def is_obstructed?(x1, y1, x2, y2)
is_obstructed_vertically?(x1, y1, x2, y2) ||
is_obstructed_horizontally?(x1, y1, x2, y2) ||
is_obstructed_diagonally?(x1, y1, x2, y2)
end
def is_obstructed_vertically?(x1, y1, x2, y2)
end
@ilyakrasnov
ilyakrasnov / strings.rb
Created January 31, 2018 19:20
Different String methods
## Downcase, Upcase, Capitalize
name = "Peter"
name.upcase # => "PETER"
name.downcase # => "peter"
name = "pEtEr"
name.capitalize # => "Peter"
## Characters
name = "Peter"
class Email
attr_accessor :subject, :date, :from
def initialize(subject, date, from)
@subject = subject
@date = date
@from = from
end
@ilyakrasnov
ilyakrasnov / person.rb
Last active January 19, 2018 11:19
Simple class
class Person
attr_accessor :name, :id, :address
def initialize(name, id, address)
@name = name
@id = id
@address = address
end
def where_do_you_live
FactoryBot.define do
factory :user do
sequence :email do |n|
"sampleEmails#{n}@gmail.com"
end
password "secretPassword"
password_confirmation "secretPassword"
end
@ilyakrasnov
ilyakrasnov / game.rb
Created November 19, 2017 07:13 — forked from kenmazaika/game.rb
Populate the Board of a Chess Game
class Game < ActiveRecord::Base
# all the associations, etc.
after_create :populate_board!
def populate_board!
# this should create all 32 pieces with their initial X/Y coordinates.
end
end
class Collatz
def initialize(n)
@current_number = n
@sequence = []
end
def compute_next_collatz
@sequence << @current_number