Judge0 API integration for running/judging code with different languages

Related tags

API laravel-judge0
Overview

Laravel Judge0

Judge0 API integration for running/judging code with different languages

setInput('judge0') ->setExpectedOutput('the value you entered is : judge0') ->setTimeLimit(1) // seconds ->setMemoryLimitInMegabytes(256) ->submit(); ">
use Mouadbnl\Judge0\Models\Submission;

$submission = Submission::create([
        'language_id' => 54, // C++ (GCC 9.2.0)
        'source_code' =>'
        #include
   
        #include
   
        using namespace std;

        int main(){
            string s;
            cin >> s;
            cout << "the value you entered is : " << s;
            return 0;
        }
        '
    ])
    ->setInput('judge0')
    ->setExpectedOutput('the value you entered is : judge0')
    ->setTimeLimit(1) // seconds
    ->setMemoryLimitInMegabytes(256)
    ->submit();

Installation

You can install the package via composer:

composer require mouadbnl/laravel-judge0

You can publish and run the migrations with:

php artisan vendor:publish --provider="Mouadbnl\Judge0\Judge0ServiceProvider" --tag="judge0-migrations"
php artisan migrate

You can publish the config file with:

php artisan vendor:publish --provider="Mouadbnl\Judge0\Judge0ServiceProvider" --tag="judge0-config"

Usage

First add Submitter trait to the User Model.

use Mouadbnl\Judge0\Traits\Submitter;
class User extends Authenticatable
{
    use Submitter;
    /** **/
}

This create a polymorphique relationship between the User model and the Submission model provided by this package. You can let the User make a submission using the follwing code:

setInput('judge0') ->setExpectedOutput('the value you entered is : judge0') ->setTimeLimit(1) // seconds ->setMemoryLimitInMegabytes(256) ->submit(); ">
$user = User::firstOrFail();
$user->submissions()->create([
        'language_id' => 54, // C++ (GCC 9.2.0)
        'source_code' =>'
        #include
   
        #include
   
        using namespace std;

        int main(){
            string s;
            cin >> s;
            cout << "the value you entered is : " << s;
            return 0;
        }
        '
    ])
    ->setInput('judge0')
    ->setExpectedOutput('the value you entered is : judge0')
    ->setTimeLimit(1) // seconds
    ->setMemoryLimitInMegabytes(256)
    ->submit();

Define the API to use

This package provides two drivers to connect to judge0 API

Instance Driver

This allows you to connect to a judge0 Docker instance. to do so please define the JUDGE0_BASE_URI which is the url to your instance and JUDGE0_KEY which it the API key to authenticate in your environment variables or .env file.

JUDGE0_BASE_URI=localhost:2358
JUDGE0_KEY=yout_key

Rapidapi Driver

This allows you to connect to the the Judge0 app on RapidAPI. For this you need to define the following in your environment variables or .env file.

  • JUDGE0_RAPIDAPI_BASE_URI the rapidapi url to make the requests to, which it by default https://judge0-ce.p.rapidapi.com.
  • JUDGE0_RAPIDAPI_HOST, by default it is judge0-ce.p.rapidapi.com.
  • JUDGE0_RAPIDAPI_KEY yout rapidapi key.
JUDGE0_RAPIDAPI_BASE_URI=https://judge0-ce.p.rapidapi.com
JUDGE0_RAPIDAPI_HOST=judge0-ce.p.rapidapi.com
JUDGE0_RAPIDAPI_KEY=yout_key

Testing

composer test

Credits

License

The MIT License (MIT). Please see License File for more information.

You might also like...
This package makes it easy for developers to access WhatsApp Cloud API service in their PHP code.
This package makes it easy for developers to access WhatsApp Cloud API service in their PHP code.

The first PHP API to send and receive messages using a cloud-hosted version of the WhatsApp Business Platform

This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science courses and the like.
This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science courses and the like.

Simple PHP API v.1.0 This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science courses a

微信支付 API v3 的 PHP Library,同时也支持 API v2

微信支付 WeChatPay OpenAPI SDK [A]Sync Chainable WeChatPay v2&v3's OpenAPI SDK for PHP 概览 微信支付 APIv2&APIv3 的Guzzle HttpClient封装组合, APIv2已内置请求数据签名及XML转换器,应

This API provides functionality for creating and maintaining users to control a simple To-Do-List application. The following shows the API structure for users and tasks resources.
This API provides functionality for creating and maintaining users to control a simple To-Do-List application. The following shows the API structure for users and tasks resources.

PHP API TO-DO-LIST v.2.0 This API aims to present a brief to consume a API resources, mainly for students in the early years of Computer Science cours

API documentation API SCB EASY APP

SCB-API-EASY V3.0 API documentation SIAM COMMERCIAL BANK PUBLIC COMPANY LTD. API SCB Easy V3 endpoint = https://fasteasy.scbeasy.link 1.0. Get balance

Courier API adalah project API untuk mengetahui ongkos kirim Logistik-logistik pengiriman barang antar kota & International
Courier API adalah project API untuk mengetahui ongkos kirim Logistik-logistik pengiriman barang antar kota & International

Courier API Courier API adalah project API untuk mengetahui ongkos kirim Logistik-logistik pengiriman barang antar kota (dalam negeri) & International

Laravel api tool kit is a set of tools that will help you to build a fast and well-organized API using laravel best practices.
Laravel api tool kit is a set of tools that will help you to build a fast and well-organized API using laravel best practices.

Laravel API tool kit and best API practices Laravel api tool kit is a set of tools that will help you to build a fast and well-organized API using lar

LaraBooks API - Simple API for iOS SwiftUI app tests.

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Simple PHP API client for tube-hosting.com rest API

Tube-Hosting API PHP client Explanation This PHP library is a simple api wrapper/client for the tube-hosting.com api. It is based on the provided docu

Releases(0.4.2)
Owner
Mouad Benali
Young college student and freelancer
Mouad Benali
PHP library for Qvapay API integration.

Php library for Qvapay API This PHP library facilitates the integration of the Qvapay API. Sign up on QvaPay Create your account to process payments t

Omar Villafuerte 9 Aug 20, 2022
Airbrake.io & Errbit integration for Symfony 3/4/5. This bundle plugs the Airbrake API client into Symfony project

AmiAirbrakeBundle Airbrake.io & Errbit integration for Symfony 3/4/5. This bundle plugs the Airbrake API client into Symfony project. Prerequisites Th

Anton Minin 8 May 6, 2022
Simple and effective multi-format Web API Server to host your PHP API as Pragmatic REST and / or RESTful API

Luracast Restler ![Gitter](https://badges.gitter.im/Join Chat.svg) Version 3.0 Release Candidate 5 Restler is a simple and effective multi-format Web

Luracast 1.4k Dec 14, 2022
Provides a Middleware to integration Tideways into Symfony Messenger Processing

Tideways Middleware for Symfony Messenger This package is currently under development and might be moved into the Tideways PHP Extension or stay indep

Tideways 6 Jul 5, 2022
Integration with your Symfony app & Vite

ViteBundle : Symfony integration with Vite This bundle helping you render all of the dynamic script and link tags needed. Essentially, he provide two

Hugues Tavernier 84 Dec 21, 2022
Fully unit tested Facebook SDK v5 integration for Laravel & Lumen

Laravel Facebook SDK A fully unit-tested package for easily integrating the Facebook SDK v5 into Laravel and Lumen 5.0, 5.1, 5.2, & 5.3. This is packa

Sammy Kaye Powers 697 Nov 6, 2022
A RESTful and extendable Backend as a Service that provides instant backend to develop sites and apps faster, with dead-simple integration for JavaScript, iOS, Android and more.

Welcome to hook ![Gitter](https://badges.gitter.im/Join Chat.svg) hook is a RESTful, extendable Backend as a Service that provides instant backend to

doubleleft 762 Dec 30, 2022
Doctrine-like fixtures integration for Shopware 6.

Shopware 6 Fixtures Did you ever want to create and load Doctrine-like fixtures in your Shopware 6 plugin? Look no further! This plugin provides an ul

Familiy Office 0 Oct 29, 2021
Paynow SDK Laravel integration

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Alfred Tanaka Kudiwahove 2 Sep 20, 2021
WordPress integration for globalis/chargebee-php-sdk

chargebee-php-sdk-wp Overview WordPress integration for globalis/chargebee-php-sdk Features Convert PSR-14 events into WordPress hooks Add query-monit

GLOBALIS media systems 7 Feb 17, 2022