code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
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 |
# Thai translation for Ruby on Rails
# original by Prem Sichanugrist (s@sikachu.com/sikandsak@gmail.com)
# activerecord keys fixed by Jittat Fakcharoenphol (jittat@gmail.com)
{
:'th' => {
:date => {
:formats => {
:default => lambda { |date| "%d-%m-#{date.year+543}" },
:short =>... | 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'
require 'spe... | Ruby |
module GraderScript
def self.grader_control_enabled?
if defined? GRADER_ROOT_DIR
GRADER_ROOT_DIR != ''
else
false
end
end
def self.raw_dir
File.join GRADER_ROOT_DIR, "raw"
end
def self.call_grader(params)
if GraderScript.grader_control_enabled?
cmd = File.join(GRADER_R... | Ruby |
gem 'test-unit', '1.2.3' if RUBY_VERSION.to_f >= 1.9
rspec_gem_dir = nil
Dir["#{RAILS_ROOT}/vendor/gems/*"].each do |subdir|
rspec_gem_dir = subdir if subdir.gsub("#{RAILS_ROOT}/vendor/gems/","") =~ /^(\w+-)?rspec-(\d+)/ && File.exist?("#{subdir}/lib/spec/rake/spectask.rb")
end
rspec_plugin_dir = File.expand_path(Fil... | Ruby |
require 'tmpdir'
class TestdataImporter
attr :log_msg
def import_from_file(problem_name,
tempfile,
time_limit,
memory_limit)
dirname = TestdataImporter.extract(problem_name, tempfile)
return false if not dirname
@log_msg = Grade... | 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 AddTaskToGraderProcess < ActiveRecord::Migration
def self.up
add_column :grader_processes, :task_id, :integer
end
def self.down
remove_column :grader_processes, :task_id, :integer
end
end
| 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 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 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 AddUrlToProblem < ActiveRecord::Migration
def self.up
add_column :problems, :url, :string
end
def self.down
remove_column :problems, :url
end
end
| 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 AddEmailToUsers < ActiveRecord::Migration
def self.up
add_column :users, :email, :string
end
def self.down
remove_column :users, :email
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 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 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 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
end
root.encrypt_new_password
role = Role.create(:name... | 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 |
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
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/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/console' | 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/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/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/generate' | Ruby |
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def user_header
menu_items = ''
user = User.find(session[:user_id])
# main page
append_to menu_items, '[Main]', 'main', 'list'
append_to menu_items, '[Submissions]', 'main', 'submission... | Ruby |
module ProblemsHelper
end
| Ruby |
module UserAdminHelper
end
| Ruby |
module GradersHelper
end
| Ruby |
module LoginHelper
end
| Ruby |
module UsersHelper
end
| Ruby |
module TestHelper
end
| Ruby |
module MainHelper
def format_short_time(time)
now = Time.now
st = ''
if (time.yday != now.yday) or
(time.year != now.year)
st = time.strftime("%x ")
end
st + time.strftime("%X")
end
end
| 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 => "problem_id"
validates_presence_of :login
validates_presence_of :full_name
validates_length_of :full_name, :minimum => 1
validates_presence_of :password, :if => :password_required?
... | Ruby |
class GraderProcess < ActiveRecord::Base
belongs_to :task
def self.find_by_host_and_pid(host,pid)
return GraderProcess.find(:first,
:conditions => {
:host => host,
:pid => pid
})
... | Ruby |
class Task < ActiveRecord::Base
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
def status_grading!
... | 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
validates_presence_of :source
validates_length_of :source, :maximum => 100_000, :allow_blank => true, :message => 'too long'
validates_length_of :source, :minimum => 1, :allow_blank => true, :message => 'too sh... | 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
def self.find_available_problems
find(:all, :conditions => {:available => true})
end
end
| Ruby |
class Language < ActiveRecord::Base
end
| 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 :authenticate
def list
@grader_processes = GraderProcess.find(:all,
:order => 'updated_at desc')
@stalled_processes = GraderProcess.find_stalled_process
end
def clear
grader_proc = GraderP... | Ruby |
class MainController < ApplicationController
before_filter :authenticate, :except => [:index, :login]
verify :method => :post, :only => [:submit],
:redirect_to => { :action => :index }
def index
redirect_to :action => 'login'
end
def login
reset_session
render :action => 'login', :la... | 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 UsersController < ApplicationController
before_filter :authenticate
verify :method => :post, :only => [:chg_passwd],
:redirect_to => { :action => :index }
in_place_edit_for :user, :alias_for_editing
in_place_edit_for :user, :email_for_editing
def index
@user = User.find(session[:user_id... | 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 :authenticate, :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... | Ruby |
class TestController < ApplicationController
before_filter :authenticate
verify :method => :post, :only => [:test_submit],
:redirect_to => { :action => :index }
def index
@user = User.find(session[:user_id])
prepare_index_information
end
def submit
@user = User.find(session[:user_id])... | Ruby |
ActionController::Routing::Routes.draw do |map|
# 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 assign values other than :controller and :action
# ... | Ruby |
# Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb
unless defined?(RAILS_ROOT)
root_path = File.join(File.dirname(__FILE__), '..')
unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
require 'pathname'
root_path = Pathname.new(root_path).cleanpath(true).to_s
end
... | Ruby |
# Be sure to restart your web server when you modify this file.
# Uncomment below to force Rails into production mode when
# you don't control web/app server and can't set it the proper way
# ENV['RAILS_ENV'] ||= 'production'
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION ... | 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 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.