<commit_before>#!/usr/bin/ruby

# standard libraries
require 'webrick'
include WEBrick

require 'rubygems' # or otherwise obtain redcloth, etc.

WEBrick::Daemon.start # forks process

s = HTTPServer.new( :Port => 8180 )
# listens on localhost only
# If needed extertnally, pass in IP address as second parameter

def input(req) req.query['input'] end

s.mount_proc('/redcloth') do |req, resp|
	require 'redcloth'
	resp.body = RedCloth.new(input(req)).to_html
end

s.mount_proc('/maruku') do |req, resp|
	require 'maruku'
	resp.body = Maruku.new(input(req)).to_html
end

s.mount_proc('/rubypants') do |req, resp|
	require 'rubypants'
	resp.body = RubyPants.new(input(req)).to_html
end

s.start<commit_msg>dispatch daemon<commit_after>#!/usr/bin/ruby

# standard libraries
require 'webrick'
include WEBrick

require 'rubygems' # or otherwise obtain redcloth, etc.

PID = '/var/run/databinder-dispatch.pid'

def pid(new_id = false)
  if new_id
    File.open(PID, 'w') do |f| f << new_id end
  else 
    File.exist?(PID) && IO.read(PID).to_i
  end
end

def start()
  puts "Warning, existing pid record: " + pid.to_s if pid
  pid(-1)         # test that we can write before forking
  WEBrick::Daemon.start # forks process
  pid(Process.pid)
  run
end

def stop()
  if pid
    begin
      Process.kill("INT", pid)
    rescue Errno::ESRCH
      puts "server not running at pid: #{pid}; removing record"
    end
    File.unlink PID
  else
    puts "no server id on record"
  end
end

def run()
  s = HTTPServer.new( :Port => 8180 )
  # listens on localhost only
  # If needed extertnally, pass in IP address as second parameter

  def input(req) req.query['input'] end

  s.mount_proc('/redcloth') do |req, resp|
  	require 'redcloth'
  	resp.body = RedCloth.new(input(req)).to_html
  end

  s.mount_proc('/maruku') do |req, resp|
  	require 'maruku'
  	resp.body = Maruku.new(input(req)).to_html
  end

  s.mount_proc('/rubypants') do |req, resp|
  	require 'rubypants'
  	resp.body = RubyPants.new(input(req)).to_html
  end
  
  trap("INT") { s.shutdown }
  s.start
end

begin
  case !ARGV.empty? && ARGV[0]
  when 'run'
    run
  when 'start'
    start
  when 'stop'
    stop
  when 'restart'
    stop
    start
  else
    puts "Invalid command. Please specify run, start, stop or restart."
    exit
  end
rescue Errno::EACCES
  puts "Error, unable to write: " + PID
  exit(1)
rescue Errno::EPERM
  puts "Error, not permitted to kill pid: " + pid.to_s
  exit(1)
end
{'fraction_non_alphanumeric': 0.12398373983739837, 'fraction_numerical': 0.004878048780487805, 'mean_word_length': 3.4422382671480145, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '1121589', 'n_tokens_mistral': 940, 'n_tokens_neox': 913, 'n_words': 260}