<commit_before>def wait_for_http_listener(uri_string, retries = 10)
  require 'net/http'
  require 'openssl'
  require 'uri'
  uri = URI(uri_string)
  begin
    puts "Trying GET #{uri_string}"
    Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
                    verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
      request = Net::HTTP::Get.new uri
      http.request request
    end
    puts "Succesfully made GET to #{uri_string}"
  rescue StandardError => e
    if retries <= 0
      raise e
    else
      puts "GET #{uri_string} failed: #{e} retrying in 1 seconds (#{retries} retries remaining)"
      retries -= 1
      sleep 1
      retry
    end
  end
end

def start_compliance_stub(port)
  # Start stub compliance server in a thread
  require 'webrick'
  require 'webrick/https'
  require 'openssl'
  require 'thread'
  Thread.new do
    server = WEBrick::HTTPServer.new(:Port => port,
                                     :SSLEnable => true,
                                     :SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
                                     :SSLCertName => [%w[CN localhost]])
    server.mount_proc '/' do |req, res|
      if req.path =~ %r{/compliance/profiles/([^/]+)/?}
        res.body = '{ "response": "ok" }'
      elsif req.path =~ %r{/compliance/profiles/([^/]+)/([^/]+)/?}
        res.body = '{ "response": "ok" }'
      else
        res.body = '{}'
        res.status = 404
      end
    end
    server.start<commit_msg>[pedant] Smaller timeout in wait_for_http_listener, style updates<commit_after>def wait_for_http_listener(uri_string, retries = 10)
  require 'net/http'
  require 'openssl'
  require 'uri'
  uri = URI(uri_string)
  begin
    puts "Trying GET #{uri_string}"
    Net::HTTP.start(uri.host, uri.port, :use_ssl => true,
                    verify_mode: OpenSSL::SSL::VERIFY_NONE) do |http|
      request = Net::HTTP::Get.new uri
      http.request request
    end
    puts "Succesfully made GET to #{uri_string}"
  rescue StandardError => e
    if retries <= 0
      raise e
    else
      puts "GET #{uri_string} failed: #{e} retrying in 0.1 seconds (#{retries} retries remaining)"
      retries -= 1
      sleep 0.1
      retry
    end
  end
end

def start_compliance_stub(port)
  # Start stub compliance server in a thread
  require 'webrick'
  require 'webrick/https'
  require 'openssl'
  require 'thread'
  Thread.new do
    server = WEBrick::HTTPServer.new(:Port => port,
                                     :SSLEnable => true,
                                     :SSLVerifyClient => OpenSSL::SSL::VERIFY_NONE,
                                     :SSLCertName => [%w[CN localhost]])
    server.mount_proc '/' do |req, res|
      case req.path
      when %r{/compliance/profiles/([^/]+)/?}
        res.body = '{ "response": "ok" }'
      when %r{/compliance/profiles/([^/]+)/([^/]+)/?}
        res.body = '{ "response": "ok" }'
      else
        res.body = '{}'
        res.status = 404
      end
    end
    server.start
{'fraction_non_alphanumeric': 0.13271090363454485, 'fraction_numerical': 0.006668889629876626, 'mean_word_length': 2.1315240083507305, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2760153', 'n_tokens_mistral': 1001, 'n_tokens_neox': 963, 'n_words': 241}