<commit_before># mischacks – Miscellaneous methods that may or may not be useful
# Copyright © 2010 <NAME>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

require 'mischacks/password'
require 'mischacks/random'

module MiscHacks
  VERSION = '0.0.5'

  class ChildError < RuntimeError
    attr_reader :status

    def initialize status
      @status = Integer status
      super "Child failed with status #{status}"
    end
  end

  def self.sh cmd, *args
    env = if args.last.is_a? Hash then args.pop else {} end

    fork_and_check do
      do_and_exit! do
        env.each_pair do |k, v| ENV[k.to_s] = v.to_s end
        exec *(%W{sh -e -c #{cmd} sh} + args.map {|a| a.to_s })
      end
    end

    nil
  end

  def self.fork_and_check
    fork do
      yield
    end.tap do |pid|
      _, status = Process.wait2 pid<commit_msg>MiscHacks: Read MiscHacks::VERSION from the VERSION file<commit_after># mischacks – Miscellaneous methods that may or may not be useful
# Copyright © 2010 <NAME>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

require 'mischacks/password'
require 'mischacks/random'

module MiscHacks
  VERSION = File.read(File.dirname(__FILE__)+'/../VERSION').chomp

  class ChildError < RuntimeError
    attr_reader :status

    def initialize status
      @status = Integer status
      super "Child failed with status #{status}"
    end
  end

  def self.sh cmd, *args
    env = if args.last.is_a? Hash then args.pop else {} end

    fork_and_check do
      do_and_exit! do
        env.each_pair do |k, v| ENV[k.to_s] = v.to_s end
        exec *(%W{sh -e -c #{cmd} sh} + args.map {|a| a.to_s })
      end
    end

    nil
  end

  def self.fork_and_check
    fork do
      yield
    end.tap do |pid|
      _, status = Process.wait2 pid
{'fraction_non_alphanumeric': 0.07062237987745888, 'fraction_numerical': 0.00419219606578523, 'mean_word_length': 3.32033426183844, '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': '6670704', 'n_tokens_mistral': 964, 'n_tokens_neox': 895, 'n_words': 407}