Coderpad logo color Features Pricing Login Register

Languages

CoderPad supports a wide variety of programming languages. Some of them have quirks and quite a few have supplementary libraries that you might want to use. Click on the language you're interested in, or scroll through the list!

Running GCC 6.2 - Autocomplete is enabled

The gcc compiler is invoked with the following args:

gcc -std=c11 -Wall -pthread -lm

Which stand for:

You should define an int main() entrypoint.

Running Clojure 1.9 - Autocomplete is not available

No extra information available. It probably just works!

CoffeeScript

Running CoffeeScript 1.10 - Autocomplete is not available

CoffeeScript in CoderPad just runs on top of the JavaScript environment, the only difference being that we do not run CoffeeScript with the --harmony flag.

Information about the JS environment is reproduced below:

We provide a highly interactive REPL with allows access to your runtime variables. If there were no errors, you will have a REPL with access to all of the global variables and functions defined in your script.

We run NodeJS with the --harmony flag on, which gives you access to most of the features in the upcoming JavaScript ES6 spec. For a complete description of which ES6 features are available, check out the Node compatibility table. Your code is also run for you in strict mode by default, which will enable most ES6 features to work without configuration on your part.

We also have an array of interesting npm packages available for your use:

Here’s a quick example of how to use sinon and chai:

  var chai = require('chai')
  var sinon = require('sinon')
  var sinonChai = require('sinon-chai')

  chai.should()
  chai.use(sinonChai)

  function hello(name, cb) {
    cb('hello ' + name)
  }

  var cb = sinon.spy()
  hello('world', cb)
  cb.should.have.been.calledWith('this test should fail')

as well as mocha:

  var Mocha = require('mocha')
  var assert = require('assert')
  var mocha = new Mocha()

  // Bit of a hack, sorry!
  mocha.suite.emit('pre-require', this, 'solution', mocha)

  describe('Test suite', function() {
    it('should work', function() {
      assert(true)
    })
  })

  mocha.run()
Running GCC 6.2 - Autocomplete is enabled

Boost is provided, with most of its header-only libraries working straight out of the box. Of its statically compiled components, we link to DateTime, Regex, System, Thread, and Timer. If you need more than those, please let us know!

The gcc compiler is invoked with the following args:

g++ -Wall -std=c++14 -pthread \
-lboost_date_time -lboost_regex -lboost_system -lboost_thread -lboost_timer -lboost_filesystem \
-lssl -lcrypto

Which stand for:

You have access to the STL libraries as long as using namespace std; is present.

You should define an int main() entrypoint.

If you’d like to write some tests against your code, you can do so using the Catch C++ testing library. Catch is a single-header library and very easy to get started with. To use it on CoderPad, simply define a macro and include the header like so:

#define CATCH_CONFIG_MAIN
#include "catch.hpp"

unsigned int Factorial( unsigned int number ) {
    return number <= 1 ? number : Factorial(number-1)*number;
}

TEST_CASE( "Factorials are computed", "[factorial]" ) {
    REQUIRE( Factorial(1) == 1 );
    REQUIRE( Factorial(2) == 2 );
    REQUIRE( Factorial(3) == 6 );
    REQUIRE( Factorial(10) == 3628800 );
}

If you do so, you should not define your own main method. You can also read more about Catch’s macros for testing.

Running .NET Core 2.0 - Autocomplete is enabled

Our C# environment runs on Microsoft’s cross-platform .NET Core runtime. The System.Json assembly is linked.

You should define a static void Main on a class named Solution.

Tests can be written in NUnit as follows:

using NUnit.Framework;
using NUnitLite;
using System;
using System.Reflection;

public class Runner {
    public static int Main(string[] args) {
        return new AutoRun(Assembly.GetCallingAssembly()).Execute(new String[] {"--labels=All"});
    }

    [TestFixture]
    public class Foo {
        [Test]
        public void TestSomething() {
            Assert.AreEqual(2,2);
        }
    }
}

Your code is compiled and run with debug mode enabled.

Running Elixir 1.4 - Autocomplete is not available

No extra information available. It probably just works!

Running Erlang OTP 19.0 - Autocomplete is not available

You should define the module as “solution” and define and export a method named “start” on it, like so:

-module(solution).
-export([start/0]).

start() ->
  io:format("Hello, World").
Running .NET Core 2.0 - Autocomplete is not available

Our F# environment runs on Microsoft’s cross-platform .NET Core runtime.

Your code is compiled and run with debug mode enabled.

You can run NUnit tests with the following code:

module Solution

open NUnitLite
open NUnit.Framework

open System
open System.Reflection


[<Test>]
let test1() = Assert.Pass()

[<Test>]
let test2() = Assert.Fail()

[<EntryPoint>]
let main argv =
    printfn "Hello, World!"
    (new AutoRun(Assembly.GetCallingAssembly())).Execute( [| "--labels=All" |])
Running Go 1.9 - Autocomplete is not available

You should declare a func main() in a package “main”, like so:

package main

import "fmt"

func main() {
  fmt.Println("Hello, world")
}
Running GHC 8.2 - Autocomplete is not available

Your code is run with runghc solution.hs. Your code runs in interpreted mode, so you don’t need a special entrypoint or anything.

We install a variety of packages in the Haskell environment. The output of cabal list --installed --simple is below:

Running HotSpot 1.8.0_91 (JDK 8) - Autocomplete is enabled

You should define a public class named Solution with a public static void main. Your code is compiled with -Xlint (linting) and run with -ea (assertions enabled).

A few libraries are included for your convenience, and are available on the classpath with no additional work from you. Simply import and fire away:

The google code project page has some useful examples.

Has a bunch of useful stuff like date parsing. The import prefix is org.apache.commons.lang3, so you can perform imports by writing import org.apache.commons.lang3.ArrayUtils.

  import org.junit.*;
  import org.junit.runner.*;

  public class Solution {
    @Test
    public void testNoop() {
      Assert.assertTrue(true);
    }

    public static void main(String[] args) {
      JUnitCore.main("Solution");
    }
  }

Stack traces originating from JUnit errors are trimmed for brevity.

In the future we may auto-detect the existence of @Test annotations, so stay tuned.

Running NodeJS v8 - Autocomplete is enabled

We provide a highly interactive REPL with allows access to your runtime variables. If there were no errors, you will have a REPL with access to all of the global variables and functions defined in your script.

We run NodeJS with the --harmony flag on, which gives you access to most of the features in the upcoming JavaScript ES6 spec. For a complete description of which ES6 features are available, check out the Node compatibility table. Your code is also run for you in strict mode by default, which will enable most ES6 features to work without configuration on your part.

We also have an array of interesting npm packages available for your use:

Here’s a quick example of how to use sinon and chai:

  var chai = require('chai')
  var sinon = require('sinon')
  var sinonChai = require('sinon-chai')

  chai.should()
  chai.use(sinonChai)

  function hello(name, cb) {
    cb('hello ' + name)
  }

  var cb = sinon.spy()
  hello('world', cb)
  cb.should.have.been.calledWith('this test should fail')

as well as mocha:

  var Mocha = require('mocha')
  var assert = require('assert')
  var mocha = new Mocha()

  // Bit of a hack, sorry!
  mocha.suite.emit('pre-require', this, 'solution', mocha)

  describe('Test suite', function() {
    it('should work', function() {
      assert(true)
    })
  })

  mocha.run()
Running Kotlin 1.1 - Autocomplete is not available

No extra information available. It probably just works!

Running marked.js 0.3 - Autocomplete is not available

No extra information available. It probably just works!

Running MySQL Server 5.7 - Autocomplete is not available

MySQL mode spins up a MySQL server with a default database with some sample data in it. The schema of the default database looks like:

employees                             projects
+---------------+---------+           +---------------+---------+
| id            | int     |<----+  +->| id            | int     |
| first_name    | varchar |     |  |  | title         | varchar |
| last_name     | varchar |     |  |  | start_date    | date    |
| salary        | int     |     |  |  | end_date      | date    |
| department_id | int     |--+  |  |  | budget        | int     |
+---------------+---------+  |  |  |  +---------------+---------+
                             |  |  |
departments                  |  |  |  employees_projects
+---------------+---------+  |  |  |  +---------------+---------+
| id            | int     |<-+  |  +--| project_id    | int     |
| name          | varchar |     +-----| employee_id   | int     |
+---------------+---------+           +---------------+---------+

The database is reset when the “Reset” button is clicked, or the pad switches to another language.

Objective-C

Running Clang 3.9 with GNUstep and libobjc2 - Autocomplete is not available

While we don’t run Objective-C on native OSX, we do run it in the latest clang with objc. This lets you include classes like NSString and so forth largely as you normally would.

Your code is compiled with

clang `gnustep-config --objc-flags` `gnustep-config --objc-libs` \
  -fobjc-arc -fobjc-nonfragile-abi -lobjc -lgnustep-base -ldispatch

which activates automatic reference counting and the nonfragile ABI.

You should define an int main() function.

To use the linked implementation of Apple’s Grand Central Dispatch, call the appropriate dispatch methods:

#import <stdio.h>
#include <dispatch/dispatch.h>

static void timer_did_fire(void *context) {
    printf("Strawberry fields...\n");
}

int main (int argc, const char * argv[])
{
    dispatch_source_t timer = dispatch_source_create(
        DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_main_queue());

    dispatch_source_set_event_handler_f(timer, timer_did_fire);
    dispatch_source_set_timer(timer, DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC,
                              0.5 * NSEC_PER_SEC);
    dispatch_resume(timer);
    dispatch_main();
}
Running OCaml 4.02 - Autocomplete is not available

Our OCaml environment compiles your code with ocamlopt using all the default options. If there are no compilation errors it will then execute the resulting binary.

We also provide the standard OCaml toplevel when your code isn’t being compiled or executed. This is paired with rlwrap to give you access to your history using the up and down arrows.

Running Perl 5.18 - Autocomplete is not available

Our Perl environment ships with the following packages:

Running Zend PHP 7.0 - Autocomplete is not available

You must wrap your code in <?php and ?> tags. Text outside of those tags will output to stdout without processing as PHP.

PHP’s mcrypt library is also installed.

Running - Autocomplete is not available

No extra information available. It probably just works!

Running CPython 2.7 - Autocomplete is enabled

The Python environment is augmented with a few REPL features as well as some helpful libraries.

The REPL uses IPython to provide a REPL with history, highlighting, and autocomplete. Additionally, whenever you run scripts in CoderPad’s editor, the REPL will deposit you at the exact line and state of any exceptions. If there were no errors, you will have a REPL with access to all of the variables and functions defined in your script.

The libraries included and ready for importing are:

Testing

We’ve got a few ways you can test your Python code in CoderPad:

  1. The excellent unittest library that ships with Python by default. Here’s a quick example:
   import unittest

   class TestStringMethods(unittest.TestCase):
       def test_upper(self):
           self.assertEqual('foo'.upper(), 'FOO')

       def test_isupper(self):
           self.assertTrue('FOO'.isupper())
           self.assertFalse('Foo'.isupper())

       def test_split(self):
           s = 'hello world'
           self.assertEqual(s.split(), ['hello', 'world'])
           # s.split should throw when the separator is not a string
           with self.assertRaises(TypeError):
               s.split(2)

   unittest.main(exit=False)
  1. The versatile pytest. The above snippet of code would look like the following when written for pytest:
   import pytest

   def test_upper():
       assert 'foo'.upper() == 'FOO'

   def test_isupper():
       assert 'FOO'.isupper()
       assert not 'Foo'.isupper()

   def test_split():
       s = 'hello world'
       assert s.split() == ['hello', 'world']
       # s.split should throw when the separator is not a string
       with pytest.raises(TypeError):
           s.split(2)

   pytest.main()
  1. mock is also available if you need to stub out some behavior. Here’s a quick usage example:
   from mock import Mock

   mock = Mock()
   mock.method(1, 2, 3)
   mock.method.assert_called_with('this should break')

mock can of course be combined with unittest and pytest for even more fun.

  1. hypothesis is available for property-based testing in Python. You can read more about it on their website, but here’s a stubbed example of how you might test that an encoding and decoding function both work:
   from hypothesis import given
   from hypothesis.strategies import text

   def encode(string):
       # return encoded string

   def decode(string):
       # return decoded string

   @given(text())
   def test_decode_inverts_encode(s):
       assert decode(encode(s)) == s

   test_decode_inverts_encode()

Calling test_decode_inverts_encode() fires up Hypothesis and tries to find an input that breaks your code.

Running CPython 3.6 - Autocomplete is enabled

Python 3 in CoderPad is generally identical to the Python 2.x environment.

One small difference is that mock is available in Python 3 in the stdlib, as unittest.mock.

Information about the Python 2.x environment is reproduced below:

The Python environment is augmented with a few REPL features as well as some helpful libraries.

The REPL uses IPython to provide a REPL with history, highlighting, and autocomplete. Additionally, whenever you run scripts in CoderPad’s editor, the REPL will deposit you at the exact line and state of any exceptions. If there were no errors, you will have a REPL with access to all of the variables and functions defined in your script.

The libraries included and ready for importing are:

Testing

We’ve got a few ways you can test your Python code in CoderPad:

  1. The excellent unittest library that ships with Python by default. Here’s a quick example:
   import unittest

   class TestStringMethods(unittest.TestCase):
       def test_upper(self):
           self.assertEqual('foo'.upper(), 'FOO')

       def test_isupper(self):
           self.assertTrue('FOO'.isupper())
           self.assertFalse('Foo'.isupper())

       def test_split(self):
           s = 'hello world'
           self.assertEqual(s.split(), ['hello', 'world'])
           # s.split should throw when the separator is not a string
           with self.assertRaises(TypeError):
               s.split(2)

   unittest.main(exit=False)
  1. The versatile pytest. The above snippet of code would look like the following when written for pytest:
   import pytest

   def test_upper():
       assert 'foo'.upper() == 'FOO'

   def test_isupper():
       assert 'FOO'.isupper()
       assert not 'Foo'.isupper()

   def test_split():
       s = 'hello world'
       assert s.split() == ['hello', 'world']
       # s.split should throw when the separator is not a string
       with pytest.raises(TypeError):
           s.split(2)

   pytest.main()
  1. mock is also available if you need to stub out some behavior. Here’s a quick usage example:
   from mock import Mock

   mock = Mock()
   mock.method(1, 2, 3)
   mock.method.assert_called_with('this should break')

mock can of course be combined with unittest and pytest for even more fun.

  1. hypothesis is available for property-based testing in Python. You can read more about it on their website, but here’s a stubbed example of how you might test that an encoding and decoding function both work:
   from hypothesis import given
   from hypothesis.strategies import text

   def encode(string):
       # return encoded string

   def decode(string):
       # return decoded string

   @given(text())
   def test_decode_inverts_encode(s):
       assert decode(encode(s)) == s

   test_decode_inverts_encode()

Calling test_decode_inverts_encode() fires up Hypothesis and tries to find an input that breaks your code.

Running R 3.3 - Autocomplete is not available

Our R environment ships with the caret, data.table, forecast, mlr, plyr, reshape2, tidyverse, xts, and zoo packages installed. No graphical output is provided at this time, but all your standard R computations should work normally.

Additionally, it should be noted that tidyverse installs quite a few useful packages too (like tidyr and readr): http://tidyverse.org.

Running MRI 2.4 - Autocomplete is enabled

The Ruby environment is augmented with a few REPL features as well as some helpful libraries.

The REPL uses Pry to provide a REPL with history, highlighting, and autocomplete. Additionally, whenever you run scripts in CoderPad’s editor, the REPL will deposit you at the exact line and state of any exceptions. If there were no errors, you will have a REPL with access to all of the variables and functions defined in your script.

The libraries included and ready for requireing are:

  require 'minitest/autorun'

  class Dog
    def talk!
      'BARK'
    end
  end

  describe Dog do
    it 'must bark when spoken to' do
      Dog.new.talk!.must_equal 'BARK'
    end
  end
  require 'rspec/autorun'

  class Dog
    def talk!
      'BARK'
    end
  end

  RSpec.describe Dog do
    it 'barks when spoken to' do
      expect(Dog.new.talk!).to eq('BARK')
    end
  end
Running Rust 1.18 - Autocomplete is not available

No extra information available. It probably just works!

Running Scala 2.12 - Autocomplete is not available

You should define an object named Solution that extends App, like so:

object Solution extends App {
  for (i <- 0 until 5) println("Hello, world!")
}

Alternatively, you can forego using the App trait helper and define main yourself:

object Solution {
  def main(args: Array[String]) {
    println("Hello, world!")
  }
}

We include the Scala testing libraries ScalaCheck and ScalaTest for your convenience. Here’s a quick example of ussing ScalaTest driven by ScalaCheck generators:

import org.scalatest.prop.GeneratorDrivenPropertyChecks
import org.scalatest.{FreeSpec, Matchers}

class Testable extends FreeSpec
    with Matchers
    with GeneratorDrivenPropertyChecks {

  def f (x: Int) = Math abs x

  "f (x) should be >= 0" in forAll (
    (x: Int) => f (x) should be >= 0
  )

  "f (x) should be >= 0 (sometimes!)" in forAll (
    (x: Int) => whenever (x != Int.MinValue) (f (x) should be >= 0)
  )
}

object Solution extends App {
  new Testable().execute()
}

Here’s a quick rundown of the Scala libraries we have installed:

libraryDependencies ++= Seq (
  "com.chuusai"     %% "shapeless"                    % "2.3.2",
  "org.scalacheck"  %% "scalacheck"                   % "1.13.4",
  "org.scalactic"   %% "scalactic"                    % "3.0.1",
  "org.scalamock"   %% "scalamock-scalatest-support"  % "3.5.0",
  "org.scalatest"   %% "scalatest"                    % "3.0.1",
  "org.scalaz"      %% "scalaz-core"                  % "7.2.12",
  "org.typelevel"   %% "cats"                         % "0.9.0"
)

Additionally, these Java libraries are available. Simply import and fire away:

The google code project page has some useful examples.

  import org.junit.Test
  import org.junit.runner.JUnitCore
  import org.junit.Assert

  class TestClass {
    @Test def testNoop() {
      Assert.assertTrue(true)
    }
  }

  object Solution {
    def main(args: Array[String]) {
      JUnitCore.main("TestClass")
    }
  }
Running Swift 4 - Autocomplete is not available

We’re using Apple’s recently open sourced Swift implementation, on a recent Linux snapshot.

Syntax highlighting might be a bit wonky, so please point out any issues via email! We also plan to add REPL support soon.

Visual Basic

Running .NET Core 2.0 - Autocomplete is not available

Our Visual Basic environment runs on Microsoft’s cross-platform .NET Core runtime.

Your code is compiled and run with debug mode enabled.

You can run NUnit tests w/ the following code:

Imports NUnit.Framework
Imports NUnitLite
Imports System
Imports System.Reflection

<TestFixture()>
Public Class TestGroup
    <Test()>
    Public Sub BasicTest()
        Assert.AreEqual(2,2)
    End Sub
End Class

Module Solution
    Sub Main()
        Dim autorunner As New AutoRun(Assembly.GetCallingAssembly())
        autorunner.execute({"--noresult"})
    End Sub
End Module

Are there any libraries or settings we missed? Feel free to email us with suggestions!