<commit_before># # Inspired from: http://stackoverflow.com/a/677141

class Hash

  # Returns the value given a path of keys, without failing.
  # Inspired from: http://stackoverflow.com/a/10131410
  def get(*args)
    res = self
    args.each do |k|
      if res.try('include?',k)
        res = res[k]
      else
        return nil
      end
    end
    res
  end
end

class String
  def number
    scan(/\d/).join
  end

  # DOC: http://www.rubydoc.info/stdlib/erb/ERB%2FUtil.url_encode
  include ERB::Util
  def url_encoded(only_spaces: false)
    if only_spaces
      gsub " ", "%20"
    else
      url_encode(self)
    end
  end

  def replace_spaces_with(replacement)
    gsub /\s+/, replacement
  end

  # SOURCE: http://stackoverflow.com/a/5492450
  # SOURCE: http://www.monkeyandcrow.com/blog/
  #                               reading_rails_how_does_message_encryptor_work/
  @@persistent_encryptor = ActiveSupport::MessageEncryptor
                          .new(Rails.application.secrets.secret_key_base)

  # NOTE: The volatile encryptor uses an on-run-time created key and
  # salt, so that it's not possible to retrieve them. However, on system
  # restart, the encryptor and so its key and salt will be regenerated.
  # Strings encrypted with an old @@volatile_encryptor will not be able
  # to be decrypted again.
  volatile_encryption_key = ActiveSupport::KeyGenerator
                              .new(SecureRandom.uuid + SecureRandom.uuid)
                              .generate_key(SecureRandom.urlsafe_base64)
  @@volatile_encryptor = ActiveSupport::MessageEncryptor
                          .new(volatile_encryption_key)


  def encrypt
    @@persistent_encryptor.encrypt_and_sign(self)
  end
<commit_msg>minor: add parens to gsub call<commit_after># # Inspired from: http://stackoverflow.com/a/677141

class Hash

  # Returns the value given a path of keys, without failing.
  # Inspired from: http://stackoverflow.com/a/10131410
  def get(*args)
    res = self
    args.each do |k|
      if res.try('include?',k)
        res = res[k]
      else
        return nil
      end
    end
    res
  end
end

class String
  def number
    scan(/\d/).join
  end

  # DOC: http://www.rubydoc.info/stdlib/erb/ERB%2FUtil.url_encode
  include ERB::Util
  def url_encoded(only_spaces: false)
    if only_spaces
      gsub(" ", "%20")
    else
      url_encode(self)
    end
  end

  def replace_spaces_with(replacement)
    gsub(/\s+/, replacement)
  end

  # SOURCE: http://stackoverflow.com/a/5492450
  # SOURCE: http://www.monkeyandcrow.com/blog/
  #                               reading_rails_how_does_message_encryptor_work/
  @@persistent_encryptor = ActiveSupport::MessageEncryptor
                          .new(Rails.application.secrets.secret_key_base)

  # NOTE: The volatile encryptor uses an on-run-time created key and
  # salt, so that it's not possible to retrieve them. However, on system
  # restart, the encryptor and so its key and salt will be regenerated.
  # Strings encrypted with an old @@volatile_encryptor will not be able
  # to be decrypted again.
  volatile_encryption_key = ActiveSupport::KeyGenerator
                              .new(SecureRandom.uuid + SecureRandom.uuid)
                              .generate_key(SecureRandom.urlsafe_base64)
  @@volatile_encryptor = ActiveSupport::MessageEncryptor
                          .new(volatile_encryption_key)


  def encrypt
    @@persistent_encryptor.encrypt_and_sign(self)
  end

{'fraction_non_alphanumeric': 0.08824374820350675, 'fraction_numerical': 0.014946823799942513, 'mean_word_length': 2.4939759036144578, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6779226', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1082, 'n_words': 270}