code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
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
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
ENV['RSPEC'] = 'true' # allows autotest to discover rspec
ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) ||
$stderr.puts("Unable to find auto... | 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
if ARGV.any? {|arg| %w[--drb -X --generate-options -G --help -h --version -v].include?(arg)}
require 'rubygems' unless ENV['NO_RUBYGEMS']
else
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path(File.dirname(__FILE__) + "/../config/enviro... | 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
if ARGV.any? {|arg| %w[--drb -X --generate-options -G --help -h --version -v].include?(arg)}
require 'rubygems' unless ENV['NO_RUBYGEMS']
else
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path(File.dirname(__FILE__) + "/../config/enviro... | Ruby |
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/console' | Ruby |
#!/usr/bin/env ruby
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
ENV['RSPEC'] = 'true' # allows autotest to discover rspec
ENV['AUTOTEST'] = 'true' # allows autotest to run w/ color on linux
system((RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV) ||
$stderr.puts("Unable to find auto... | 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.join(File.dirname(__FILE__),'..','config','environment'))
require 'spec/autorun'
require 'spec/rails'
# Uncomment the next line to use webrat's matchers... | 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'
TEST_REQUEST_EARLY_TIMEOUT_KEY = 'contest.test_request.early_timeout'
# set @@cache = true to only reload once.
@@cache = false
@@configurations = nil
... | 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(contest_started=false)
if contest_started
Announcement.find(:all,
:conditions => "(published = 1) AND (frontpage = 0)",
:order => "created_at DESC")
else
Announcement.find(:all,
... | 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
validates_presence_of :name
validates_format_of :name, :with => /^\w+$/
validates_presence_of :full_name
def self.find_available_problems
find(:all, :conditions => {:available => true}, :order => "date_added DESC")
end
def self.new_from_... | Ruby |
class Country < ActiveRecord::Base
has_many :sites
end
| Ruby |
class Language < ActiveRecord::Base
@@languages_by_ext = {}
def self.cache_ext_hash
@@languages_by_ext = {}
Language.find(:all).each do |language|
language.common_ext.split(',').each do |ext|
@@languages_by_ext[ext] = language
end
end
end
def self.find_by_extension(ext)
if... | Ruby |
class MessagesController < ApplicationController
before_filter :authenticate
verify :method => :post, :only => ['create'],
:redirect_to => { :action => 'list' }
before_filter :admin_authorization, :only => ['console','show',
'reply','hide']
def list
... | 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
SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode'
def admin_authorization
return false unless authe... | 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',
'start_exam',
'start_grading',
'stop_all',
... | Ruby |
class MainController < ApplicationController
SYSTEM_MODE_CONF_KEY = 'system.mode'
before_filter :authenticate, :except => [:index, :login]
before_filter :check_viewability, :except => [:index, :login]
# COMMENTED 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,
:forget,
... | 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 |
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,... | Ruby |
class SiteController < ApplicationController
before_filter :site_admin_authorization, :except => 'login'
def login
# Site administrator login
@countries = Country.find(:all, :include => :sites)
@country_select = @countries.collect { |c| [c.name, c.id] }
@country_select_with_all = [['Any',0]]
... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.