<commit_before># Copyright (C) 2009 <NAME> <<EMAIL>> | MIT License

require 'rubygems'
require 'fileutils'
require 'stemp'

def read
  file = ARGV.shift
  (file && File.read(file) || STDIN.read).sub(/^#!.+?\n/, '')
end

def split(content)
  split_point = 0
  brace_level = 0
  (0..content.size).each do |i|
    if content[i, 1] == '{'
      if brace_level > 0 || content[split_point, i - split_point] =~ /\w+\s+[\w:\(\),\s]+$/
        brace_level += 1
      end
    elsif brace_level > 0 && content[i, 1] == '}'
      brace_level -= 1
      split_point = i + 1 if brace_level == 0
    end
  end
  return {
    :head => content[0, split_point],
    :body => content[split_point, content.size - split_point]
  }
end

def build_and_run(dir)
  (system('qmake -project CONFIG-=app_bundle') and
   system('qmake') and
   system('make > /dev/null') and
   system("./#{dir.sub(/.*\//, '')}")) or puts File.read('main.cpp')
end

def write_source(content)
  File.open("main.cpp", 'w') do |f|
    f.write <<END
#include <QtCore>
#{content[:head]}
int main(int argc, char *argv[])
{
Q_UNUSED(argc);
Q_UNUSED(argv);
#{content[:body]}
return 0;
}
END
  end
end

def run
  dir = STemp.mkdtemp("/tmp/fooq-XXX")
  FileUtils.cd(dir)
  write_source(split(read))
  build_and_run(dir)
  FileUtils.rm_r(dir)
end<commit_msg>Got a little too excited when cleaning the code up<commit_after># Copyright (C) 2009 <NAME> <<EMAIL>> | MIT License

require 'rubygems'
require 'fileutils'
require 'stemp'

def read
  file = ARGV.shift
  (file && File.read(file) || STDIN.read).sub(/^#!.+?\n/, '')
end

def split(content)
  split_point = 0
  brace_level = 0
  (0..content.size).each do |i|
    if content[i, 1] == '{'
      if brace_level > 0 || content[split_point, i - split_point] =~ /\w+\s+[\w:\(\),\s]+$/
        brace_level += 1
      end
    elsif brace_level > 0 && content[i, 1] == '}'
      brace_level -= 1
      split_point = i + 1 if brace_level == 0
    end
  end
  return {
    :head => content[0, split_point],
    :body => content[split_point, content.size - split_point]
  }
end

def build_and_run(dir)
  (system('qmake -project CONFIG-=app_bundle') and
   system('qmake') and
   system('make > /dev/null') and
   system("./#{dir.sub(/.*\//, '')}")) or puts File.read('main.cpp')
end

def write_source(content)
  File.open("main.cpp", 'w') do |f|
    f.write <<END
#include <QtCore>
#{content[:head]}
int main(int argc, char *argv[])
{
Q_UNUSED(argc);
Q_UNUSED(argv);
#{content[:body]}
return 0;
}
END
  end
end

def run
  dir = STemp.mkdtemp("/tmp/fooq-XXX")
  content = split(read)
  FileUtils.cd(dir)
  write_source(content)
  build_and_run(dir)
  FileUtils.rm_r(dir)
end
{'fraction_non_alphanumeric': 0.184655885671305, 'fraction_numerical': 0.012786761940579166, 'mean_word_length': 3.353518821603928, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 21, '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': '1814333', 'n_tokens_mistral': 1059, 'n_tokens_neox': 1029, 'n_words': 244}