<commit_before>require 'rack-plastic'
require 'etc'

module Rack

  class Serverinfo < Plastic

    def change_nokogiri_doc(doc)
      badge = doc.create_element 'div', style: style

      server_info_text.each do |info|
        badge.add_child(doc.create_element('p', info, style: 'margin: 0'))
      end

      append_to_body(doc, badge)

      doc
    end

    private

    def server_info_text
      @server_info_text ||= [
        "Hostname: #{hostname}",
        "User: #{user}",
        "Rails-Env: #{rails_env}",
      ]
    end

    def style
      @style ||= [
        'position: absolute;',
        'bottom: 10px;',
        'right: 10px;',
        'border: 4px solid red;',
        'padding: 5px;',
        'border-radius: 5px;',
        'background-color: black;',
        'opacity: 0.5;',
        'color: white;',
        'font-size: 10px;',
      ].join
    end

    def user
     @user ||= Etc.getlogin
    end

    def rails_env
      @rails_env ||= ENV['RAILS_ENV']
    end

    def hostname
      @hostname ||= Socket.gethostname
    end

    def append_to_body(doc, node)
      doc.at_css('body').add_next_sibling(node)
    end

  end

end<commit_msg>Get the username via process uid.<commit_after>require 'rack-plastic'
require 'etc'

module Rack

  class Serverinfo < Plastic

    def change_nokogiri_doc(doc)
      badge = doc.create_element 'div', style: style

      server_info_text.each do |info|
        badge.add_child(doc.create_element('p', info, style: 'margin: 0'))
      end

      append_to_body(doc, badge)

      doc
    end

    private

    def server_info_text
      @server_info_text ||= [
        "Hostname: #{hostname}",
        "User: #{user.name}",
        "Rails-Env: #{rails_env}",
      ]
    end

    def style
      @style ||= [
        'position: absolute;',
        'bottom: 10px;',
        'right: 10px;',
        'border: 4px solid red;',
        'padding: 5px;',
        'border-radius: 5px;',
        'background-color: black;',
        'opacity: 0.5;',
        'color: white;',
        'font-size: 10px;',
      ].join
    end

    def user
     @user ||= Etc.getpwuid(Process.uid)
    end

    def rails_env
      @rails_env ||= ENV['RAILS_ENV']
    end

    def hostname
      @hostname ||= Socket.gethostname
    end

    def append_to_body(doc, node)
      doc.at_css('body').add_next_sibling(node)
    end

  end

end
{'fraction_non_alphanumeric': 0.13246425567703954, 'fraction_numerical': 0.010092514718250631, 'mean_word_length': 2.085603112840467, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '6163523', 'n_tokens_mistral': 870, 'n_tokens_neox': 819, 'n_words': 182}