Skip to content

Instantly share code, notes, and snippets.

View hkilis's full-sized avatar

Hazem ElKilisly hkilis

View GitHub Profile
require 'net/http'
require 'thread'
require 'thwait'
class LoaderIoWorker
BASE_URL = 'https://api.loader.io/v2'
APP_ID = 'xxx'
AUTH_KEY = 'yyy'
AUTH_HEADER = {'loaderio-auth' => AUTH_KEY}
MAX_RETRIES = 10
attr_accessor :domain, :tests
start_date = DateTime.new(2019, 5, 22, 8, 59, 0).utc #change date to start of error
os = Order.unscoped.where("created_at > ?", start_date).includes(:order_items)
os.map do |o|
o.order_items.map do |oi|
if oi.options_ar.present?
begin
JSON.parse(oi.options_ar)
rescue
oi.update_attributes(options_ar: eval(oi.options_ar))
JSON.parse(oi.options_ar)
include ExceptionForMatrix
def and_matrices(mx1, mx2)
Matrix.Raise ErrDimensionMismatch, "Matrix dimension mismatch" unless (mx1.row_count == mx2.row_count && mx1.column_count == mx2.column_count)
arr = Array.new(mx1.row_count){Array.new(mx1.column_count)}
mx1.each_with_index{ |elem, ix, iy| arr[ix][iy] = (elem && mx2.element(ix,iy)) }
Matrix.rows(arr)
end
BRAND_RATING_FACTOR = {:high => 1.1, :low => 0.9}
PRICING_REFRENCE = {15 => 0.75, 25 => 0.775, 50 => 0.8, 75 => 0.825, 100 => 0.85, 200 => 0.875, 400 => 0.9, 600 => 0.925}
price_reference = 99
product_database_shipping_cost = 50
brand_rating = 'high'
def get_pricing_ceil(price)
PRICING_REFRENCE.find {|key, _| price < key}.try(:last) || 0.95
end