Skip to content

Instantly share code, notes, and snippets.

View fantgeass's full-sized avatar

Vadim Vorotilov fantgeass

  • Almaty, KZ
View GitHub Profile
# 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:
# 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:
@fantgeass
fantgeass / .rspec
Last active August 29, 2015 14:06
test-environment-code
--color
--require spec_helper
--format documentation
@fantgeass
fantgeass / example1.rb
Created December 2, 2014 15:30
how-to: exceptions in ruby
def foo
yield
rescue
puts "Only on error"
else
puts "Only on success"
ensure
puts "Always executed"
end
@fantgeass
fantgeass / use-fail.rb
Created December 2, 2014 15:33
how-to: exceptions in ruby
begin
fail "Oops";
rescue => error
raise if error.message != "Oops"
end
@fantgeass
fantgeass / throw-in-rack.rb
Created December 2, 2014 17:29
how-to: exceptions in ruby
def last_modified(time)
response[’Last-Modified’] = time
if request.env[’HTTP_IF_MODIFIED_SINCE’] > time
throw :halt, response
end
end
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