interface for judge0 api
gem install judge0
or
# Gemfile
gem 'judge0'
Judge0.base_url = 'http://api.custom-judge0.com'
sub = Judge0::Submission.new do |config|
config.source_code = 'p "Hello world!"'
config.language_id = 72
end
sub.run # hash of the submission result
sub.stdout # output
sub = Judge0::Submission.new do |config|
config.source_code = 'sleep 2; p "Hello world!"'
config.language_id = 72
end
sub.get_token
t = Thread.new {
sub.wait_response!
}
puts "🛏️ waiting..." # doing something while the code is running
t.join
puts sub.output
this is useful when you are trying to wait the response on a rails job but cant pass a submission as a params without writing a serializer, maybe in future i will make a job serializer and configure it out of the box
params = {
"source_code": "sleep 2; p 'Hello word!'",
"language_id": 72
}
token = Judge0.get_token(params)
Judge0.wait_response(token)
sub = Judge0::Submission.new do |config|
config.source_code = 'p gets.to_i'
config.language_id = 72
end
tests = [
['0', '0'],
['1', '1']
]
sub.tests_battery(tests)
sub = Judge0::Submission.new do |config|
config.source_code = 'p gets.to_i'
config.language_id = 72
end
tests = [
{input: '0', output: '0'},
{input: '1', output: '1'}
]
sub.tests_battery(tests)
class Test
attr_accessor :input, :output
def initialize(input, output)
@input = input
@output = output
end
end
sub = Judge0::Submission.new do |config|
config.source_code = 'p gets.to_i'
config.language_id = 72
end
tests = [
Test.new('0', '0'),
Test.new('1', '1')
]
sub.tests_battery(tests)
require 'pp'
pp Judge0::languages
pp Judge0::statuses
pp Judge0::system_info
pp Judge0::config_info
irb -Ilib -r judge0
gem build judge0.gemspec
gem push judge0-x.x.x.gem