• Stars
    star
    431
  • Rank 100,545 (Top 2 %)
  • Language
    Scala
  • License
    Apache License 2.0
  • Created almost 8 years ago
  • Updated 13 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An interactive playground for Scala

Github Build Status Join the chat

Demo

What is Scastie?

Scastie is sbt in your browser. You can:

  • Use any version of Scala
  • Use alternate backends such as Scala 3, Scala.js, Scala Native, and Typelevel Scala.
  • Use any publicly available library
  • Share Scala programs with anybody
  • Embed Scastie into your own website or library user guide.

How does it work?

When a user evaluates their code, the browser sends all its input to our server. We run your code in an isolated Java Virtual Machine on our servers. We integrated a Scaladex interface to allow you to search the Scala ecosystem and include any published Scala library in your project. You don’t need to remember what the latest version number of a particular library is anymore!

The output is streamed back to the user. A protocol will allow the client to interpret different events such as compiler errors, runtime exceptions, instrumentation, console output, etc.

We also support a worksheet mode, which feels much like a worksheet in an IDE. It lets a user write code as top-level expressions, without having to put your code inside of a class or object with a main method. Worksheet mode gives you two ways to interleave your results; on the one hand, when an expression is evaluated, you can see the value and type of the evaluated expression to the right of the code that you wrote. On the other hand, worksheet mode also makes it possible to do a kind of literate programming; that is, you may interleave code and HTML blocks much like in notebook environments such as iPython notebooks.

How do I embed Scastie?

You can embed a snippet with two different ways. You can embed a resource that was previously saved or you can convert code to a snippet.

Embedded Resources

Via HTML

Any saved resource can be embedded via a script tag by appending ".js" to its URL.

<!-- Annonymous Resource -->
<script src="https://scastie.scala-lang.org/xbrvky6fTjysG32zK6kzRQ.js"></script>

<!-- User's Resource -->
<script src="https://scastie.scala-lang.org/MasseGuillaume/CpO2s8v2Q1qGdO3vROYjfg.js"></script>
<script src="https://scastie.scala-lang.org/MasseGuillaume/CpO2s8v2Q1qGdO3vROYjfg/1.js"></script>

The embedding will be patched at the location of the script tag.

It's also possible to adjust the theme via the GET parameter theme. For example:

<script src="https://scastie.scala-lang.org/xbrvky6fTjysG32zK6kzRQ.js?theme=dark"></script>

The theme can be dark or light. The default value is light. It's also possible to customize the css.

Take a look at: https://codepen.io/olegych/pen/OJXVYoR

Via Javascript

<!-- Embedding Script -->
<div id="resource-1"></div>
<div id="resource-2"></div>
<div id="resource-3"></div>

<script src="https://scastie.scala-lang.org/embedded.js"></script>

<script>
window.addEventListener('load', function() {
  scastie.Embedded('#resource-1', { 
    base64UUID: "CJ8KTL98QAiWvoVUPI3kXg"
  });

  scastie.Embedded('#resource-2', {
    user: "MasseGuillaume",
    base64UUID: "33D4P3ysQCq2em2MRiv5sQ"
  });


  scastie.Embedded('#resource-3', {
    user: "MasseGuillaume",
    base64UUID: "33D4P3ysQCq2em2MRiv5sQ",
    update: 1
  });
});
</script>

Take a look at: https://codepen.io/MasseGuillaume/pen/aLpzvW

Converting Code Into Snippets

It's also possible to convert code into a snippet. The preferred way is to embed a snippet since it's output is cached. This mode will compile and run the snippet every time it's accessed.

<pre class="simple">
1 + 1
</pre>

<pre class="scala-js">
import org.scalajs.dom
import org.scalajs.dom.raw.HTMLImageElement

val img = dom.document.createElement("img").asInstanceOf[HTMLImageElement]
img.alt = "such dog" 
img.src = "https://goo.gl/a3Xr41"
img
</pre>

<pre class="full"></pre>

<!-- Embedding Script -->
<script src="https://scastie.scala-lang.org/embedded.js"></script>

<script>
window.addEventListener('load', function() {
  // DOM selector without build options
  scastie.Embedded('.simple');

  // with some options
  scastie.Embedded('.scala-js', { targetType: 'js' });

  // all option
  scastie.Embedded('.full', {
    theme: 'light', // default: 'light'; ('dark' or 'light')
    code: '1 + 1', // default: DOM node content
    isWorksheetMode: true,
    sbtConfig: 'libraryDependencies += "org.json4s" %% "json4s-native" % "3.5.2"',
    targetType: 'jvm',  // jvm, dotty, typelevel, js
    scalaVersion: '2.12.4'
  });

  // Setting Scala-Native targetType is not yet supported: https://github.com/scalacenter/scastie/issues/50
  // Setting Scala.js version is not yet supported: https://github.com/scalacenter/scastie/issues/228
});
</script>

Take a look at: https://codepen.io/MasseGuillaume/pen/OxbVzm

Try library

You can pass your library to Scastie like this:

https://scastie.scala-lang.org/try?g=com.typesafe.play&a=play&v=2.8.12&t=JVM&sv=2.13&o=playframework&r=playframework

The parameters are:

  • g - maven group id, required
  • a - maven artifact id, required
  • v - maven artifact version, required
  • t - target type, one of JVM|DOTTY|JS, required
  • sv - scala version, required, can be partial like 2.12
  • sjsv - scala.js version, optional
  • o - scaladex organization, required for proper display of your library in build settings
  • r - scaladex repository, required for proper display of your library in build settings
  • c - initial snippet code, optional

Configure snippet via query params

You can also pass full inputs json like this:

https://scastie.scala-lang.org/?inputs=%7B%0A%20%20%20%20%22_isWorksheetMode%22%20%3A%20true%2C%0A%20%20%20%20%22code%22%20%3A%20%221%20%2B%201%22%2C%0A%20%20%20%20%22target%22%20%3A%20%7B%0A%20%20%20%20%20%20%22scalaVersion%22%20%3A%20%223.1.1%22%2C%0A%20%20%20%20%20%20%22tpe%22%20%3A%20%22Scala3%22%0A%20%20%20%20%7D%2C%0A%20%20%20%20%22libraries%22%20%3A%20%5B%20%5D%2C%0A%20%20%20%20%22librariesFromList%22%20%3A%20%5B%20%5D%2C%0A%20%20%20%20%22sbtConfigExtra%22%20%3A%20%22scalacOptions%20%2B%2B%3D%20Seq%28%5Cn%20%20%5C%22-deprecation%5C%22%2C%5Cn%20%20%5C%22-encoding%5C%22%2C%20%5C%22UTF-8%5C%22%2C%5Cn%20%20%5C%22-feature%5C%22%2C%5Cn%20%20%5C%22-unchecked%5C%22%5Cn%29%22%2C%0A%20%20%20%20%22sbtPluginsConfigExtra%22%20%3A%20%22%22%2C%0A%20%20%20%20%22isShowingInUserProfile%22%20%3A%20true%0A%7D

See the format here:

Supports

Scastie is supported by the Scala Center

Scala Center Logo

with the help of Browser Stack for end-to-end testing

Browser Stack Logo

More Repositories

1

bloop

Bloop is a build server and CLI tool to compile, test and run Scala fast from any editor or build tool.
Scala
898
star
2

scalafix

Refactoring and linting tool for Scala
Scala
822
star
3

scala-3-migration-guide

The Scala 3 migration guide for everyone.
Scala
237
star
4

scalajs-bundler

Scala
235
star
5

scaladex

The Scala Package Index
Scala
197
star
6

sbt-missinglink

An sbt plugin for missinglink
Scala
133
star
7

scalac-profiling

Compilation profiling tool for Scala 2 projects
Scala
129
star
8

macros

Archived - Scala Macros
Scala
123
star
9

sprees

Scala Open Source Sprees: join us and learn how to contribute to open source!
111
star
10

scala3-migrate

A tool to help migrating from Scala 2 to Scala 3
Scala
102
star
11

advisoryboard

Scala Center Advisory Board planning
Scala
101
star
12

sbt-scalafix

sbt plugin for Scalafix
Scala
88
star
13

sbt-version-policy

Compatibility checks for your dependencies
Scala
81
star
14

sbt-dependency-submission

A Github Action to submit the dependency graph of an sbt build to the Dependency Submission API
Scala
58
star
15

scala-debug-adapter

Implementation of the Debug Adapter Protocol for Scala
Scala
56
star
16

scala-advent-of-code

Scala Center's solution of Advent of Code
Scala
54
star
17

tasty-query

Scala
47
star
18

GoogleSummerOfCode

Ideas list for GSoC 2024 mentored by Scala Center
38
star
19

course-management-tools

Course Management tools
Scala
28
star
20

classpath-shrinker

Scalac plugin to detect classpath entries that aren't directly used
Scala
28
star
21

sbtfix

Scalafix rewrites to migrate from sbt 0.13 to 1.0.
Scala
23
star
22

tooling-working-groups

Scala Tooling Working Groups
20
star
23

sbt-eviction-rules

An sbt plugin enhancing the evicted key.
Scala
19
star
24

scala-syntax

Scalameta pretty printer for better Scalafix refactorings
Scala
17
star
25

mix-macros-scala-2-and-3

Demo mixing definitions of macros for Scala 2 and 3 in one source file
Scala
17
star
26

GoogleSummerOfCode2021

16
star
27

simple-rockets-compiler

A Scala 3 DSL to compile programs for SimpleRockets 2
Scala
11
star
28

scalafix.g8

Giter8 template to implement custom rewrites
Scala
10
star
29

tasty-mima

TASTy Migration Manager
Scala
9
star
30

load-plugin

A sbt helper to programmatically load plugins
Scala
9
star
31

scaladex-contrib

pom => github
8
star
32

student-projects

The list of the available projects at the Scala Center for bachelor and master students.
8
star
33

tasty-reader-compat-testkit

Validating the TASTy Reader for Scala 2 with external projects that are published for Scala 3
Scala
8
star
34

gradle-bloop

Gradle plugin for Bloop
Scala
7
star
35

accessible-scala

SCP-016: Accessible Scala
Scala
7
star
36

effective-scala-slide-code

Scala
6
star
37

platform

The Scala Platform process and the tools around it.
Scala
6
star
38

library-example

Scala
6
star
39

ambassadors

This repo contains the materials for the Scala Center ambassadors to be used in their activities
5
star
40

sbt-tasty-mima

sbt plugin for TASTy-MiMa
Scala
4
star
41

sbt-scalafix-example

Example sbt build using scalafix
Scala
4
star
42

example-scalafix-rule

Scala
3
star
43

scaladex-index

bintray search meta, bintray poms, sonatype poms, users poms, live data
3
star
44

scalafix-named-literal-arguments

Example Scalafix rule to insert named arguments for boolean literals. This repo only exists for documentation purposes. The rule itself is not intended to be used
Scala
3
star
45

homebrew-bloop

Homebrew formula for Bloop
Ruby
2
star
46

bloop-maven-plugin

Maven Plugin for Bloop
Scala
2
star
47

versions

Scala
2
star
48

scala3-migration-course

A Scala 3 migration course based on sbt-scala3-migrate
Scala
1
star
49

intellij-scala-quickinstall

EXPERIMENT - Single-click install script for IntelliJ + Scala plugin
1
star
50

scaladex-small-index

1
star
51

sbt-github-dependency-graph

An sbt plugin to submit your dependencies to the Github Dependency Graph API.
Scala
1
star
52

accessible-scala-demo

CSS
1
star
53

scalacenter.github.io

HTML
1
star
54

bloop-config

Bloop configuration library
Scala
1
star
55

snake-workshop

Workshop for Scalabase 2021
Scala
1
star