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
# -*- coding: utf-8 -*- | |
# | |
# Purpose: | |
# Extend the date parsing capabilities of Ruby to work with dates with international month names. | |
# | |
# Usage: | |
# | |
# Date.parse_international(date_string) | |
# DateTime.parse_international(date_string) | |
# date_string.to_international_date |
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 SalesReportWorker < ApplicationController | |
include Sidekiq::Worker | |
sidekiq_options backtrace: true, retry: false | |
self.view_paths = "app/views" # Where to look for view templates | |
def perform(request_ident, params) | |
@_response = ActionDispatch::Response.new # Needed to avoid "ActionController::RackDelegation#content_type | |
# delegated to @_response.content_type, but @_response is nil" error | |
... |
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 ActiveRecord::Base | |
def self.import!(record_list) | |
raise ArgumentError "record_list not an Array of Hashes" unless record_list.is_a?(Array) && record_list.all? {|rec| rec.is_a? Hash } | |
return record_list if record_list.empty? | |
(1..record_list.count).step(1000).each do |start| | |
key_list, value_list = convert_record_list(record_list[start-1..start+999]) | |
sql = "INSERT INTO #{self.table_name} (#{key_list.join(", ")}) VALUES #{value_list.map {|rec| "(#{rec.join(", ")})" }.join(" ,")}" | |
self.connection.insert_sql(sql) |