Project

judge0

0.0
No commit activity in last 3 years
No release in over 3 years
ruby interface for judge0 api.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

>= 1.0.0
 Project Readme

judge0-gem

interface for judge0 api

Installation

gem install judge0

or

# Gemfile
gem 'judge0'

Usage Examples

set a custom url

  Judge0.base_url = 'http://api.custom-judge0.com'

simple code execution

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

wait the response on another thread

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
same thing but without creating a Judge0::submission object

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)

tests battery execution

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)

utils

require 'pp'
pp Judge0::languages
pp Judge0::statuses
pp Judge0::system_info
pp Judge0::config_info

development

test

  irb -Ilib -r judge0

build

  gem build judge0.gemspec

push

  gem push judge0-x.x.x.gem