Skip to content

Instantly share code, notes, and snippets.

Vadim Vorotilov fantgeass

  • Almaty, Kazakhstan
View GitHub Profile
View get_max.exs
defmodule Solution do
def get_max([ head | tail ]), do: get_max(tail, head)
def get_max([ head | tail ], max), do: get_max(tail, (if head > max, do: head, else: max))
def get_max([], max), do: max
end
@fantgeass
fantgeass / throw-in-rack.rb
Created Dec 2, 2014
how-to: exceptions in ruby
View throw-in-rack.rb
def last_modified(time)
response[’Last-Modified’] = time
if request.env[’HTTP_IF_MODIFIED_SINCE’] > time
throw :halt, response
end
end
@fantgeass
fantgeass / use-fail.rb
Created Dec 2, 2014
how-to: exceptions in ruby
View use-fail.rb
begin
fail "Oops";
rescue => error
raise if error.message != "Oops"
end
@fantgeass
fantgeass / example1.rb
Created Dec 2, 2014
how-to: exceptions in ruby
View example1.rb
def foo
yield
rescue
puts "Only on error"
else
puts "Only on success"
ensure
puts "Always executed"
end
@fantgeass
fantgeass / .rspec
Last active Aug 29, 2015
test-environment-code
View .rspec
--color
--require spec_helper
--format documentation
View rspec_model_testing_template.rb
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
View rspec_model_testing_template.rb
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
You can’t perform that action at this time.