Skip to content

Instantly share code, notes, and snippets.

View semmin's full-sized avatar
👋

Simon Bagreev semmin

👋
View GitHub Profile
@semmin
semmin / rubocop.yml
Last active February 3, 2016 19:28
styleguide
AllCops:
RunRailsCops: true
Exclude:
- 'bin/**/*'
- 'db/**/*'
- 'vendor/**/*'
- 'tmp/**/*'
- 'spec/spec_helper.rb'
- 'spec/rails_helper.rb'
@semmin
semmin / towers_of_hanoi.rb
Last active August 29, 2015 14:06
Towers of Hanoi in Ruby with tests
class Peg
attr_accessor :title, :rings
def initialize(title: , rings: 0)
@title = title
@rings = Array(1..rings)
end
end
def move(rings, from, destination, other)
@semmin
semmin / array_to_hash.rb
Created September 4, 2014 14:43
Suppose I have the following Array of tuples [ ['a',1], ['b',2], ['c','3' ] How can I convert this to a Hash? { 'a' => 1, 'b' => 2, 'c' => 3}?
a = [ ['a',1], ['b',2], ['c',3] ]
h={}
a.flatten!.each_with_index {|el, i| i % 2 == 0 ? h[el]=a[i+1] : () }
h
# => {"a"=>1, "b"=>2, "c"=>3}
@semmin
semmin / zadacha.rb
Last active August 29, 2015 14:06
Задача про непарные числа в массиве
a = [4,1,1,2,2,3,3,3,2,2,5,5,5,5]
el = a.pop
while el do # O(N)
# в массиве осталось нечетное число чисел равных el
if a.find_all {|m| m == el}.size % 2 != 0 # O(N2)
a.delete_if {|m| m == el} # O(N3) значит вместе с el их было четное число, значит это не то что мы ищем
else # если осталось четное число или 0, то изначально было нечетное, это то что мы ищем
puts "Непарный элемент: #{el}"
break
source "http://rubygems.org"
group :development do
gem 'rake', '~> 0.9'
gem 'rack', '~> 1.4.1'
gem 'jekyll', '~> 0.12'
gem 'rdiscount', '~> 1.6.8'
gem 'pygments.rb', '~> 0.3.4'
gem 'RedCloth', '~> 4.2.9'
gem 'haml', '~> 3.1.7'
@semmin
semmin / gist:2783524
Created May 24, 2012 18:54
Package levels -- request for approval
# lib/package_level/package_level.rb
module PackageLevel
module CareerSection
module Bronze
class Config
class << self
attr_accessor :max_active_job_postings,
:max_employers,
:max_job_postings_error_text,
Failures:
1) CreateQuasarJobPosting perform when both company and employer exist on Quasar should have the correct QuasarJobPosting
Failure/Error: CreateQuasarJobPosting.perform(@job_posting.id).last.attributes.should == @quasar_job_posting.attributes
expected: {"id"=>1011, "source_id"=>1055, "employer_id"=>1010, "title"=>"Application Wrangler", "description"=>"Quis omnis molestias nobis sint mesh user-centric web-readiness minus. Sapiente tempora sunt delectus voluptatem facilis Advanced local conglomeration fugiat est. Eligendi mollitia autem inventore est id explicabo. Est • officia voluptas accusantium.", "city"=>"Virginia Beach", "state"=>"VA", "zip"=>"23453", "employment_type"=>"Full Time", "posted_at"=>Mon, 07 May 2012 17:02:58 EDT -04:00, "latitude"=>36.8527778, "longitude"=>-75.9783333, "active"=>true, "requisition_number"=>"4016e97e8e3f5a0f"}
got: {"id"=>1011, "source_id"=>1055, "employer_id"=>1010, "title"=>"Application Wrangler", "description"=>"Quis omnis molestias nobi