<commit_before>module Mina
  # Helpers
  module Helpers

    # Invokes another Rake task.
    #
    # Invokes the task given in `task`. Returns nothing.
    #
    #     invoke :'git:clone'
    #     invoke :restart
    #
    def invoke(task)
      Rake.application.invoke_task task
    end

    # Evaluates an ERB block in the current scope and returns a string.
    #
    #     a = 1
    #     b = 2
    #
    #     # Assuming foo.erb is <%= a %> and <%= b %>
    #     puts erb('foo.erb')
    #
    #     #=> "1 and 2"
    #
    # Returns the output string of the ERB template.
    #
    def erb(file, b=binding)
      require 'erb'
      erb = ERB.new(File.read(file))
      erb.result b
    end

    # SSHs into the host and runs the code that has been queued.
    #
    # This is already automatically invoked before Rake exits to run all
    # commands that have been queued up.
    #
    #     queue "sudo restart"
    #     run!
    #
    # Returns nothing.
    #
    def run!
      ssh commands(:default)
    end

    # Executes a command via SSH.
    #
    # Returns nothing usually, but if `{ return: true }` is given, returns the
    # STDOUT output of the SSH session.
    #
    # options  - Hash of options.
    #            :pretty  - Prettify the output.
    #            :return  - If set to true, returns the output.
    #
    # Example
    #
    #     ssh("ls", return: true)
    #
    def ssh(cmd, options={})
      cmd = cmd.join("\n")  if cmd.is_a?(Array)

      require 'shellwords'<commit_msg>Show elapsed time that a deploy takes.<commit_after>module Mina
  # Helpers
  module Helpers

    # Invokes another Rake task.
    #
    # Invokes the task given in `task`. Returns nothing.
    #
    #     invoke :'git:clone'
    #     invoke :restart
    #
    def invoke(task)
      Rake.application.invoke_task task
    end

    # Evaluates an ERB block in the current scope and returns a string.
    #
    #     a = 1
    #     b = 2
    #
    #     # Assuming foo.erb is <%= a %> and <%= b %>
    #     puts erb('foo.erb')
    #
    #     #=> "1 and 2"
    #
    # Returns the output string of the ERB template.
    #
    def erb(file, b=binding)
      require 'erb'
      erb = ERB.new(File.read(file))
      erb.result b
    end

    # SSHs into the host and runs the code that has been queued.
    #
    # This is already automatically invoked before Rake exits to run all
    # commands that have been queued up.
    #
    #     queue "sudo restart"
    #     run!
    #
    # Returns nothing.
    #
    def run!
      time, output = measure do
        ssh commands(:default)
      end

      print_str "Elapsed time: %.2f seconds" % [time]
      output
    end

    # Measures the time (in ms) a block takes.
    # Returns a [time, output] tuple.
    def measure(&blk)
      t = Time.now
      output = yield
      [(Time.now - t).to_i, output]
    end

    # Executes a command via SSH.
    #
    # Returns nothing usually, but if `{ return: true }` is given, returns the
    # STDOUT output of the SSH session.
    #
    # options  - Hash of options.
    #            :pretty  - Prettify the output.
    #            :return  - If set to true, returns the output.
    #
    # Example
    #
    #     ssh("ls", return: true)
    #
    def ssh(cmd, options={})
      cmd = cmd.join("\n")  if cmd.is_a?(Array)

      require 'shellwords'
{'fraction_non_alphanumeric': 0.10110020814748737, 'fraction_numerical': 0.0026761819803746653, 'mean_word_length': 1.7238866396761134, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '467610', 'n_tokens_mistral': 1130, 'n_tokens_neox': 1079, 'n_words': 364}