Code Monkey home page Code Monkey logo

compilex's Introduction

compilex

[![NPM version](https://badge.fury.io/js/compilex.svg)](http://badge.fury.io/js/compilex) [![Build Status](https://travis-ci.org/scriptnull/compilex.svg?branch=master)](https://travis-ci.org/scriptnull/compilex) [![Dependency Status](https://david-dm.org/scriptnull/compilex.svg)](https://david-dm.org/scriptnull/compilex) [![Download Status](http://img.shields.io/npm/dm/compilex.svg)](https://www.npmjs.org/package/compilex) [![License](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/scriptnull/compilex/blob/master/License.md) [![Gitter](https://badges.gitter.im/JoinChat.svg)](https://gitter.im/scriptnull/compilex?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

compilex is a node.js library which is used to build online code compiler/interpreter websites and webservices.

You can compile and respond back outputs for all the languages that can be compiled by the server.

Some of the online code compiling/judging websites are

Using compilex , you can built sites and services like the above said examples.

compilex is an experimental package , however , if you want to build your site quickly , you can prefer to use the API of the above said services. Node.js Wrapper modules for those API are available. You can try HackerRank SDK and HackerEarth SDK.

Typical scenarios in which you have to go with wrapper modules instead of compilex are

  • If you don't want to have the pain of configuring compilers on your server.
  • If you don't have the access to the VM on which your site is hosted
  • If you feel tired of configuring compilex over SSH.

Why compilex ?

  1. compilex can detect infinite loops in the users program .
  2. It can compile programs by getting input from STDIN.
  3. Generates statistics for the administrator.

Supported Languages

compilex is currently in initial development stage . As the library grows , so does the list here .

Language Support
C
C++
Java
Python
C#
Visual Basic

Work Flow

  1. Get the program as input from the client as a request
  2. Use compilex modules to compile the program
  3. Get the output and errors in json and string formats
  4. Respond the output to the client

Setting Up Compilers

Inorder to compile any programming language , you need to first have the compiler for that programming language in the server machine.

C and C++

  1. Installation :You need GCC compiler that can compile programs from your cmd/terminal
    • Windows - You can get MinGw .
    • Linux - Most of the linux versions are installed with gcc by default. If you haven't got , Take a look at Installing GCC .
  2. Testing the Environment :After installing , set your environment variables for accessing the GCC command lines from any directory
    • Windows - create a c file in a directory , execute
      g++ filename.c -o output.exe
      output.exe

      then you will get the output of the program
    • Linux - create a c file in a directory , execute
      gcc filename.c -o output.out
      ./output.out

      then you will get the output of the program

Java

  1. Installion : You need JDK ( Java Development Kit ) to compile Java programs.Click here to download JDK for various platforms.
  2. Testing the Environment :After installing , set your environment variables for accessing the javac command lines from any directory
    • Create a Java file named Main.java with main function
      javac Main.java
      java Main

      then you will get the output of the program.

Python

  1. Installation : You can get and install Python from here
  2. Testing the Environment :After installing , set your environment variables for accessing python command lines from any directory
    • Create a python file hello.py and execute
      python hello.py
      then you will get the output of the program.

C# and VB

  1. Installation : You can have the idea of accessing C# compiler from here . This step also adds VB compiler to the scope automatically as csc and vbc are located in the same directory
  2. Testing the Environment :After installing , set your environment variables for accessing C# and VB command lines from any directory
    • Create a C# or VB file Hello.cs or Hello.vb and execute
      csc Hello.cs
      Hello.exe

      or
      vbc Hello.vb
      Hello.exe

      then you will get the output of the program.

NOTE : Video demos for setting up the compilers and using compilex will be availble soon.

Documentation

1)Require compilex
```javascript var compiler = require('compilex'); var options = {stats : true}; //prints stats on console compiler.init(options); ``` init() creates a folder named temp in your project directory which is used for storage purpose. Before using other methods , make sure to call init() method.
2)C and C++
```javascript //if windows var envData = { OS : "windows" , cmd : "g++"}; // (uses g++ command to compile ) //else var envData = { OS : "linux" , cmd : "gcc" }; // ( uses gcc command to compile ) compiler.compileCPP(envData , code , function (data) { res.send(data); //data.error = error message //data.output = output value });
//res is the response object

<h5>3)C and C++ with inputs </h5>
```javascript
    //if windows  
    var envData = { OS : "windows" , cmd : "g++"}; // (uses g++ command to compile )
    //else
    var envData = { OS : "linux" , cmd : "gcc" }; // ( uses gcc command to compile )
    compiler.compileCPPWithInput(envData , code , input , function (data) {
        res.send(data);
    });
4)Java
```javascript //if windows var envData = { OS : "windows"}; //else var envData = { OS : "linux" }; // (Support for Linux in Next version) compiler.compileJava( envData , code , function(data){ res.send(data); }); ```
5)Java with inputs
```javascript //if windows var envData = { OS : "windows"}; //else var envData = { OS : "linux" }; // (Support for Linux in Next version) compiler.compileJavaWithInput( envData , code , input , function(data){ res.send(data); }); ```
6)Python
```javascript //if windows var envData = { OS : "windows"}; //else var envData = { OS : "linux" }; compiler.compilePython( envData , code , function(data){ res.send(data); }); ```
7)Python with inputs
```javascript //if windows var envData = { OS : "windows"}; //else var envData = { OS : "linux" }; compiler.compilePythonWithInput( envData , code , input , function(data){ res.send(data); }); ```
8)C#
```javascript var envData = { OS : "windows"}; //mono modules for linux is not included till now compiler.compileCS( envData , code , function(data){ res.send(data); }); ```
9)C# with inputs
```javascript
var envData = { OS : "windows"}; 
//mono modules for linux is not included till now
compiler.compileCSWithInput( envData , code , input ,  function(data){
    res.send(data);        
});
<h5>10)Visual Basic</h5>
```javascript
    var envData = { OS : "windows"}; 
    compiler.compileVB( envData , code , function(data){
        res.send(data);
    });    
11)Visual Basic with inputs
```javascript
var envData = { OS : "windows"}; 
compiler.compileVBWithInput( envData , code , input ,  function(data){
    res.send(data);        
});

<h5>12)Memory Management </h5>
All the temporary files ( source code and executables ) are created in your temp directory.
flush and flushSync helps you to free the memory by deleting the temporary files.
```javascript
    compiler.flush(function(){
    console.log('All temporary files flushed !'); 
    });

Synchronous version of flush

    compiler.flushSync();
13)Statistical Data
Getting statistics about your compilex server has been taken care. fullStat returns json data about your server. ```javascript compiler.fullStat(function(data){ res.send(data); }); ```
1)options : (windows only c/c++ only)
timeout: number of milliseconds to wait before killing the compiled program ```javascript //compile and execute the file and kill it after 1 second if it still running var envData = { OS : "linux" , cmd : "gcc" ,options: {timeout:1000 } }; compiler.compileCPP(envData , code , function (data) { res.send(data); //data.error = error message //data.output = output value }); ```

Examples

You can find examples here.The examples are downloaded everytime you download compilex via npm. you can begin with editing CSS and publish your site in minutes. Here is the screenshot of the demo.

alt text

License

All the contents in this repository are released under the MIT License .

Support via Gittip

compilex's People

Contributors

scriptnull avatar xnio94 avatar

Watchers

James Cloos avatar Badr bellaj avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.