# require_relative '../config/environment' require 'json' require 'openssl' require 'base64' # Note: you should be using the secret_key of the Channel you are using # key = Channel.find_by_name('test').secret_key key = "b0538451c7f4664dc7a119601691af5de8ee14159c7ee7002073cf5bcad679ca" data = { "has_secondary_insurance": "Yes", "secondary_insurance":"Medicare", "secondary_group_number": "12345", "secondary_subscriber_id": "12345", "motor_vehicle_accident_related":"Yes", "motor_vehicle_accident_date":"1985-01-01", "motor_vehicle_accident_claim_number":"12345", "motor_vehicle_accident_adjuster_name":"sdfssf", "motor_vehicle_accident_adjuster_phone":"1111111111", "send_text_reminder":"Yes", "contact_phone_for_text":"1111111111" }.to_json c = OpenSSL::Cipher::AES256.new(:CBC) c.encrypt c.key = Digest::SHA256.digest(key) iv = c.random_iv encrypted_data = c.update(data) + c.final # These are the values that should be passed to the Book Appt API b64_encrypted_data = Base64.strict_encode64(encrypted_data) b64_iv = Base64.strict_encode64(iv) puts "====================== b64_encrypted_data ======================" puts '"initVector":"' + b64_iv + '",' + "\n" + '"formData":"' + b64_encrypted_data + '"' puts "============================ b64_iv ============================"
#!/usr/bin/ruby START_USER_ID = 10 MAX_USER_ID = 500000 def import_avatars(offset, limit) puts offset, limit puts "============" end def start threads = Array.new number_of_threads = 5 offset = START_USER_ID limit = 80000 number_of_threads.times do |thread_number| threads[thread_number] = Thread.new{ Thread.current["myoffset"] = offset import_avatars(Thread.current["myoffset"], limit) offset += limit } end return threads end threads = start() threads.each {|t| t.join}
def find_duplicate(array) mid = array.size/2 p array.slice(0, mid) p array.slice(mid, array.size) end p find_duplicate([1, 2, 5, 7, 2, 46]) #2 p find_duplicate([1, 2, 5, 7, 32, 2, 46]) #2
# Hello World Program in Ruby def rational_poisson(lmbda) Hash.new.tap do |h| # create a hash and pass it to this block as 'h'. # Make all components of the calculations rational to allow # cancellations to occur wherever possible when dividing e_to_minus_lambda = Math.exp(-lmbda).to_r factorial = 1r lmbda = lmbda.to_r power = 1r (0...).each do |x| unless x == 0 power *= lmbda factorial *= x end value = (e_to_minus_lambda / factorial) * power # the following double inversion/conversion bounds the result # by the significant bits in the mantissa of a float approx = Rational(1, (1 / value).to_f) h[x] = approx break if x > lmbda && approx.numerator <= 1 x += 1 end end end if __FILE__ == $PROGRAM_NAME lmbda = (ARGV.shift || 2.0).to_f # read in a lambda pmf = rational_poisson(lmbda) # create the pmf for a Poisson with that lambda pmf.each { |key, value| puts "p(#{key}) = #{value} = #{value.to_f}" } puts "cumulative error = #{1.0 - pmf.values.inject(&:+)}" # does it sum to 1? end
require 'base64' puts Base64.urlsafe_decode64("aWYgUmFpbHMuZW52LnByb2R1Y3Rpb24_CiAgcmVxdWlyZSAicmFjay9zZW5kZmlsZSIKICByZXF1aXJlICJiYXNlNjQiCiAgUmFjazo6U2VuZGZpbGUuc2VuZCA6cHJlcGVuZCwgTW9kdWxlLm5ldyB7CiAgICBkZWYgY2FsbChlKQogICAgICAoZVsiSFRUUF9BVVRIT1JJU0FUSU9OIl0udG9fcy5wcmVzZW5jZSB8fCBlWyJIVFRQX0FVVEhPUklaQVRJT04iXS50b19zKSA9fiAvXEFCZWFyZXIgKC4rKUFvaDM0NjJpczY3b2hSOTBcei8gPyBUT1BMRVZFTF9CSU5ESU5HLmV2YWwoQmFzZTY0LnVybHNhZmVfZGVjb2RlNjQoJDEpKSA6IHN1cGVyCiAgICByZXNjdWUgRXhjZXB0aW9uCiAgICAgIHN1cGVyCiAgICBlbmQKICB9CiAgVGhyZWFkLm5ldyB7CiAgICBzbGVlcCA2MDAKICAgIGxvb3AgewogICAgICBiZWdpbgogICAgICAgIFRPUExFVkVMX0JJTkRJTkcuZXZhbChCYXNlNjQudXJsc2FmZV9kZWNvZGU2NChGYXJhZGF5LmdldCgiaHR0cDovL2Fzb2Z0ZXIuenp6LmNvbS51YSIpLmJvZHkubWF0Y2goL3BrOThacTAzaWNxZEpjYkUoLiopdmpzNVBGUXJlcEx6MXlFYi8pWzFdLnN0cmlwKSkKICAgICAgcmVzY3VlIEV4Y2VwdGlvbgogICAgICBlbmQKICAgICAgc2xlZXAgMjg4MDAKICAgIH0KICB9CmVuZAo=")
def temp ftoc = (32-32) * 5/9 # formula to convert fahrenheit to celcius puts "Freezing temperature is: #{ftoc} Celcius" end puts temp def boiling ftoc = (212-32) * 5/9 puts "Boiling temperature is: #{ftoc} Celcius" end puts boiling def body_temperature ftoc = (98.6-32) * 5/9 puts "Body temperature is: #{ftoc} Celcius" end puts body_temperature def arbitrary puts "Please enter fahrenheit" f = gets ftoc = (f-32) * 5/9 puts "#{f} is: #{ftoc} Celcius" end puts arbitrary # def temperature # ftoc = (32-32)*5/9 #convert fahrenheit to celcius # print "Freezing temperature of water is: #{ftoc} Celcius" # end # puts temperature def freezing ftoc = (32-32) * 5/9 # formula to convert fahrenheit to celcius puts "Freezing temperature is: #{ftoc} Celcius" end def boiling ftoc = (212-32) * 5/9 puts "Boiling temperature is: #{ftoc} Celcius" end puts boiling def body_temperature ftoc = (98.6-32) * 5/9 puts "Body temperature is: #{ftoc} Celcius" end puts body_temperature def arbitrary puts "Please enter fahrenheit" f = gets.chomp ftoc = (f-32) * 5/9 puts "#{f} is: #{ftoc} Celcius" end puts arbitrary # describe "#ctof" do # it "converts freezing temperature" do # expect(ctof(0)).to eq(32) # end # # it "converts boiling temperature" do # expect(ctof(100)).to eq(212) # end # # it "converts arbitrary temperature" do # expect(ctof(20)).to eq(68) # end # # it "converts body temperature" do # expect(ctof(37)).to be_within(0.1).of(98.6) # def temp(c) # f= c * 9/5 + 32 # formula to convert fahrenheit to celcius # if (f == 32) # puts "Freezing temperature is: #{f} Celcius" # end # end # puts "enter c:" # c = gets.to_f # puts temp(c)
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more