### Clone and Install Jobe Source: https://github.com/trampgeek/jobe/blob/master/README.md Clones the Jobe project into the web root directory and executes the installation script. The script requires root privileges to set up necessary users and sudo configurations. ```bash cd WEBROOT sudo git clone https://github.com/trampgeek/jobe.git ``` ```bash cd WEBROOT/jobe sudo ./install ``` -------------------------------- ### Octave Language Task Configuration Example in PHP Source: https://github.com/trampgeek/jobe/blob/master/README.md Provides an example of a task configuration for the Octave programming language in PHP. Similar to the C example, this would extend LanguageTask and define Octave-specific settings for compilation (or interpretation) and execution. The focus is on how Octave scripts are handled. ```php class Octave_Task extends LanguageTask { public function __construct() { parent::__construct(); // Set Octave-specific default interpret and run options $this->interpret_command = 'octave'; // Example interpret command $this->run_command = [$this->interpret_command, '--no-window-system', '%s']; // Example run command } public function getVersion() { return 'octave --version'; // Example version check command } public function compile() { // For interpreted languages like Octave, this might do nothing or copy the script. $this->executableFileName = $this->sourceFileName; // Treat source file as executable } public function getRunCommand() { // Return the bash command to execute the Octave script. return array_merge([$this->executableFileName], $this->run_args); } } ``` -------------------------------- ### Install PHPUnit via Composer Source: https://github.com/trampgeek/jobe/blob/master/tests/README.md Installs PHPUnit, a recommended testing framework for CodeIgniter, using Composer. This command ensures that the necessary testing dependencies are available in your project. ```console > composer install ``` -------------------------------- ### Example Coderunner Sandbox Parameters for C Compilation Source: https://github.com/trampgeek/jobe/blob/master/README.md This example shows how to set compilation arguments for C code within Moodle Coderunner's sandbox parameters. It specifies enabling all warnings and aborting on any warning, ensuring C89 compliance. This configuration is passed to Jobe to control the compilation process. ```json { "compileargs": ["-Wall", "-Werror", "-std=c89"] } ``` -------------------------------- ### Install Jobe Dependencies on Ubuntu 22.04 Source: https://github.com/trampgeek/jobe/blob/master/README.md Installs essential packages for Jobe, including web server components, PHP, Node.js, Python3, and build tools. Additional packages like octave and fp-compiler are optional for specific language support. ```bash sudo apt-get --no-install-recommends install acl apache2 php \ libapache2-mod-php php-cli nodejs git libcgroup-dev \ php-mbstring nodejs python3 build-essential default-jdk \ octave php-intl python3-pip fp-compiler acl sudo sqlite3 ``` -------------------------------- ### Submit C 'Hello World' Program via REST API Source: https://github.com/trampgeek/jobe/blob/master/README.md Demonstrates how to submit a C 'Hello World' program to the Jobe server using a JSON payload via a POST request. It specifies the content type header and the target URL for the API endpoint. This example is useful for testing Jobe standalone or integrating it with clients. ```bash curl -d '{"run_spec": {"language_id": "c", "sourcefilename": "test.c", "sourcecode": "\n#include \n\nint main() {\n printf(\"Hello world\\n\");\n}\n"}}' -H "Content-type: application/json; charset-utf-8" localhost/jobe/index.php/restapi/runs ``` -------------------------------- ### Test Jobe Server Installation Source: https://github.com/trampgeek/jobe/blob/master/README.md Utilize the testsubmit.py script to verify the Jobe server's functionality. Run the script with the --host and --port arguments pointing to your Jobe server's address. The first run might be slow as it obtains language versions; subsequent runs are faster due to caching. This script helps confirm general correctness. ```python python3 testsubmit.py --host='jobe.somehow.somewhere' --port=80 ``` -------------------------------- ### C Language Task Configuration Example in PHP Source: https://github.com/trampgeek/jobe/blob/master/README.md Illustrates a specific task configuration for the C programming language in PHP. This would typically extend the abstract LanguageTask class and define C-specific compilation and execution commands. The example focuses on overriding default compile and run settings. ```php class C_Task extends LanguageTask { public function __construct() { parent::__construct(); // Set C-specific default compile and run options $this->compile_command = 'gcc -o %s %s'; // Example compile command $this->run_command = ['./%s']; // Example run command } public function getVersion() { return 'gcc --version'; // Example version check command } public function compile() { // Compile the source file, setting $this->executableFileName on success // or $this->cmpinfo on failure. } public function getRunCommand() { // Return the bash command to execute the compiled program. return array_merge([$this->executableFileName], $this->run_args); } } ``` -------------------------------- ### Deploy JobeInABox Docker Image Source: https://github.com/trampgeek/jobe/blob/master/README.md Launch the JobeInABox Docker image on a server to quickly set up a Jobe server. This command maps port 80 of the host to port 80 of the container, naming the container 'jobe'. It's recommended to increase memory and core count for production environments. After launching, verify the installation by accessing the /jobe/index.php/restapi/languages endpoint. ```shell sudo docker run -d -p 80:80 --name jobe trampgeek/jobeinabox ``` -------------------------------- ### Updating Jobe Installation with Purge Option Source: https://github.com/trampgeek/jobe/blob/master/README.md Illustrates the command to update an existing Jobe installation to a new version. It involves navigating to the Jobe directory and executing the install script with the '--purge' option. This command is typically run after performing a 'git pull' to fetch the latest code. ```bash sudo ./install --purge ``` -------------------------------- ### Submit C Code with Custom Resource Limits using Python Source: https://context7.com/trampgeek/jobe/llms.txt This Python example demonstrates submitting C code to Jobe with detailed resource constraints and compiler options. It showcases how to set CPU time, memory limits, disk usage, stream sizes, and process counts, along with custom compilation and linking arguments. ```python # C program with strict compiler warnings and limited resources c_code = """ #include #include int main() { double result = sqrt(144.0); printf("Square root of 144 is %.2f\n", result); return 0; } """ result = run_code( language_id='c', source_code=c_code, source_filename='math_demo.c', parameters={ 'compileargs': ['-Wall', '-Werror', '-std=c99'], 'linkargs': ['-lm'], # Link math library 'cputime': 2, # Max 2 seconds CPU 'memorylimit': 100, # Max 100 MB RAM 'disklimit': 10, # Max 10 MB disk writes 'streamsize': 1, # Max 1 MB output 'numprocs': 10 # Max 10 processes } ) if result['outcome'] == 15: print(f"Success: {result['stdout']}") elif result['outcome'] == 11: print(f"Compilation error:\n{result['cmpinfo']}") elif result['outcome'] == 13: print("Time limit exceeded") elif result['outcome'] == 17: print("Memory limit exceeded") ``` -------------------------------- ### Execute Java Programs with JVM Options (Python) Source: https://context7.com/trampgeek/jobe/llms.txt Submits Java code for execution, allowing custom JVM options and resource limits. The code must have a public class matching the source filename. Includes stdin example. ```python # Assuming run_code function is defined elsewhere java_code = """ import java.util.*; public class Calculator { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter two numbers: "); int a = scanner.nextInt(); int b = scanner.nextInt(); System.out.println("Sum: " + (a + b)); System.out.println("Product: " + (a * b)); } } """ result = run_code( language_id='java', source_code=java_code, source_filename='Calculator.java', # Must match public class name stdin='15 7', parameters={ 'interpreterargs': ['-Xrs', '-Xss8m', '-Xmx300m'], # JVM options 'cputime': 10, # Java needs more time for startup 'memorylimit': 1000 # Java needs more memory } ) # Assumes run_code is defined print(result['stdout']) ``` -------------------------------- ### GET /restapi/languages Source: https://context7.com/trampgeek/jobe/llms.txt Retrieves a list of all programming languages and their supported versions available on the Jobe server. ```APIDOC ## GET /restapi/languages ### Description Query all programming languages and their versions available on the server. ### Method GET ### Endpoint /restapi/languages ### Parameters None ### Request Example ```bash curl http://localhost/jobe/index.php/restapi/languages ``` ### Response #### Success Response (200) - **languages** (array of arrays) - A list where each inner array contains the language ID and its version string. #### Response Example ```json [ ["c", "gcc 9.3.0"], ["cpp", "g++ 9.3.0"], ["python3", "3.8.5"], ["java", "openjdk 11.0.11"], ["nodejs", "v10.19.0"], ["php", "7.4.3"], ["octave", "5.2.0"], ["pascal", "Free Pascal Compiler version 3.0.4"] ] ``` ``` -------------------------------- ### GET /jobe/index.php/restapi/languages Source: https://github.com/trampgeek/jobe/blob/master/README.md Retrieves a list of supported programming languages by the Jobe server. ```APIDOC ## GET /jobe/index.php/restapi/languages ### Description Retrieves a list of supported programming languages by the Jobe server. ### Method GET ### Endpoint /jobe/index.php/restapi/languages ### Response #### Success Response (200) - **languages** (array) - A list of supported language objects. - **id** (string) - The unique identifier for the language. - **name** (string) - The display name of the language. - **version** (string) - The version of the language compiler/interpreter. #### Response Example ```json [ { "id": "c", "name": "C", "version": "GCC 9.4.0" }, { "id": "python3", "name": "Python 3", "version": "3.8.10" } ] ``` ``` -------------------------------- ### Example JSON Payload for Code Execution Source: https://github.com/trampgeek/jobe/blob/master/README.md Provides the JSON structure required for the POST request payload when submitting code for execution via the Jobe REST API. It includes the 'run_spec' object, which defines the programming language, source filename, and the source code itself. This format is crucial for successful job submission. ```json { "run_spec": { "language_id": "c", "sourcefilename": "test.c", "sourcecode": "\n#include \n\nint main() {\n printf(\"Hello world\\n\");\n}\n" } } ``` -------------------------------- ### Get Supported Languages via REST API Source: https://context7.com/trampgeek/jobe/llms.txt This endpoint retrieves a list of all programming languages and their corresponding versions supported by the Jobe server. It's useful for determining which languages are available for code execution. The response is a JSON array of language-version pairs. ```bash # Using curl curl http://localhost/jobe/index.php/restapi/languages # Response example [ ["c", "gcc 9.3.0"], ["cpp", "g++ 9.3.0"], ["python3", "3.8.5"], ["java", "openjdk 11.0.11"], ["nodejs", "v10.19.0"], ["php", "7.4.3"], ["octave", "5.2.0"], ["pascal", "Free Pascal Compiler version 3.0.4"] ] ``` -------------------------------- ### Handle C Compilation Errors Source: https://context7.com/trampgeek/jobe/llms.txt This example shows how to handle compilation errors in C code. It intentionally includes syntax and type errors in the C code and then uses the 'run_code' function to compile it with specific compiler flags. The output checks the 'outcome' code and prints compilation error details if present. ```python # C code with intentional errors buggy_code = """ #include int main() { printf("Missing semicolon") // Syntax error int x = "string"; // Type error return 0; } """ result = run_code( language_id='c', source_code=buggy_code, source_filename='buggy.c', parameters={'compileargs': ['-Wall', '-Werror']} ) # Check outcome code OUTCOME_CODES = { 11: 'Compilation Error', 12: 'Runtime Error', 13: 'Time Limit Exceeded', 15: 'Success', 17: 'Memory Limit Exceeded', 19: 'Illegal System Call', 20: 'Internal Server Error', 21: 'Server Overload' } outcome = OUTCOME_CODES.get(result['outcome'], 'Unknown') print(f"Outcome: {outcome}") if result['outcome'] == 11: print(f"Compilation failed:\n{result['cmpinfo']}") ``` -------------------------------- ### Execute Python Code in Debug Mode Source: https://context7.com/trampgeek/jobe/llms.txt This example shows how to execute Python code with the debug mode enabled. The 'run_code' function is called with the 'debug' parameter set to True. This preserves the execution environment for post-mortem analysis. The output includes the run ID and standard output. ```python debug_code = """ with open('debug_output.txt', 'w') as f: f.write('Debug information\n') f.write('Process details here\n') print("Debug run completed") """ result = run_code( language_id='python3', source_code=debug_code, source_filename='debug_test.py', parameters={'debug': True} # Preserve run directory ) print(f"Run ID: {result['run_id']}") print(f"Output: {result['stdout']}") ``` -------------------------------- ### Enabling Apache Modules for SSL Proxy Source: https://github.com/trampgeek/jobe/blob/master/README.md Commands to enable necessary Apache modules (mod_proxy, mod_proxy_http, mod_ssl) required for setting up reverse proxy access over SSL. These modules must be enabled before restarting Apache. ```bash sudo a2enmod proxy sudo a2enmod proxy_http sudo a2enmod ssl ``` -------------------------------- ### Configure Apache Locale for UTF-8 Source: https://github.com/trampgeek/jobe/blob/master/README.md Modify the Apache envvars file to set the LANG environment variable to a UTF-8 compatible locale, such as C.UTF-8 or en_NZ.UTF-8. This is crucial for programs generating UTF-8 output to avoid UnicodeEncodeError. Ensure the chosen locale is installed on the server. After modification, restart Apache. ```shell export LANG=C.UTF-8 # or export LANG=en_NZ.UTF-8 ``` -------------------------------- ### Submit Python Code with Support Files (Python) Source: https://context7.com/trampgeek/jobe/llms.txt Executes Python code that depends on pre-uploaded support files. Uploads a helper module first, then submits the main script referencing it. Uses the `run_code` function with `file_list` parameter. ```python # Assuming upload_file and run_code functions are defined elsewhere # First, upload a helper module helper_code = """ def greet(name): return f"Hello, {name}! Welcome to Jobe." def calculate(a, b): return a * b + (a + b) """ upload_file('helper12345678', helper_code) # Assumes upload_file is defined # Now submit main program that imports the helper main_code = """ import helper print(helper.greet("World")) result = helper.calculate(10, 5) print(f"Calculation result: {result}") """ result = run_code( language_id='python3', source_code=main_code, source_filename='main.py', parameters={ 'file_list': [ ['helper12345678', 'helper.py'] # [file_id, local_filename] ] } ) # Assumes run_code is defined print(result['stdout']) ``` -------------------------------- ### Run All Application Tests (Windows) Source: https://github.com/trampgeek/jobe/blob/master/tests/README.md Executes the entire test suite for the CodeIgniter application on Windows systems. This command specifies the path to the PHPUnit executable within the vendor directory. ```console > vendor\bin\phpunit ``` -------------------------------- ### Run All Application Tests Source: https://github.com/trampgeek/jobe/blob/master/tests/README.md Executes the entire test suite for the CodeIgniter application from the project's root directory. This command assumes the PHPUnit executable is in the PATH or a symbolic link has been created. ```console > ./phpunit ``` -------------------------------- ### Create PHPUnit Symbolic Link (macOS/Linux) Source: https://github.com/trampgeek/jobe/blob/master/tests/README.md Creates a symbolic link for the PHPUnit executable, making it easier to run tests from the project's root directory on macOS and Linux systems. This avoids needing to specify the full path to the vendor binaries. ```console > ln -s ./vendor/bin/phpunit ./phpunit ``` -------------------------------- ### Execute PHP Scripts with Interpreter Args (Python) Source: https://context7.com/trampgeek/jobe/llms.txt Runs PHP code, allowing custom interpreter arguments and specifying CPU time limits. Demonstrates JSON encoding, pretty printing, and reading from standard input. ```python # Python client code # Assuming run_code function is defined elsewhere php_code = """ 'Alice', 'age' => 30, 'city' => 'Wonderland' ); echo "User Information:\n"; echo json_encode($data, JSON_PRETTY_PRINT); echo "\n"; // Read from stdin $input = trim(fgets(STDIN)); echo "You entered: $input\n"; ?>""" result = run_code( language_id='php', source_code=php_code, source_filename='info.php', stdin='test input', parameters={ 'interpreterargs': ['--no-php-ini'], # Don't load php.ini 'cputime': 3 } ) # Assumes run_code is defined print(result['stdout']) ``` -------------------------------- ### Submit Code for Execution using Python Source: https://context7.com/trampgeek/jobe/llms.txt This Python function demonstrates how to submit source code to the Jobe server for compilation and execution. It constructs a run specification, sends it as a JSON payload via HTTP POST, and handles the response. It allows specifying source code, filename, input, and optional resource parameters. ```python import json import http.client JOBE_SERVER = 'localhost' def run_code(language_id, source_code, source_filename, stdin='', parameters=None): """Submit code to Jobe for compilation and execution""" runspec = { 'language_id': language_id, 'sourcecode': source_code, 'sourcefilename': source_filename, 'input': stdin } if parameters: runspec['parameters'] = parameters payload = json.dumps({'run_spec': runspec}) headers = { 'Content-type': 'application/json; charset=utf-8', 'Accept': 'application/json' } connection = http.client.HTTPConnection(JOBE_SERVER) connection.request('POST', '/jobe/index.php/restapi/runs', payload, headers) response = connection.getresponse() if response.status == 200: result = json.loads(response.read().decode('utf8')) return result else: error_msg = response.read().decode('utf8') raise Exception(f"HTTP {response.status}: {error_msg}") # Example: Python Hello World result = run_code( language_id='python3', source_code='print("Hello, World!")\nprint(input("Name: "))', source_filename='hello.py', stdin='Alice', parameters={'cputime': 3, 'memorylimit': 500} ) print(f"Outcome: {result['outcome']}") # 15 = success print(f"Output: {result['stdout']}") # Hello, World!\nAlice print(f"Errors: {result['stderr']}") # Empty if no errors ``` -------------------------------- ### Execute Node.js Code with stdin Source: https://context7.com/trampgeek/jobe/llms.txt This snippet demonstrates executing Node.js code. It includes sample data, calculates sum and average, and reads from standard input. The 'run_code' function is used with specific parameters for interpreter arguments and CPU time. ```python js_code = """ const readline = require('readline'); const rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: false }); const numbers = [10, 25, 8, 42, 15]; const sum = numbers.reduce((acc, val) => acc + val, 0); const avg = sum / numbers.length; console.log(`Numbers: ${numbers.join(', ')}`); console.log(`Sum: ${sum}`); console.log(`Average: ${avg}`); rl.on('line', (line) => { console.log(`Received: ${line}`); }); """ result = run_code( language_id='nodejs', source_code=js_code, source_filename='stats.js', stdin='Hello from stdin', parameters={ 'interpreterargs': ['--use_strict'], 'cputime': 5 } ) print(result['stdout']) ``` -------------------------------- ### POST /restapi/runs Source: https://context7.com/trampgeek/jobe/llms.txt Submits source code to the Jobe server for compilation and execution. This endpoint can handle basic execution with optional standard input. ```APIDOC ## POST /restapi/runs ### Description Execute source code in a specified language with optional input and resource limits. ### Method POST ### Endpoint /restapi/runs ### Parameters #### Request Body - **run_spec** (object) - Required - Specifies the details of the code execution. - **language_id** (string) - Required - The ID of the programming language (e.g., 'python3', 'c'). - **sourcecode** (string) - Required - The source code to be compiled and executed. - **sourcefilename** (string) - Required - The filename for the source code. - **input** (string) - Optional - The standard input to be provided to the executed code. - **parameters** (object) - Optional - An object containing execution parameters and resource limits. ### Request Example ```json { "run_spec": { "language_id": "python3", "sourcecode": "print(\"Hello, World!\")\nprint(input(\"Name: \"))", "sourcefilename": "hello.py", "input": "Alice", "parameters": { "cputime": 3, "memorylimit": 500 } } } ``` ### Response #### Success Response (200) - **runid** (string) - A unique identifier for the execution request. - **outcome** (integer) - An integer code representing the execution outcome (e.g., 15 for success). - **stdout** (string) - The standard output from the executed code. - **stderr** (string) - The standard error output from the executed code. - **cmpinfo** (string) - Information about the compilation process, if applicable. #### Response Example ```json { "runid": "some_run_id", "outcome": 15, "stdout": "Hello, World!\nAlice", "stderr": "", "cmpinfo": "" } ``` ``` -------------------------------- ### POST /restapi/runs with Custom Resource Limits Source: https://context7.com/trampgeek/jobe/llms.txt Submits source code with detailed control over compilation arguments, linking options, and various resource limits like CPU time, memory, and disk usage. ```APIDOC ## POST /restapi/runs (Custom Limits) ### Description Execute code with fine-grained control over CPU time, memory, disk usage, and compiler options. ### Method POST ### Endpoint /restapi/runs ### Parameters #### Request Body - **run_spec** (object) - Required - Specifies the details of the code execution. - **language_id** (string) - Required - The ID of the programming language. - **sourcecode** (string) - Required - The source code to be compiled and executed. - **sourcefilename** (string) - Required - The filename for the source code. - **input** (string) - Optional - Standard input for the code. - **parameters** (object) - Optional - An object containing execution parameters and resource limits. - **compileargs** (array of strings) - Optional - Arguments passed to the compiler (e.g., '-Wall'). - **linkargs** (array of strings) - Optional - Arguments passed to the linker (e.g., '-lm'). - **cputime** (integer) - Optional - Maximum CPU time in seconds. - **memorylimit** (integer) - Optional - Maximum memory limit in MB. - **disklimit** (integer) - Optional - Maximum disk write limit in MB. - **streamsize** (integer) - Optional - Maximum output stream size in MB. - **numprocs** (integer) - Optional - Maximum number of processes allowed. ### Request Example ```python # C program with strict compiler warnings and limited resources c_code = """ #include #include int main() { double result = sqrt(144.0); printf(\"Square root of 144 is %.2f\\n\", result); return 0; } """ run_spec = { 'language_id': 'c', 'sourcecode': c_code, 'sourcefilename': 'math_demo.c', 'parameters': { 'compileargs': ['-Wall', '-Werror', '-std=c99'], 'linkargs': ['-lm'], # Link math library 'cputime': 2, # Max 2 seconds CPU 'memorylimit': 100, # Max 100 MB RAM 'disklimit': 10, # Max 10 MB disk writes 'streamsize': 1, # Max 1 MB output 'numprocs': 10 # Max 10 processes } } payload = json.dumps({'run_spec': run_spec}) # ... further request logic ... ``` ### Response #### Success Response (200) - **runid** (string) - Unique identifier for the execution. - **outcome** (integer) - Execution outcome code. - **stdout** (string) - Standard output. - **stderr** (string) - Standard error. - **cmpinfo** (string) - Compilation information. #### Response Example ```json { "runid": "another_run_id", "outcome": 15, // Example: success "stdout": "Square root of 144 is 12.00\n", "stderr": "", "cmpinfo": "" } ``` ``` -------------------------------- ### Configure UFW Firewall for Jobe Server Source: https://github.com/trampgeek/jobe/blob/master/README.md Secure the Jobe server by configuring the Uncomplicated Firewall (UFW). This involves setting default outgoing policies to reject, allowing incoming SSH on port 22, and permitting incoming TCP traffic on port 80 specifically from your Moodle server's IP address. Finally, enable the firewall. ```shell sudo apt install ufw sudo ufw default reject outgoing sudo ufw allow in 22/tcp sudo ufw allow in proto tcp to any port 80 from sudo ufw enable ``` -------------------------------- ### Python Function for API Key Authentication Source: https://context7.com/trampgeek/jobe/llms.txt This Python code defines a function 'run_code_with_auth' to execute code using the Jobe API with an API key for authentication. It constructs the request payload and headers, including the 'X-API-KEY'. The function handles successful responses (200) and rate limit exceptions (429). ```python def run_code_with_auth(language_id, source_code, source_filename, api_key): """Submit code with API key authentication""" runspec = { 'language_id': language_id, 'sourcecode': source_code, 'sourcefilename': source_filename } payload = json.dumps({'run_spec': runspec}) headers = { 'Content-type': 'application/json; charset=utf-8', 'Accept': 'application/json', 'X-API-KEY': api_key # API key for authentication } connection = http.client.HTTPConnection(JOBE_SERVER) connection.request('POST', '/jobe/index.php/restapi/runs', payload, headers) response = connection.getresponse() if response.status == 200: return json.loads(response.read().decode('utf8')) elif response.status == 429: raise Exception("Rate limit exceeded") else: raise Exception(f"HTTP {response.status}: {response.read().decode('utf8')}") # Use API key for rate-limited access API_KEY = '2AAA7A5415B4A9B394B54BF1D2E9D' result = run_code_with_auth('python3', 'print("Hello")', 'test.py', API_KEY) print(result['stdout']) ``` -------------------------------- ### POST /jobe/index.php/restapi/runs Source: https://github.com/trampgeek/jobe/blob/master/README.md Submits code to the Jobe server for execution. The request body must contain a 'run_spec' object specifying the language, source file name, and source code. ```APIDOC ## POST /jobe/index.php/restapi/runs ### Description Submits code to the Jobe server for execution. The request body must contain a 'run_spec' object specifying the language, source file name, and source code. ### Method POST ### Endpoint /jobe/index.php/restapi/runs ### Parameters #### Request Body - **run_spec** (object) - Required - An object containing the run specification. - **language_id** (string) - Required - The ID of the programming language. - **sourcefilename** (string) - Required - The name of the source file. - **sourcecode** (string) - Required - The actual source code to be executed. ### Request Example ```json { "run_spec": { "language_id": "c", "sourcefilename": "test.c", "sourcecode": "\n#include \n\nint main() {\n printf(\"Hello world\\n\");\n}" } } ``` ### Headers - **Content-type**: application/json; charset-utf-8 ### Response #### Success Response (200) - **result** (object) - The result of the code execution. - **errors** (string) - Any errors encountered during execution. - **warnings** (string) - Any warnings generated. - **time** (string) - The time taken for execution. - **memory** (integer) - The memory used during execution. #### Response Example ```json { "result": "Hello world\n", "errors": "", "warnings": "", "time": "0.01", "memory": 1024 } ``` ``` -------------------------------- ### Execute C++ Programs with Compiler Flags (Python) Source: https://context7.com/trampgeek/jobe/llms.txt Compiles and runs C++ code, allowing custom compiler flags and CPU time limits. Demonstrates sorting a vector and printing to standard output. Checks for success outcome (15) and provides error details. ```python # Assuming run_code function is defined elsewhere cpp_code = """ #include #include #include int main() { std::vector numbers = {5, 2, 8, 1, 9}; std::sort(numbers.begin(), numbers.end()); std::cout << "Sorted numbers: "; for (int n : numbers) { std::cout << n << " "; } std::cout << std::endl; return 0; } """ result = run_code( language_id='cpp', source_code=cpp_code, source_filename='sort_demo.cpp', parameters={ 'compileargs': ['-Wall', '-std=c++11', '-O2'], 'cputime': 5 } ) # Assumes run_code is defined if result['outcome'] == 15: print(f"Success:\n{result['stdout']}") else: print(f"Failed with outcome {result['outcome']}") if result['cmpinfo']: print(f"Compilation errors:\n{result['cmpinfo']}") if result['stderr']: print(f"Runtime errors:\n{result['stderr']}") ``` -------------------------------- ### Check Supported Languages via REST API Source: https://github.com/trampgeek/jobe/blob/master/README.md Shows how to verify the list of supported programming languages by Jobe. This is achieved by accessing the '/languages' endpoint of the REST API via a web browser. The expected output is a JSON array of language identifiers. ```bash http:///jobe/index.php/restapi/languages ``` -------------------------------- ### Python: Batch Execute Multiple Code Tests Source: https://context7.com/trampgeek/jobe/llms.txt This Python function efficiently executes a suite of test cases by submitting each to Jobe's `run_code` function. It handles different programming languages and captures execution results, including success status, standard output, and error messages. Dependencies include Jobe's `run_code` function, which is assumed to be available in the execution environment. ```python def batch_test_suite(test_cases): """Execute multiple test cases and return results""" results = [] for i, test in enumerate(test_cases): try: result = run_code( language_id=test['language'], source_code=test['code'], source_filename=test['filename'], stdin=test.get('input', ''), parameters=test.get('params') ) results.append({ 'test_id': i, 'passed': result['outcome'] == 15, 'output': result['stdout'], 'errors': result['stderr'] }) except Exception as e: results.append({ 'test_id': i, 'passed': False, 'error': str(e) }) return results # Define test suite tests = [ { 'language': 'python3', 'code': 'print(sum([1, 2, 3, 4, 5]))', 'filename': 'test1.py' }, { 'language': 'c', 'code': '#include \nint main(){printf("%d", 10+20); return 0;}', 'filename': 'test2.c' }, { 'language': 'nodejs', 'code': 'console.log([1,2,3].map(x => x*2));', 'filename': 'test3.js' } ] results = batch_test_suite(tests) for r in results: status = "PASS" if r['passed'] else "FAIL" print(f"Test {r['test_id']}: {status} - {r.get('output', r.get('error'))}") ``` -------------------------------- ### Generate Code Coverage Reports Source: https://github.com/trampgeek/jobe/blob/master/tests/README.md Generates both text-based and HTML code coverage reports for the application tests. This command also increases the memory limit to accommodate the coverage analysis. ```console > ./phpunit --colors --coverage-text=tests/coverage.txt --coverage-html=tests/coverage/ -d memory_limit=1024m ``` -------------------------------- ### Test Jobe Server Performance Source: https://github.com/trampgeek/jobe/blob/master/README.md Assess the performance of the Jobe server using the --perf command-line argument with testsubmit.py. This test measures the maximum burst and sustained submission rates. You can optionally specify a language (e.g., 'java') to test specific language performance. Warning: Do not run this on a live production server. ```python python3 testsubmit.py --perf --host='jobe.somehow.somewhere' # For specific language testing, e.g. Java: python3 testsubmit.py --perf --host='jobe.somehow.somewhere' java ``` -------------------------------- ### Configure Pylintrc File Source: https://github.com/trampgeek/jobe/blob/master/README.md Generates the default pylint configuration file. It includes two variations to accommodate different versions of pylint, one supporting the '--score' option and another for older versions that do not. ```bash pylint --reports=no --score=n --generate-rcfile > /etc/pylintrc ``` ```bash pylint --reports=no --generate-rcfile > /etc/pylintrc ``` -------------------------------- ### Default Compile and Interpreter Arguments for Languages Source: https://github.com/trampgeek/jobe/blob/master/README.md Defines the default 'compileargs' and 'interpreterargs' for various programming languages supported by Jobe. These arguments are used to configure the compilation or execution environment for a job. If empty, the global default is used. ```text language_id | language | compileargs | interpreterargs ------------|------------------------|-----------------------------------------|---------------------------------------------- c | C | ["-Wall", "-Werror", "-std=c99", "-x c"] | cpp | C++ | ["-Wall", "-Werror"] | python2 | Python2 | | ["-BESs"] python3 | Python3 | | ["-BE"] java | Java | | ["-Xrs", "-Xss8m", "-Xmx200m"] nodejs | JavaScript (nodejs) | | ["--use_strict"] octave | Octave (matlab variant) | | ["--norc", "--no-window-system", "--silent", "-H"] php | PHP | | ["--no-php-ini"] pascal | Free Pascal | ["-vew", "-Se"] | ```