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
module UserPasswordHashCleaner | |
extend self | |
def call(params) | |
return {} if params.nil? | |
return params if hash_has_password_info?(params) | |
strip_password_keys_from_hash(params) | |
end | |
protected |
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
ruby user_password_hash_cleaner.rb | |
.... | |
Finished tests in 0.001046s, 3824.0918 tests/s, 3824.0918 assertions/s. |
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
numbers = [1,3,5,8,10,54,99] | |
cards = [5,3,4,6,2] | |
# get only the values where the distance is greater than 10 | |
numbers.each_cons(2).select {|a,b| b-a>10 } #=> [[10, 54], [54, 99]] | |
# determine if the hand is a straight | |
cards.sort.each_cons(5).all? do |series| | |
(series.first..series.last).to_a == series | |
end #=> true |
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
[1,3] | |
[3,5] | |
[5,8] | |
... | |
[54,99] |
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 Roll < Array | |
def small_straight? | |
sort.each_cons(4).any? {|vals| in_series?(vals) } | |
end | |
def large_straight? | |
sort.each_cons(5).all? {|vals| in_series?(vals) } | |
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
# American good grades | |
grades = [:A, :A, :B, :B, :C] | |
# Tiger momma standards | |
grades.all? {|grade| [:A, :B].include? grade } #=> false | |
# Next semester... | |
grades = [:A, :A, :A, :B, :B] | |
grades.all? {|grade| [:A, :B].include? grade } #=> true |
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
f.each_line.each_cons(2) {|line_1, line_2| line_1 == line_2 } |
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 update | |
if params[:credit_card] | |
#process order | |
response = @order.process(params) | |
if response[:status] == "success" | |
render :template => "orders/show" | |
else | |
render :json => response | |
end | |
else |
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 update | |
render if params[:credit_card] | |
process_order(params) | |
else | |
create_shipping_contact(params) | |
end | |
end | |
def process_order(params) | |
response = @order.process(params) |
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 update | |
render params[:credit_card].present? ? process_order(params) : | |
create_shipping_contact(params) | |
end | |
def process_order(params) | |
response = @order.process(params) | |
response[:status] == "success" ? { template: "orders/show" } : | |
{ json: response } | |
end |