<commit_before>#!/usr/bin/ruby
require 'webrick'

class Servlet < WEBrick::HTTPServlet::AbstractServlet
  def do_GET(request, response)
    response.status = 200
    response['Content-Type'] = 'text/html'
    response.body = File.read(SURVEY_PATH)
  end
  def do_POST(request, response)
    path = File.expand_path('../data/web-survey.log', __FILE__)
    date = Time.now.strftime('%Y-%m-%d')
    File.open(path, 'a') { |file|
      request.query.each { |field, value|
        file.write "#{date},#{field},#{value}\n"
      }
    }

    response.status = 200
    response['Content-Type'] = 'text/html'
    response.body = "<html><body>
      Responses received; closing window...
      <script>
        setTimeout(function() {
          window.open('', '_self', ''); 
          window.close();
        }, 1000);
      </script>
    </body></html>"

    sleep 1
    `kill #{Process.pid}`
  end
end

SURVEY_PATH = ARGV[0] or raise "First arg: path to html to show"
PORT = ARGV[1] or raise "Second arg: port (example: 2998)"
server = WEBrick::HTTPServer.new :Port => PORT.to_i
server.mount "/", Servlet, './'
trap('INT') { server.stop }
trap('TERM') { server.stop }
if fork
  server.start
else
  `open http://localhost:#{PORT}/`
end
<commit_msg>Oops, didn't update data path for moved web-survey.<commit_after>#!/usr/bin/ruby
require 'webrick'

class Servlet < WEBrick::HTTPServlet::AbstractServlet
  def do_GET(request, response)
    response.status = 200
    response['Content-Type'] = 'text/html'
    response.body = File.read(SURVEY_PATH)
  end
  def do_POST(request, response)
    path = File.expand_path('../../data/web-survey.log', __FILE__)
    date = Time.now.strftime('%Y-%m-%d')
    File.open(path, 'a') { |file|
      request.query.each { |field, value|
        file.write "#{date},#{field},#{value}\n"
      }
    }

    response.status = 200
    response['Content-Type'] = 'text/html'
    response.body = "<html><body>
      Responses received; closing window...
      <script>
        setTimeout(function() {
          window.open('', '_self', ''); 
          window.close();
        }, 1000);
      </script>
    </body></html>"

    sleep 1
    `kill #{Process.pid}`
  end
end

SURVEY_PATH = ARGV[0] or raise "First arg: path to html to show"
PORT = ARGV[1] or raise "Second arg: port (example: 2998)"
server = WEBrick::HTTPServer.new :Port => PORT.to_i
server.mount "/", Servlet, './'
trap('INT') { server.stop }
trap('TERM') { server.stop }
if fork
  server.start
else
  `open http://localhost:#{PORT}/`
end

{'fraction_non_alphanumeric': 0.17399920729290527, 'fraction_numerical': 0.013476020610384463, 'mean_word_length': 2.974803149606299, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2454365', 'n_tokens_mistral': 907, 'n_tokens_neox': 871, 'n_words': 193}