<commit_before>require 'socket'
require 'daemon'

class GenericUnixServer
  VERSION="0.1"
  MAX_CMD_LEN=1024
  class Error < StandardError; end
  class CmdToLong < StandardError; end
  include Daemon

  def self.def_cmd(cmd, &blk); define_method("process_" + cmd.to_s, &blk) end
  
  def_cmd(:CMD)  { |*args| "OK " + @known_commands.keys.sort.join(" ") }
  def_cmd(:HELP) { |*args| "OK Usage: CMD param1 param2 ..." }
  def_cmd(:ECHO) { |*args| "OK " + args.join(" ") }

  def start!
    File.delete(@socket_file) if File.exists?(@socket_file)
    @server = UNIXServer.open(@socket_file)
    File.chmod(0666, @socket_file)
      
    while c = @server.accept
      begin
      while l = c.gets(MAX_CMD_LEN)
        raise CmdToLong if l.size >= MAX_CMD_LEN
        c.puts process(l.strip).to_s
      end<commit_msg>Do not use daemon library<commit_after>require 'socket'

class GenericUnixServer
  VERSION="0.1"
  MAX_CMD_LEN=1024
  class Error < StandardError; end
  class CmdToLong < StandardError; end

  def self.def_cmd(cmd, &blk); define_method("process_" + cmd.to_s, &blk) end
  
  def_cmd(:CMD)  { |*args| "OK " + @known_commands.keys.sort.join(" ") }
  def_cmd(:HELP) { |*args| "OK Usage: CMD param1 param2 ..." }
  def_cmd(:ECHO) { |*args| "OK " + args.join(" ") }

  def start!
    File.delete(@socket_file) if File.exists?(@socket_file)
    @server = UNIXServer.open(@socket_file)
    File.chmod(0666, @socket_file)
      
    while c = @server.accept
      begin
      while l = c.gets(MAX_CMD_LEN)
        raise CmdToLong if l.size >= MAX_CMD_LEN
        c.puts process(l.strip).to_s
      end
{'fraction_non_alphanumeric': 0.14196762141967623, 'fraction_numerical': 0.014943960149439602, 'mean_word_length': 3.3083109919571045, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6170279', 'n_tokens_mistral': 621, 'n_tokens_neox': 594, 'n_words': 127}