This file contains hidden or 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
https://github.com/makandra/cucumber_factory | |
Create records from Cucumber features without writing step definitions. http://makandra.com/ | |
https://github.com/jayzes/cucumber-api-steps | |
Cucumber steps to easily test REST-based XML and JSON APIs | |
https://github.com/collectiveidea/json_spec | |
Easily handle JSON in RSpec and Cucumber http://rubygems.org/gems/json_spec | |
https://github.com/napcs/cucumber_watir |
This file contains hidden or 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 MyArray < Array | |
def flatten | |
reduce [] do |memo, item| | |
memo.concat item.is_a?(Array) ? MyArray.new(item).flatten : [item] | |
end | |
end | |
end | |
test_arr = MyArray.new [ 1, [ 1 ], [ 1, [ 1 ] ] ] |
This file contains hidden or 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
result_sets = { | |
top_rated: Post.all.order(rating: :desc).first(50), | |
top_rated_in_followed_topic: Post.all.where(topic_id: @user.followed_topics.pluck(:id)).order(rating: :desc).first(50) | |
} |
This file contains hidden or 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
set_a = result_sets[:top_rated] | |
set_b = result_sets[:top_rated_from_following_topics] | |
# Using zip | |
# -------------------- | |
# Assuming both arrays are the same length, zipping them will create a result | |
# that includes all elements from both a1 and a2. | |
# It pulls from them in alternating order (a, b, a, b, etc) | |
result = set_a.zip set_b |
This file contains hidden or 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
Y-AXIS: percent chance that next element will come from "set b" | |
X-AXIS: percent completed through iteration | |
Example using zip: | |
100% | | |
50% | x x x x | |
0% | | |
|___________________ | |
0% 33% 66% 100% |
This file contains hidden or 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
Y-AXIS: percent chance that next element will come from "set b" | |
X-AXIS: percent completed through iteration | |
Desired result | |
100% | x | |
75% | x | |
50% | x | |
25% | x | |
0% | x |
This file contains hidden or 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 Array | |
# helper method to help with testing | |
def mean | |
map(&:to_f).reduce(&:+) / length.to_f | |
end | |
# target is another array | |
# priority is a number between 0 and 1 |
This file contains hidden or 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
result = set_a.priority_merge(1, set_2).uniq | |
This file contains hidden or 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
a1 = 50.times.map { 1 } | |
a2 = 50.times.map { 2 } | |
puts "when priority is 1.0" | |
result = 50.times.map do | |
result = a1.priority_merge(1.0, a2) | |
result.select { |item| item == 2 }.count.to_f / a1.length.to_f | |
end | |
puts "results contain on average #{result.mean}% elements from the merged array" |
This file contains hidden or 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 = 5.times { |i| puts i } | |
# Coffee = (1).times (i) -> console.log i | |
Number.prototype.times = (cb) -> | |
i = -1; | |
while (++i < this) then cb(i) | |
+this | |
# Ruby = 1.upto(5) { |i| puts i } | |
# Coffee = (1).upto 5, (i) -> console.log i | |
Number.prototype.upto = (t, cb) -> |