Skip to content

Instantly share code, notes, and snippets.

@davidworkman9
Created February 26, 2014 00:08
Show Gist options
  • Save davidworkman9/9220704 to your computer and use it in GitHub Desktop.
Save davidworkman9/9220704 to your computer and use it in GitHub Desktop.
_.each(large_array, function (el) {
setTimeout(function () {
// do calculation
}, 0);
});
@Lepozepo
Copy link

average_sales: (options) ->
    self = this
    @unblock()
    #options: day_of_week, start_hour, end_hour
    start_day = moment().tz("America/Los_Angeles").subtract("days",77).startOf('day')
    yesterday = moment().tz("America/Los_Angeles").subtract("days",1).endOf("day")

    total_sales = 0
    Sales.find({created_at_unix:{$gte:start_day.unix(),$lte:yesterday.unix()}}).forEach (sale) ->
        Meteor.setTimeout ->
                self.unblock()
                validate = []
                if options and options.day_of_week?
                    validate.push moment(sale.created_at).tz("America/Los_Angeles").day() is options.day_of_week
                if options and options.start_hour?
                    validate.push moment(sale.created_at).tz("America/Los_Angeles").hour() >= options.start_hour
                if options and options.end_hour?
                    validate.push moment(sale.created_at).tz("America/Los_Angeles").hour() < options.end_hour

                if _.every validate
                    if sale.net_total_money? and sale.net_total_money.amount?
                        total_sales += sale.net_total_money.amount
            ,0

    (total_sales/100)/11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment