code
stringlengths
1
1.73M
language
stringclasses
1 value
#!/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
#!/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 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 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
# Rails app directory RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__),"../../..")) GRADER_ROOT = File.expand_path(File.join(File.dirname(__FILE__),"..")) # This load all required codes require File.join(File.dirname(__FILE__),'../lib/boot') # load the required environment file require File.dirname(__FI...
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
# # A runner drives the engine into various tasks. # module Grader class Runner def initialize(engine, grader_process=nil) @engine = engine @grader_process = grader_process end def grade_oldest_task task = Task.get_inqueue_and_change_status(Task::STATUS_GRADING) if task!=nil ...
Ruby
module Grader # This singleton class holds basic configurations for grader. When # running in each mode, grader uses resources from different # directories and outputs differently. Usually the attributes name # are descriptive; below we explain more on each attributes. class Configuration # Rails' envi...
Ruby
def filter_filename_for_testrun(testrun, filename_list, raw_prefix='') l = [] regex = Regexp.new("^(#{Regexp.escape(raw_prefix)}#{testrun}[a-z]*|#{testrun}-.*)$") filename_list.each do |filename| if regex.match(filename) l << filename end end l end def build_testrun_info(num_testruns, input_fi...
Ruby
module Grader class SubmissionRoomMaker def initialize @config = Grader::Configuration.get_instance end def produce_grading_room(submission) user = submission.user problem = submission.problem grading_room = "#{@config.user_result_dir}/" + "#{user.login}/#{problem.na...
Ruby
module Grader class Initializer def self.run(&block) config = Grader::Configuration.get_instance yield config end end end
Ruby
require File.join(File.dirname(__FILE__), 'configuration') require File.join(File.dirname(__FILE__), 'initializer') require File.join(File.dirname(__FILE__), 'submission_helper') require File.join(File.dirname(__FILE__), 'test_request_helper') require File.join(File.dirname(__FILE__), 'engine') require File.join(Fil...
Ruby
# # This part contains various test_request helpers for interfacing # with Grader::Engine. There are TestRequestRoomMaker and # TestRequestReporter. module Grader # # A TestRequestRoomMaker is a helper object for Engine # - finds grading room: in user_result_dir/(user)/test_request/ ... # - prepare problem c...
Ruby
require 'fileutils' require 'ftools' require 'lib/dir_init' module Grader # # A grader engine grades a submission, against anything: a test # data, or a user submitted test data. It uses two helpers objects: # room_maker and reporter. # class Engine attr_writer :room_maker attr_writer :repor...
Ruby
require 'ftools' # DirInit::Manager handles directory initialization and clean-up when # there are many concurrent processes that wants to modify the # directory in the same way. # # An example usage is when each process wants to copy some temporary # files to the directory and delete these files after finishing its #...
Ruby
dir = File.dirname(__FILE__) Dir[File.expand_path("#{dir}/**/*.rb")].uniq.each do |file| require file end
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'spec/rails/story_adapter'
Ruby
class CreateSubmissions < ActiveRecord::Migration def self.up create_table :submissions do |t| t.column :user_id, :integer t.column :problem_id, :integer t.column :language_id, :integer t.column :source, :text t.column :binary, :binary t.column :submitted_at, :datetime t....
Ruby
class AddLanguageExt < ActiveRecord::Migration def self.up add_column :languages, :ext, :string, :limit => 10 Language.reset_column_information langs = Language.find(:all) langs.each do |l| l.ext = l.name l.save end end def self.down remove_column :languages, :ext end end
Ruby
class AddSessions < ActiveRecord::Migration def self.up create_table :sessions do |t| t.column :session_id, :string t.column :data, :text t.column :updated_at, :datetime end add_index :sessions, :session_id add_index :sessions, :updated_at end def self.down drop_table :sess...
Ruby
class AddSiteToUserAndAddDefaultSite < ActiveRecord::Migration def self.up default_site = Site.new({:name => 'default', :started => false}) default_site.save! add_column :users, :site_id, :integer User.reset_column_information User.find(:all).each do |user| c...
Ruby
class AddTimestampsToUsers < ActiveRecord::Migration def self.up add_timestamps :users end def self.down remove_timestamps :users end end
Ruby
class AddAdminEmailToConfig < ActiveRecord::Migration def self.up Configuration.create(:key => 'system.admin_email', :value_type => 'string', :value => 'admin@admin.email') end def self.down Configuration.find_by_key('system.admin_email').destroy end en...
Ruby
class CreateMessages < ActiveRecord::Migration def self.up create_table :messages do |t| t.column "sender_id", :integer t.column "receiver_id", :integer t.column "replying_message_id", :integer t.column "body", :text t.column "replied", :boolean # this is for efficiency ...
Ruby
class AddTaskToGraderProcess < ActiveRecord::Migration def self.up add_column :grader_processes, :task_id, :integer end def self.down remove_column :grader_processes, :task_id end end
Ruby
class ChangeUserLoginStringLimit < ActiveRecord::Migration def self.up execute "ALTER TABLE `users` CHANGE `login` `login` VARCHAR( 50 )" end def self.down execute "ALTER TABLE `users` CHANGE `login` `login` VARCHAR( 10 )" end end
Ruby
class AddContestFlagToAnnouncements < ActiveRecord::Migration def self.up add_column :announcements, :contest_only, :boolean, :default => false end def self.down remove_column :announcements, :contest_only end end
Ruby
class AddRunstatColumnsToTestRequest < ActiveRecord::Migration def self.up add_column :test_requests, :running_time, :float add_column :test_requests, :exit_status, :string add_column :test_requests, :memory_usage, :integer end def self.down remove_column :test_requests, :running_time remove_...
Ruby
class AddStatusToTasks < ActiveRecord::Migration def self.up add_column :tasks, :status, :integer add_column :tasks, :updated_at, :datetime Task.reset_column_information Task.find(:all).each do |task| task.status_complete task.save end end def self.down remove_column :tasks, ...
Ruby
class CreateConfigurations < ActiveRecord::Migration def self.up create_table :configurations do |t| t.column :key, :string t.column :value_type, :string t.column :value, :string t.timestamps end Configuration.reset_column_information Configuration.create(:key => 'system.sing...
Ruby
class AddCountryToSitesAndUsers < ActiveRecord::Migration def self.up add_column 'sites', 'country_id', :integer add_column 'sites', 'password', :string add_column 'users', 'country_id', :integer end def self.down remove_column 'users', 'country_id' remove_column 'sites', 'country_id' r...
Ruby
class AddModeToConfigurations < ActiveRecord::Migration def self.up # Configuration['system.mode']: # * 'standard' mode # * 'contest' mode (check site start time/stop time) # * 'analysis' mode (show results, no new submissions) Configuration.create(:key => 'system.mode', ...
Ruby
class RefactorProblemBodyToDescription < ActiveRecord::Migration def self.up add_column :problems, :description_id, :integer Problem.reset_column_information Problem.find(:all).each do |problem| if problem.body!=nil description = Description.new description.body = problem.body ...
Ruby
class ChangeCompilerMessageTypeTestRequest < ActiveRecord::Migration def self.up change_column :test_requests, :compiler_message, :text end def self.down change_column :test_requests, :compiler_message, :string end end
Ruby
class CreateRoles < ActiveRecord::Migration def self.up create_table :roles do |t| t.column 'name', :string end create_table :roles_users, :id => false do |t| t.column 'role_id', :integer t.column 'user_id', :integer end add_index :roles_users, :user_id end def self.down ...
Ruby
class AddFrontpageFlagToAnnouncement < ActiveRecord::Migration def self.up add_column :announcements, "frontpage", :boolean, :default => 0 end def self.down remove_column :announcements, "frontpage" end end
Ruby
class AddMoreOptionsToConfigurations < ActiveRecord::Migration def self.up # If the server is in contest mode and # Configuration['contest.multisites'] is true # the menu for site administrator is shown. Configuration.create(:key => 'contest.multisites', :value_type => 'b...
Ruby
class CreateGraderProcesses < ActiveRecord::Migration def self.up create_table :grader_processes do |t| t.column :ip, :string, :limit => 20 t.column :pid, :integer t.column :mode, :string t.column :active, :boolean t.timestamps end add_index :grader_processes, ["ip","pid"] ...
Ruby
class AddIndexToSubmissions < ActiveRecord::Migration def self.up add_index :submissions, [:user_id, :problem_id] end def self.down remove_index :submissions, :column => [:user_id, :problem_id] end end
Ruby
class CreateDescriptions < ActiveRecord::Migration def self.up create_table :descriptions do |t| t.column :body, :text t.column :markdowned, :boolean t.timestamps end end def self.down drop_table :descriptions end end
Ruby
class AddUrlToProblem < ActiveRecord::Migration def self.up add_column :problems, :url, :string end def self.down remove_column :problems, :url end end
Ruby
class AddEmailingInfoOnConfigOption < ActiveRecord::Migration def self.up # If Configuration['system.online_registration'] is true, the # system allows online registration, and will use these # information for sending confirmation emails. Configuration.create(:key => 'system.online_registration.smtp',...
Ruby
class CreateRights < ActiveRecord::Migration def self.up create_table :rights do |t| t.column 'name', :string t.column 'controller', :string t.column 'action', :string end create_table :rights_roles, :id => false do |t| t.column 'right_id', :integer t.column 'role_id', :inte...
Ruby
class CreateGraderMessages < ActiveRecord::Migration def self.up create_table :grader_messages do |t| t.integer :grader_process_id t.integer :command t.string :options t.integer :target_id t.boolean :accepted t.boolean :completed t.integer :accepting_grader_process_id ...
Ruby
class AddEmailToUsers < ActiveRecord::Migration def self.up add_column :users, :email, :string end def self.down remove_column :users, :email end end
Ruby
class CreateCountries < ActiveRecord::Migration def self.up create_table :countries do |t| t.column :name, :string t.timestamps end end def self.down drop_table :countries end end
Ruby
class AddActivatedToUsers < ActiveRecord::Migration def self.up add_column :users, :activated, :boolean, :default => 0 User.reset_column_information User.find(:all).each do |user| # disable validation class <<user def valid? return true end end user.ac...
Ruby
class AddTerminatedToGraderProcesses < ActiveRecord::Migration def self.up add_column :grader_processes, :terminated, :boolean end def self.down remove_column :grader_processes, :terminated end end
Ruby
class CreateTasks < ActiveRecord::Migration def self.up create_table :tasks do |t| t.column 'submission_id', :integer t.column 'created_at', :datetime end end def self.down drop_table :tasks end end
Ruby
class CreateAnnouncements < ActiveRecord::Migration def self.up create_table :announcements do |t| t.string :author t.text :body t.boolean :published t.timestamps end end def self.down drop_table :announcements end end
Ruby
class AddCommonExtToLanguages < ActiveRecord::Migration def self.up # language.common_ext is a comma-separated list of common file # extensions. add_column :languages, :common_ext, :string # updating table information Language.reset_column_information common_ext = { 'c' => 'c', '...
Ruby
class AddGradersRightToAdminRole < ActiveRecord::Migration def self.up admin_role = Role.find_by_name('admin') graders_right = Right.create(:name => 'graders_admin', :controller => 'graders', :action => 'all') admin_role.rights << gra...
Ruby
class AddTaskTypeToGraderProcesses < ActiveRecord::Migration def self.up add_column 'grader_processes', 'task_type', :string end def self.down remove_column 'grader_processes', 'task_type' end end
Ruby
class AddBodyToProblems < ActiveRecord::Migration def self.up add_column :problems, :body, :text end def self.down remove_column :problems, :body end end
Ruby
class CreateProblems < ActiveRecord::Migration def self.up create_table :problems do |t| t.column :name, :string, :limit => 30 t.column :full_name, :string t.column :full_score, :integer t.column :date_added, :date t.column :available, :boolean end end def self.down drop...
Ruby
class AddNumberToSubmissions < ActiveRecord::Migration def self.up add_column :submissions, :number, :integer # add number field for all records Submission.reset_column_information last_user_id = nil last_problem_id = nil current_number = 0 Submission.find(:all, :or...
Ruby
class CreateTestRequests < ActiveRecord::Migration def self.up create_table :test_requests do |t| t.column :user_id, :integer t.column :problem_id, :integer t.column :submission_id, :integer t.column :input_file_name, :string t.column :output_file_name, :string t.column :runnin...
Ruby
class CreateLanguages < ActiveRecord::Migration def self.up create_table :languages do |t| t.column :name, :string, :limit => 10 t.column :pretty_name, :string end Language.create(:name => "c", :pretty_name => "C") Language.create(:name => "cpp", :pretty_name => "C++") Language.create...
Ruby
class AddSupportsForOutputOnlyProblems < ActiveRecord::Migration def self.up add_column :submissions, :source_filename, :string add_column :problems, :output_only, :boolean end def self.down remove_column :submissions, :source_filename remove_column :problems, :output_only end end
Ruby
class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.column :login, :string, :limit => 10 t.column :full_name, :string t.column :hashed_password, :string t.column :salt, :string, :limit => 5 t.column :alias, :string end # force unique name ...
Ruby
class AddTestRequestEarlyTimeoutToConfig < ActiveRecord::Migration def self.up # If Configuration['contest.test_request.early_timeout'] is true # the user will not be able to use test request at 30 minutes # before the contest ends. Configuration.create(:key => 'contest.test_request.early_timeout...
Ruby
class AddAdminAndRoles < ActiveRecord::Migration def self.up root = User.new(:login => 'root', :full_name => 'Administrator', :alias => 'root') root.password = 'ioionrails'; class << root public :encrypt_new_password def valid? true end end root.encrypt_ne...
Ruby
class AddTestAllowedToProblems < ActiveRecord::Migration def self.up add_column :problems, :test_allowed, :boolean Problem.reset_column_information Problem.find(:all).each do |problem| problem.test_allowed = true problem.save end end def self.down remove_column :problems, :test_a...
Ruby
class RenameGraderProcessColumnIpToHost < ActiveRecord::Migration def self.up rename_column :grader_processes, :ip, :host end def self.down rename_column :grader_processes, :host, :ip end end
Ruby
class CreateSites < ActiveRecord::Migration def self.up create_table :sites do |t| t.string :name t.boolean :started t.datetime :start_time t.timestamps end end def self.down drop_table :sites end end
Ruby
class AddContestNameToConfiguration < ActiveRecord::Migration def self.up # Configuration['contest.name']: # it will be shown on the user header bar Configuration.create(:key => 'contest.name', :value_type => 'string', :value => 'Grader') end def s...
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' class Test::Unit::TestCase # Transactional fixtures accelerate your tests by wrapping each test method # in a transaction that's rolled back on completion. This ensures that the # test datab...
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../../config/environment") def clear_all_tasks Task.find(:all).each do |task| task.destroy end end puts Task.find(:all, :conditions => {:status => Task::STATUS_COMPLETE}).length clear_all_tasks
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../../config/environment") def take_wait_return task = Task.get_inqueue_and_change_status(Task::STATUS_GRADING) sleep (rand)/10.0 task.status_complete task.save! end n = 300 n.times do |i| take_wait_return puts i end
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../../config/environment") def clear_all_tasks Task.find(:all).each do |task| task.destroy end end clear_all_tasks (1..1000).each do |i| Task.create(:id => i, :submission_id => i, :status => Task::S...
Ruby
#!c:/ruby/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired...
Ruby
#!c:/ruby/bin/ruby # # You may specify the path to the FastCGI crash log (a log of unhandled # exceptions which forced the FastCGI instance to exit, great for debugging) # and the number of requests to process before running garbage collection. # # By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log #...
Ruby
#!c:/ruby/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired...
Ruby
#!c:/ruby/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired...
Ruby
#!c:/ruby/bin/ruby # # You may specify the path to the FastCGI crash log (a log of unhandled # exceptions which forced the FastCGI instance to exit, great for debugging) # and the number of requests to process before running garbage collection. # # By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log #...
Ruby
#!c:/ruby/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired...
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/breakpointer'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/runner'
Ruby
#!/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/generate'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/destroy'
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/plugin'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/breakpointer'
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/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/about'
Ruby
#!/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