<commit_before># coding: utf-8
#

require 'sinatra/base'
require 'haml'
require 'json'

require 'cddaiv/log'
require 'cddaiv/model'
require 'cddaiv/mailer'
require 'cddaiv/oauth'
require 'cddaiv/scheduler'
require 'cddaiv/version'

# fix Sinatra logging retardation
class String
  def join(*_); self; end
end

module CDDAIV
  class VoteError < RuntimeError; end

  class WebApp < Sinatra::Base
    @@secret = 'this is not secure'

    def self.secret=(str)
      @@secret = str
    end

    configure do
      enable :static
      enable :logging
      enable :dump_errors
      enable :raise_errors

      set :root, File.join(File.dirname(__FILE__), '..', '..')
      set :public_dir, File.join(settings.root, 'static')
      set :views, File.join(settings.root, 'templates')
      set :sessions, expire_after: 2592000
      set :session_secret, @@secret
      set :haml, ugly: true
    end

    helpers do
      def set_source
        uri = request.path
        uri += '?' + request.query_string unless request.query_string.empty?
        session[:source] = uri
      end
    end

    before do
      env['rack.logger'] = CDDAIV::Log.logger
      env['rack.errors'] = CDDAIV::Log.logger

      @user = session[:user] ? User.get(session[:user]) : nil
      @source = session[:source] || '/all'
      @oauth = OAuth.options

      unless @token = session[:token]
        @token = session[:token] = ('A'..'Z').to_a.sample(12).join
      end

      @ftype_type = :none
      @ftype = Hash.new
      case params[:ftype]
      when 'issue'
        @ftype_type = :issue
        @ftype[:type] = :issue
      when 'pr'
        @ftype_type = :pr
        @ftype[:type] = :pr
      end

      @fstate_type = :none
      @fstate = Hash.new
      case params[:fstate]
      when 'stale'
        @fstate_type = :stale
        @fstate[:stale] = true
      when 'fresh'
        @fstate_type = :fresh
        @fstate[:stale] = false
      end<commit_msg>Enable both AJAX and plain HTTP voting<commit_after># coding: utf-8
#

require 'sinatra/base'
require 'haml'
require 'json'

require 'cddaiv/log'
require 'cddaiv/model'
require 'cddaiv/mailer'
require 'cddaiv/oauth'
require 'cddaiv/scheduler'
require 'cddaiv/version'

# fix Sinatra logging retardation
class String
  def join(*_); self; end
end

module CDDAIV
  class VoteError < RuntimeError; end

  class WebApp < Sinatra::Base
    @@secret = 'this is not secure'

    def self.secret=(str)
      @@secret = str
    end

    configure do
      enable :static
      enable :logging
      enable :dump_errors
      enable :raise_errors

      set :root, File.join(File.dirname(__FILE__), '..', '..')
      set :public_dir, File.join(settings.root, 'static')
      set :views, File.join(settings.root, 'templates')
      set :sessions, expire_after: 2592000
      set :session_secret, @@secret
      set :haml, ugly: true
    end

    helpers do
      def set_source
        uri = request.path
        uri += '?' + request.query_string unless request.query_string.empty?
        session[:source] = uri
      end
    end

    before do
      env['rack.logger'] = CDDAIV::Log.logger
      env['rack.errors'] = CDDAIV::Log.logger

      @user = session[:user] ? User.get(session[:user]) : nil
      @source = session[:source] || '/all'
      session[:nojs] = params[:nojs] unless params[:nojs].nil?
      @nojs = session[:nojs] == 'yes'

      @oauth = OAuth.options

      unless @token = session[:token]
        @token = session[:token] = ('A'..'Z').to_a.sample(12).join
      end

      @ftype_type = :none
      @ftype = Hash.new
      case params[:ftype]
      when 'issue'
        @ftype_type = :issue
        @ftype[:type] = :issue
      when 'pr'
        @ftype_type = :pr
        @ftype[:type] = :pr
      end

      @fstate_type = :none
      @fstate = Hash.new
      case params[:fstate]
      when 'stale'
        @fstate_type = :stale
        @fstate[:stale] = true
      when 'fresh'
        @fstate_type = :fresh
        @fstate[:stale] = false
      end
{'fraction_non_alphanumeric': 0.1295880149812734, 'fraction_numerical': 0.004993757802746567, 'mean_word_length': 2.421007685738685, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4782859', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1315, 'n_words': 328}