code
stringlengths
1
1.73M
language
stringclasses
1 value
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/dbconsole'
Ruby
#!/usr/bin/env ruby $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib")) require 'rubygems' require 'spec' exit ::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(ARGV, STDERR, STDOUT))
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/plugin'
Ruby
#!/usr/bin/env ruby $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../rspec/lib' # For svn $LOAD_PATH.unshift File.dirname(__FILE__) + '/../vendor/plugins/rspec/lib' # For rspec installed as plugin require 'rubygems' require 'drb/drb' require 'rbconfig' require 'spec' require 'optparse' # This is based on Florian We...
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/spawner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/spawner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/inspector'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/reaper'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/reaper'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/inspector'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/request'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/request'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/generate'
Ruby
# This file is copied to ~/spec when you run 'ruby script/generate rspec' # from the project root directory. ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'spec' require 'spec/rails' Spec::Runner.configure do |config| # If you're not using ActiveRecord ...
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper SYSTEM_MODE_CONF_KEY = 'system.mode' def user_header menu_items = '' user = User.find(session[:user_id]) if (user!=nil) and (session[:admin]) # admin menu menu_items << "<b>Admi...
Ruby
module ProblemsHelper end
Ruby
module UserAdminHelper end
Ruby
module GradersHelper end
Ruby
module SitesHelper end
Ruby
module LoginHelper end
Ruby
module ConfigurationsHelper end
Ruby
module UsersHelper end
Ruby
module AnnouncementsHelper end
Ruby
module TasksHelper end
Ruby
module MessagesHelper end
Ruby
module TestHelper end
Ruby
module SiteHelper end
Ruby
module MainHelper end
Ruby
require 'yaml' # # This class also contains various login of the system. # class Configuration < ActiveRecord::Base SYSTEM_MODE_CONF_KEY = 'system.mode' # set @@cache = true to only reload once. @@cache = false @@configurations = nil @@task_grading_info = nil def self.get(key) if @@cache if @...
Ruby
class Site < ActiveRecord::Base belongs_to :country has_many :users def clear_start_time_if_not_started if !self.started self.start_time = nil end end def time_left contest_time = Configuration['contest.time_limit'] if tmatch = /(\d+):(\d+)/.match(contest_time) h = tmatch[1].to_...
Ruby
class Right < ActiveRecord::Base has_and_belongs_to_many :roles end
Ruby
require 'digest/sha1' class User < ActiveRecord::Base has_and_belongs_to_many :roles has_many :test_requests, :order => "submitted_at DESC" has_many :messages, :class_name => "Message", :foreign_key => "sender_id", :order => 'created_at DESC' has_many :replied_messages, ...
Ruby
class Announcement < ActiveRecord::Base def self.find_published Announcement.find(:all, :conditions => "(published = 1) AND (frontpage = 0)", :order => "created_at DESC") end def self.find_for_frontpage Announcement.find(:all, :conditions...
Ruby
class GraderProcess < ActiveRecord::Base def self.find_by_host_and_pid(host,pid) return GraderProcess.find(:first, :conditions => { :host => host, :pid => pid }) end def self.re...
Ruby
class Task < ActiveRecord::Base belongs_to :submission STATUS_GRADING = 0 STATUS_INQUEUE = 1 STATUS_COMPLETE = 2 def status_inqueue self.status = Task::STATUS_INQUEUE end def status_inqueue! status_inqueue self.save end def status_grading self.status = Task::STATUS_GRADING end ...
Ruby
class Role < ActiveRecord::Base has_and_belongs_to_many :users has_and_belongs_to_many :rights end
Ruby
class Submission < ActiveRecord::Base belongs_to :language belongs_to :problem belongs_to :user before_validation :assign_problem before_validation :assign_language validates_presence_of :source validates_length_of :source, :maximum => 100_000, :allow_blank => true, :message => 'too long' validates_l...
Ruby
class Message < ActiveRecord::Base belongs_to :sender, :class_name => "User" belongs_to :receiver, :class_name => "User" belongs_to :replying_message, :class_name => "Message" # commented manually do it # #has_many :replied_messages, { # :class_name => "Message", # :foreign_key => "replying_messag...
Ruby
class Description < ActiveRecord::Base end
Ruby
# # A TestRequest is a composition of submission with user's testdata. # # Note about TestRequest#problem: Usually, A TestRequest has to be # associated with a problem, so that execution environment can be # determined. However, to be more flexible, we have to ensure that # it works as well with problem=nil. In...
Ruby
class Problem < ActiveRecord::Base belongs_to :description def self.find_available_problems find(:all, :conditions => {:available => true}, :order => "date_added DESC") end end
Ruby
class Country < ActiveRecord::Base has_many :sites end
Ruby
class Language < ActiveRecord::Base end
Ruby
class MessagesController < ApplicationController before_filter :authenticate verify :method => :post, :only => ['create'], :redirect_to => { :action => 'list' } before_filter :admin_authorization, :only => ['console','show','reply'] def list @user = User.find(session[:user_id]) @messages = ...
Ruby
class ProblemsController < ApplicationController before_filter :authenticate, :authorization in_place_edit_for :problem, :name in_place_edit_for :problem, :full_name in_place_edit_for :problem, :full_score def index list render :action => 'list' end # GETs should be safe (see http://www.w3.org...
Ruby
class GradersController < ApplicationController before_filter :admin_authorization verify :method => :post, :only => ['clear_all'], :redirect_to => {:action => 'index'} def index redirect_to :action => 'list' end def list @grader_processes = GraderProcess.find(:all, ...
Ruby
class MainController < ApplicationController SYSTEM_MODE_CONF_KEY = 'system.mode' before_filter :authenticate, :except => [:index, :login] before_filter :check_viewability, :except => [:index, :login] # # COMMENT OUT: filter in each action instead # # before_filter :verify_time_limit, :only => [:submit] v...
Ruby
class SitesController < ApplicationController before_filter :admin_authorization # GET /sites # GET /sites.xml def index @sites = Site.find(:all, :order => 'country_id') respond_to do |format| format.html # index.html.erb format.xml { render :xml => @sites } end end # GET /sites...
Ruby
class LoginController < ApplicationController def index # show login screen reset_session redirect_to :controller => 'main', :action => 'login' end def login if user = User.authenticate(params[:login], params[:password]) session[:user_id] = user.id redirect_to :controller => 'main', ...
Ruby
class ConfigurationsController < ApplicationController before_filter :authenticate before_filter { |controller| controller.authorization_by_roles(['admin'])} in_place_edit_for :configuration, :key in_place_edit_for :configuration, :type in_place_edit_for :configuration, :value def index @configuratio...
Ruby
class TasksController < ApplicationController before_filter :authenticate, :check_viewability def index redirect_to :action => 'list' end def list @problems = Problem.find_available_problems @user = User.find(session[:user_id]) end def view base_filename = File.basename("#{params[:file]}...
Ruby
require 'tmail' require 'net/smtp' class UsersController < ApplicationController before_filter :authenticate, :except => [:new, :register, :confirm] verify :method => :post, :only => [:chg_passwd], :redirect_to => { :action => :index } in_place_edit_for :user, :alias_for_editing in_place_edit_for :...
Ruby
class AnnouncementsController < ApplicationController before_filter :admin_authorization in_place_edit_for :announcement, :published # GET /announcements # GET /announcements.xml def index @announcements = Announcement.find(:all, :order => "created_at DESC") ...
Ruby
# Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base # Pick a unique cookie name to distinguish our session data from others' session :session_key => '_grader_ses...
Ruby
class UserAdminController < ApplicationController before_filter :admin_authorization def index list render :action => 'list' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :method => :post, :only => [ :destroy, :create, :update ], :redirect_to => { ...
Ruby
class SiteController < ApplicationController before_filter :site_admin_authorization def index if @site.started render :action => 'started', :layout => 'empty' else render :action => 'prompt', :layout => 'empty' end end def start @site.started = true @site.start_time = Time.ne...
Ruby
class TestController < ApplicationController SYSTEM_MODE_CONF_KEY = 'system.mode' before_filter :authenticate, :check_viewability # # COMMENT OUT: filter in each action instead # # before_filter :verify_time_limit, :only => [:submit] verify :method => :post, :only => [:submit], :redirect_to => { :a...
Ruby
ActionController::Routing::Routes.draw do |map| map.resources :announcements map.resources :sites # The priority is based upon order of creation: first created -> highest priority. # Sample of regular route: # map.connect 'products/:id', :controller => 'catalog', :action => 'view' # Keep in mind you can...
Ruby
# Don't change this file! # Configure your app in config/environment.rb and config/environments/*.rb RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) module Rails class << self def boot! unless booted? preinitialize pick_boot.run end end def booted? ...
Ruby
class SizeFilterHandler < Mongrel::HttpHandler def initialize(options = {}) @max_size = options[:max_size] || -1 @redirect_url = options[:redirect_url] @request_notify = true end def request_begins(params) @request_too_large = false # Only operate on POST requests return unless pa...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # The production environment is meant for finished, "live" apps. # Code is not reloaded between requests config.cache_classes = true # Use a different logger for distributed setups # config.logger = SyslogLogger.new # Full error repor...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the webserver when you make code changes. config.ca...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between...
Ruby
# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require(File.join(File.dirname(__FILE__), 'config', 'boot')) require 'rake' require 'rake/testtask' require 'rake/rdoctask' require 'tasks/rails'
Ruby
#!/usr/bin/ruby def talk(str) if TALKATIVE puts str end end def execute(command, error_message="") if not system(command) puts "ERROR: #{error_message}" exit(127) end end def save_source(submission,dir,fname) f = File.open("#{dir}/#{fname}","w") f.write(submission.source) f.close end def c...
Ruby
#!/usr/bin/ruby problem_home = ENV['PROBLEM_HOME'] require "#{problem_home}/script/test_dsl.rb" if ARGV.length < 2 puts "Usage: check <language> <test-number> [<output-file>]" exit(0) end language = ARGV[0] test_num = ARGV[1].to_i if ARGV.length >= 3 output_file_name = ARGV[2] else output_file_name = "output...
Ruby
#!/usr/bin/ruby problem_home = ENV['PROBLEM_HOME'] require "#{problem_home}/script/test_dsl.rb" if ARGV.length < 2 puts "Usage: check <language> <test-number> [<output-file>]" exit(0) end language = ARGV[0] test_num = ARGV[1].to_i if ARGV.length >= 3 output_file_name = ARGV[2] else output_file_name = "output...
Ruby
#!/usr/bin/ruby problem_home = ENV['PROBLEM_HOME'] require "#{problem_home}/script/test_dsl.rb" if ARGV.length < 2 puts "Usage: check <language> <test-number> [<output-file>]" exit(0) end language = ARGV[0] test_num = ARGV[1].to_i if ARGV.length >= 3 output_file_name = ARGV[2] else output_file_name = "output...
Ruby
#!/usr/bin/ruby problem_home = ENV['PROBLEM_HOME'] require "#{problem_home}/script/test_dsl.rb" if ARGV.length < 2 puts "Usage: check <language> <test-number> [<output-file>]" exit(0) end language = ARGV[0] test_num = ARGV[1].to_i if ARGV.length >= 3 output_file_name = ARGV[2] else output_file_name = "output...
Ruby
#!/usr/bin/ruby problem_home = ENV['PROBLEM_HOME'] require "#{problem_home}/script/test_dsl.rb" if ARGV.length < 2 puts "Usage: check <language> <test-number> [<output-file>]" exit(0) end language = ARGV[0] test_num = ARGV[1].to_i if ARGV.length >= 3 output_file_name = ARGV[2] else output_file_name = "output...
Ruby
#!/usr/bin/ruby problem_home = ENV['PROBLEM_HOME'] require "#{problem_home}/script/test_dsl.rb" if ARGV.length < 2 puts "Usage: check <language> <test-number> [<output-file>]" exit(0) end language = ARGV[0] test_num = ARGV[1].to_i if ARGV.length >= 3 output_file_name = ARGV[2] else output_file_name = "output...
Ruby
#!/usr/bin/ruby problem_home = ENV['PROBLEM_HOME'] require "#{problem_home}/script/test_dsl.rb" if ARGV.length < 2 puts "Usage: check <language> <test-number> [<output-file>]" exit(0) end language = ARGV[0] test_num = ARGV[1].to_i if ARGV.length >= 3 output_file_name = ARGV[2] else output_file_name = "output...
Ruby
#!/usr/bin/ruby problem_home = ENV['PROBLEM_HOME'] require "#{problem_home}/script/test_dsl.rb" if ARGV.length < 2 puts "Usage: check <language> <test-number> [<output-file>]" exit(0) end language = ARGV[0] test_num = ARGV[1].to_i if ARGV.length >= 3 output_file_name = ARGV[2] else output_file_name = "output...
Ruby
module GraderEngineHelperMethods def clear_sandbox config = Grader::Configuration.get_instance clear_cmd = "rm -rf #{config.test_sandbox_dir}/*" system(clear_cmd) end def init_sandbox config = Grader::Configuration.get_instance clear_sandbox FileUtils.mkdir_p config.user_result_dir c...
Ruby
# This test helper loads the grader's environment and rails environment GRADER_ENV = 'test' require File.join(File.dirname(__FILE__),'../config/environment') # this shall be removed soon RAILS_ENV = Grader::Configuration.get_instance.rails_env require RAILS_ROOT + '/config/environment' # make sure not to access re...
Ruby
# This test helper loads the grader's environment and rails environment GRADER_ENV = 'test' require File.join(File.dirname(__FILE__),'../config/environment') # this shall be removed soon RAILS_ENV = Grader::Configuration.get_instance.rails_env require RAILS_ROOT + '/config/environment' # make sure not to access re...
Ruby
#!/usr/bin/ruby # new_problem: # * creates a directory for a problem in the current directory, # * create standard testcase config file require 'erb' def process_options(options) i = 2 while i<ARGV.length if ARGV[i]=='-t' options[:time_limit] = ARGV[i+1].to_i if ARGV.length>i+1 i += 1 end ...
Ruby
#!/usr/bin/ruby def talk(str) if TALKATIVE puts str end end def execute(command, error_message="") if not system(command) puts "ERROR: #{error_message}" exit(127) end end def save_source(submission,dir,fname) f = File.open("#{dir}/#{fname}","w") f.write(submission.source) f.close end def c...
Ruby
#!/usr/bin/ruby require 'erb' require 'fileutils' require File.join(File.dirname(__FILE__),'lib/import_helper') JUDGE_ENVIRONMENTS = [:grading, :exam] ENV_INFO = { :grading => { :ev_dir => 'ev', :raw_prefix => '', }, :exam => { :ev_dir => 'ev-exam', :raw_prefix => 'ex.', } } def input_filena...
Ruby
#!/usr/bin/ruby require 'optparse' def config Grader::Configuration.get_instance end def log_file_name if !File.exists?(config.log_dir) raise "Log directory does not exist: #{config.log_dir}" end config.log_dir + "/#{GRADER_ENV}.#{Process.pid}" end def log(str) if config.talkative puts str ...
Ruby
#!/usr/bin/ruby def stop_grader(id) if id==:all File.open(File.dirname(__FILE__) + "/stop.all",'w').close else File.open(File.dirname(__FILE__) + "/stop.#{id}",'w').close end end def check_stopfile FileTest.exist?(File.dirname(__FILE__) + "/stop.all") or FileTest.exist?(File.dirname(__FILE__) + "/...
Ruby
#!/usr/bin/ruby # import_problem: # * creates a directory for a problem in the current directory, # * copy testdata in the old format and create standard testcase config file require 'erb' require 'fileutils' require File.join(File.dirname(__FILE__),'lib/import_helper') def input_filename(dir,i) "#{dir}/input-#{...
Ruby
#!/usr/bin/ruby # import_problem: # * creates a directory for a problem in the current directory, # * copy testdata in the old format and create standard testcase config file require 'erb' require 'fileutils' require File.join(File.dirname(__FILE__),'lib/import_helper') def input_filename(dir,i) "#{dir}/input-#{...
Ruby
#!/usr/bin/ruby # new_problem: # * creates a directory for a problem in the current directory, # * create standard testcase config file require 'erb' def process_options(options) i = 2 while i<ARGV.length if ARGV[i]=='-t' options[:time_limit] = ARGV[i+1].to_i if ARGV.length>i+1 i += 1 end ...
Ruby
#!/usr/bin/ruby def log(str='') if ENV['TALKATIVE']!=nil puts str end if ENV['GRADER_LOGGING']!=nil log_fname = ENV['GRADER_LOGGING'] fp = File.open(log_fname,"a") fp.puts("judge: #{Time.new.strftime("%H:%M")} #{str}") fp.close end end problem_home = ENV['PROBLEM_HOME'] def execute(comman...
Ruby
#!/usr/bin/ruby CORRECT_MARK = 'P' INCORRECT_MARK = '-' TIMEOUT_MARK = 'T' RUN_ERROR_MARK = 'x' def log(str='') if ENV['TALKATIVE']!=nil puts str end if ENV['GRADER_LOGGING']!=nil log_fname = ENV['GRADER_LOGGING'] fp = File.open(log_fname,"a") fp.puts("grade: #{Time.new.strftime("%H:%M")} #{str}...
Ruby
#!/usr/bin/ruby problem_home = ENV['PROBLEM_HOME'] require "#{problem_home}/script/test_dsl.rb" if ARGV.length < 2 puts "Usage: check <language> <test-number> [<output-file>]" exit(0) end language = ARGV[0] test_num = ARGV[1].to_i if ARGV.length >= 3 output_file_name = ARGV[2] else output_file_name = "output...
Ruby
#!/usr/bin/ruby def log(str='') if ENV['TALKATIVE']!=nil puts str end if ENV['GRADER_LOGGING']!=nil log_fname = ENV['GRADER_LOGGING'] fp = File.open(log_fname,"a") fp.puts("run: #{Time.new.strftime("%H:%M")} #{str}") fp.close end end def extract_time(t) # puts "TIME: #{t}" if (result=...
Ruby
#!/usr/bin/ruby def log(str='') if ENV['TALKATIVE']!=nil puts str end if ENV['GRADER_LOGGING']!=nil log_fname = ENV['GRADER_LOGGING'] fp = File.open(log_fname,"a") fp.puts("judge: #{Time.new.strftime("%H:%M")} #{str}") fp.close end end problem_home = ENV['PROBLEM_HOME'] def execute(comman...
Ruby
#!/usr/bin/ruby CORRECT_MARK = 'P' INCORRECT_MARK = '-' TIMEOUT_MARK = 'T' RUN_ERROR_MARK = 'x' def log(str='') if ENV['TALKATIVE']!=nil puts str end if ENV['GRADER_LOGGING']!=nil log_fname = ENV['GRADER_LOGGING'] fp = File.open(log_fname,"a") fp.puts("grade: #{Time.new.strftime("%H:%M")} #{str}...
Ruby
#!/usr/bin/ruby def log(str='') if ENV['TALKATIVE']!=nil puts str end if ENV['GRADER_LOGGING']!=nil log_fname = ENV['GRADER_LOGGING'] fp = File.open(log_fname,"a") fp.puts("run: #{Time.new.strftime("%H:%M")} #{str}") fp.close end end def extract_time(t) # puts "TIME: #{t}" if (result=...
Ruby
class DSLNode def DSLNode.scalar_attr(*names) names.each do |name| define_method name do |*a| if a.length == 0 instance_variable_get( "@#{name}" ) else instance_variable_set( "@#{name}", a[0] ) end end end end def DSLNode.array_attr(*names) ...
Ruby
#!/usr/bin/ruby problem_home = ENV['PROBLEM_HOME'] require "#{problem_home}/script/test_dsl.rb" if ARGV.length < 2 puts "Usage: check <language> <test-number> [<output-file>]" exit(0) end language = ARGV[0] test_num = ARGV[1].to_i if ARGV.length >= 3 output_file_name = ARGV[2] else output_file_name = "output...
Ruby
#!/usr/bin/ruby # # This is a check script wrapper. It read all required information # and call a real check script call REAL_CHECK_SCRIPT in directory # [problem_home]/script # REAL_CHECK_SCRIPT = "<%= script_name %>" # The REAL_CHECK_SCRIPT is called with: # # (script) <lang> <test-num> <in-file> <out-file> <ans...
Ruby