<commit_before>class ApplicationController < ActionController::Base
  protect_from_forgery
  before_filter :authenticate_user
  before_filter :send_css_link_header
  before_filter :increase_traffic_counter

  @@_css_link_header = nil

  TRAFFIC_DECREMENTER = 0.25

  TAG_FILTER_COOKIE = :tag_filters

  def authenticate_user
    if session[:u] &&
    (user = User.where(:session_token => session[:u].to_s).first) &&
    user.is_active?
      @user = user
      Rails.logger.info "  Logged in as user #{@user.id} (#{@user.username})"
    end

    true
  end

  # speed hax
  @@_css_link_header = nil
  def send_css_link_header
    begin
      if !@@_css_link_header
        # is there a better way to find this?
        j = JSON.parse(File.read(Dir.glob(
          "#{Rails.root}/public/assets/manifest-*.json").first))

        @@_css_link_header = "</assets/" << j["assets"]["application.css"] <<
          ">; rel=stylesheet"
      end
    rescue => e
      Rails.logger.error e.inspect
    end

    if @@_css_link_header
      response.headers["Link"] = @@_css_link_header
    end
  end

  def increase_traffic_counter
    @traffic = 1.0

    if user_is_spider? || [ "json", "rss" ].include?(params[:format])
      return true
    end

    Keystore.transaction do
      now_i = Time.now.to_i
      date_kv = Keystore.find_or_create_key_for_update("traffic:date", now_i)
      traffic_kv = Keystore.find_or_create_key_for_update("traffic:hits", 0)

      # increment traffic counter on each request
      traffic = traffic_kv.value.to_i + 100
      # every second, decrement traffic by some amount
      traffic -= (100.0 * (now_i - date_kv.value) * TRAFFIC_DECREMENTER).to_i
      # clamp
      traffic = [ 100, traffic ].max<commit_msg>don't do css link header hack in development<commit_after>class ApplicationController < ActionController::Base
  protect_from_forgery
  before_filter :authenticate_user
  before_filter :send_css_link_header
  before_filter :increase_traffic_counter

  @@_css_link_header = nil

  TRAFFIC_DECREMENTER = 0.25

  TAG_FILTER_COOKIE = :tag_filters

  def authenticate_user
    if session[:u] &&
    (user = User.where(:session_token => session[:u].to_s).first) &&
    user.is_active?
      @user = user
      Rails.logger.info "  Logged in as user #{@user.id} (#{@user.username})"
    end

    true
  end

  # speed hax
  @@_css_link_header = nil
  def send_css_link_header
    if !Rails.env.development?
      begin
        if !@@_css_link_header
          # is there a better way to find this?
          j = JSON.parse(File.read(Dir.glob(
            "#{Rails.root}/public/assets/manifest-*.json").first))

          @@_css_link_header = "</assets/" << j["assets"]["application.css"] <<
            ">; rel=stylesheet"
        end
      rescue => e
        Rails.logger.error e.inspect
      end

      if @@_css_link_header
        response.headers["Link"] = @@_css_link_header
      end
    end
  end

  def increase_traffic_counter
    @traffic = 1.0

    if user_is_spider? || [ "json", "rss" ].include?(params[:format])
      return true
    end

    Keystore.transaction do
      now_i = Time.now.to_i
      date_kv = Keystore.find_or_create_key_for_update("traffic:date", now_i)
      traffic_kv = Keystore.find_or_create_key_for_update("traffic:hits", 0)

      # increment traffic counter on each request
      traffic = traffic_kv.value.to_i + 100
      # every second, decrement traffic by some amount
      traffic -= (100.0 * (now_i - date_kv.value) * TRAFFIC_DECREMENTER).to_i
      # clamp
      traffic = [ 100, traffic ].max
{'fraction_non_alphanumeric': 0.11039686975964226, 'fraction_numerical': 0.008943543879262158, 'mean_word_length': 2.9029443838604143, 'pattern_counts': {'":': 0, '<': 15, '<?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': '3093559', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1198, 'n_words': 249}