Яuбy / Говнокод #29087 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
# Setup the admin service from Microsoft
  def setup_microsoft_admin_service
    # define the empty microsoft picture url
    @no_profile_picture = 'https://secure.aadcdn.microsoftonline-p.com/ests/2.1.5670.18/content/images/work_account.png'
    # Application id and secret from microsoft
    client_id = ENV['AZURE_CLIENT_ID']
    # client_secret = 'z8uGboGliWfBqa8/s8K4KbDH96l1F0+PuFwX+AOGJTQ='
    client_secret = ENV['AZURE_CLIENT_SECRET']
    # Should also be listed in microsoft app
    tenant        = Current.organization['microsoft_azure_domain_hint']
    # Create credentials using Active Directory Azure Library
    client_cred   = ADAL::ClientCredential.new(client_id, client_secret)
    context       = ADAL::AuthenticationContext.new(ADAL::Authority::WORLD_WIDE_AUTHORITY, tenant)
    # Return the acquired tokens from the graph site
    context.acquire_token_for_client('https://graph.microsoft.com', client_cred)
  end

Perfección

Shannarra_ Shannarra_, (Updated )

Комментарии (3, +3)

Яuбy / Говнокод #29081 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
if (analysis.document? && analysis.update(name: params[:analysis][:name], description: params[:analysis][:description], anonymous: params[:analysis][:anonymous], dependency: analysis.dependency)) ||
       (analysis.cloud_file_link.present? && analysis.update(name: params[:analysis][:name], description: params[:analysis][:description], anonymous: params[:analysis][:anonymous], dependency: analysis.dependency)) ||
       (analysis.videolink.present? && analysis.update(name: params[:analysis][:name], description: params[:analysis][:description], videolink: params[:analysis][:videolink], anonymous: params[:analysis][:anonymous], dependency: analysis.dependency)) ||
       analysis.update(name: params[:analysis][:name], description: params[:analysis][:description], hyperlink: params[:analysis][:hyperlink], anonymous: params[:analysis][:anonymous], dependency: analysis.dependency)

pls kill me

Shannarra_ Shannarra_, (Updated )

Комментарии (9, +9)

Яuбy / Говнокод #29078 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
# https://www.source-code.biz/snippets/vbasic/9.htm
    def calc_probability_of_inverse_normal_cumulative_distribution(probability)
      raise Math::DomainError unless probability.instance_of? BigDecimal

      a1 = -39.6968302866538
      a2 = 220.946098424521
      a3 = -275.928510446969
      a4 = 138.357751867269
      a5 = -30.6647980661472
      a6 = 2.50662827745924
      b1 = -54.4760987982241
      b2 = 161.585836858041
      b3 = -155.698979859887
      b4 = 66.8013118877197
      b5 = -13.2806815528857
      c1 = -7.78489400243029E-03
      c2 = -0.322396458041136
      c3 = -2.40075827716184
      c4 = -2.54973253934373
      c5 = 4.37466414146497
      c6 = 2.93816398269878
      d1 = 7.78469570904146E-03
      d2 = 0.32246712907004
      d3 = 2.445134137143
      d4 = 3.75440866190742
      probability_low = 0.02425
      probability_high = 1 - probability_low

      raise Math::DomainError if probability <= 0 || probability >= 1

      # glhf to the person who's gonna refactor this
      # rubocop:disable Layout/LineLength
      if probability < probability_low
        q = (-2 * Math.log(probability))**0.5
        (((((((((((c1 * q) + c2) * q) + c3) * q) + c4) * q) + c5) * q) + c6) / ((((((((d1 * q) + d2) * q) + d3) * q) + d4) * q) + 1)).to_f
      elsif probability <= probability_high
        q = probability - 0.5
        r = q * q
        (((((((((((a1 * r) + a2) * r) + a3) * r) + a4) * r) + a5) * r) + a6) * q / ((((((((((b1 * r) + b2) * r) + b3) * r) + b4) * r) + b5) * r) + 1)).to_f
      else
        q = (-2 * Math.log(1 - probability))**0.5
        (-((((((((((c1 * q) + c2) * q) + c3) * q) + c4) * q) + c5) * q) + c6) / ((((((((d1 * q) + d2) * q) + d3) * q) + d4) * q) + 1)).to_f
      end
      # rubocop:enable Layout/LineLength
    end

красота.

автор: аспирант-физик.

Shannarra_ Shannarra_, (Updated )

Комментарии (4, +4)

Яuбy / Говнокод #28860 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
class MoveAchieveTemplateIdentifierToRatePeriodPrograms < ActiveRecord::Migration
  def up
    RatePeriod.find_in_batches(batch_size: 1_000) do |batch|
      sleep(50)
      batch.each do |rate_period|
        achieve_template_identifier = rate_period.achieve_template_identifier
        rate_period.rate_period_programs.update_all(achieve_template_identifier: achieve_template_identifier)
      end
    end
  end

  def down
    raise ActiveRecord::IrreversibleMigration
  end
end

fml

Shannarra_ Shannarra_, (Updated )

Комментарии (3, +3)