Skip to content

Instantly share code, notes, and snippets.

View finbarr's full-sized avatar

Finbarr Taylor finbarr

View GitHub Profile
class Array
def bucketize(n)
return [] if (buckets = n.to_i) <= 0
j = length / buckets.to_f
result = each_with_index.chunk { |_, i| (i / j).floor }.map { |_, v| v.map(&:first) }
result << [] until result.length == buckets
result
end
end
@fearphage
fearphage / README.md
Last active October 18, 2022 20:19
$.whenAll jQuery extension

$.whenAll is an extension to jQuery's $.when. The main difference is $.when stops when it receives the first rejected promise. This extension treats all successes and failures as progress events. After all the promises have completed, the global promise is resolved if there were no errors. Otherwise the global promise is rejected.

Sameple #1

$.whenAll($.get('http://github.com'), $.get('good luck with this one'))
  .then(
    // success callback
    function(request) {}
    // failure callback - called once at the end
 ,function() {}