Git Product home page Git Product logo

scastie's Introduction

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

scastie's People

Contributors

allanrenucci avatar anatoliykmetyuk avatar arminio avatar dependabot[bot] avatar dimart avatar dominv avatar duhemm avatar giabao avatar jacoby6000 avatar japgolly avatar jiminhsieh avatar julienrf avatar kacperfkorban avatar kordyjan avatar masseguillaume avatar michalbogacz avatar mouslihabdelhakim avatar olegych avatar opensas avatar rochala avatar ronaldmarske avatar rorygraves avatar scala-center-steward[bot] avatar scala-steward avatar sethtisue avatar sjrd avatar smarter avatar som-snytt avatar vincenzobaz avatar xuwei-k avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

scastie's Issues

Save, Update, Fork & List

For example in https://jsfiddle.net/

An anonymous user

An authenticated user

Additions

  • we could also add an edit function where you would mutate the resource (for fixing bugs). (/MasseGuillaume/n93tzqv0 => mutates /MasseGuillaume/n93tzqv0)

Help dialog

  • The CSS is not the same when it is shown the first time and when you evaluate help in the worksheet mode
  • The dialog do not show up again whereas I didn’t check the “don’t show again” box
  • The “worksheet mode” section is empty

Restart crashed sbt instances

I experience the following st output on very small snippets:

java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Metaspace
	at java.util.concurrent.FutureTask.report(FutureTask.java:122)
	at java.util.concurrent.FutureTask.get(FutureTask.java:192)
	at sbt.ConcurrentRestrictions$$anon$4.take(ConcurrentRestrictions.scala:188)
	at sbt.Execute.next$1(Execute.scala:85)
	at sbt.Execute.processAll(Execute.scala:88)
	at sbt.Execute.runKeep(Execute.scala:68)
	at sbt.EvaluateTask$.liftedTree1$1(EvaluateTask.scala:359)
	at sbt.EvaluateTask$.run$1(EvaluateTask.scala:358)
	at sbt.EvaluateTask$.runTask(EvaluateTask.scala:378)
	at sbt.Aggregation$$anonfun$3.apply(Aggregation.scala:69)
	at sbt.Aggregation$$anonfun$3.apply(Aggregation.scala:67)
	at sbt.EvaluateTask$.withStreams(EvaluateTask.scala:314)
	at sbt.Aggregation$.timedRun(Aggregation.scala:67)
	at sbt.Aggregation$.runTasks(Aggregation.scala:76)
	at sbt.Aggregation$$anonfun$applyDynamicTasks$1.apply(Aggregation.scala:117)
	at sbt.Aggregation$$anonfun$applyDynamicTasks$1.apply(Aggregation.scala:115)
	at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:61)
	at sbt.Command$$anonfun$applyEffect$2$$anonfun$apply$3.apply(Command.scala:61)
	at sbt.Act$$anonfun$sbt$Act$$actParser0$1$$anonfun$sbt$Act$$anonfun$$evaluate$1$1$$anonfun$apply$10.apply(Act.scala:259)
	at sbt.Act$$anonfun$sbt$Act$$actParser0$1$$anonfun$sbt$Act$$anonfun$$evaluate$1$1$$anonfun$apply$10.apply(Act.scala:256)
	at sbt.Command$.process(Command.scala:93)
	at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:96)
	at sbt.MainLoop$$anonfun$1$$anonfun$apply$1.apply(MainLoop.scala:96)
	at sbt.State$$anon$1.process(State.scala:184)
	at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:96)
	at sbt.MainLoop$$anonfun$1.apply(MainLoop.scala:96)
	at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
	at sbt.MainLoop$.next(MainLoop.scala:96)
	at sbt.MainLoop$.run(MainLoop.scala:89)
	at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:68)
	at sbt.MainLoop$$anonfun$runWithNewLog$1.apply(MainLoop.scala:63)
	at sbt.Using.apply(Using.scala:24)
	at sbt.MainLoop$.runWithNewLog(MainLoop.scala:63)
	at sbt.MainLoop$.runAndClearLast(MainLoop.scala:46)
	at sbt.MainLoop$.runLoggedLoop(MainLoop.scala:30)
	at sbt.MainLoop$.runLogged(MainLoop.scala:22)
	at sbt.StandardMain$.runManaged(Main.scala:57)
	at sbt.xMain.run(Main.scala:29)
	at xsbt.boot.Launch$$anonfun$run$1.apply(Launch.scala:109)
	at xsbt.boot.Launch$.withContextLoader(Launch.scala:128)
	at xsbt.boot.Launch$.run(Launch.scala:109)
	at xsbt.boot.Launch$$anonfun$apply$1.apply(Launch.scala:35)
	at xsbt.boot.Launch$.launch(Launch.scala:117)
	at xsbt.boot.Launch$.apply(Launch.scala:18)
	at xsbt.boot.Boot$.runImpl(Boot.scala:41)
	at xsbt.boot.Boot$.main(Boot.scala:17)
	at xsbt.boot.Boot.main(Boot.scala)
Caused by: java.lang.OutOfMemoryError: Metaspace
[error] java.util.concurrent.ExecutionException: java.lang.OutOfMemoryError: Metaspace

Instrumentation overlay hides the source code

Instrumented output is too close to the source code in my opinion.

Also, I think that if one edits a line of source code that has been instrumented the instrsumentation overlay should disappear, otherwire the source code may become hidden by the overlay.

Typelevel's scalac

Similar to Dotty, Scala-Native, etc. Add a "Target" Typelevel's scalac

Edited text disappears under worksheet results

Notice how the edited code is lost under the evaluated code
screen shot 2017-01-24 at 14 57 15

Steps to reproduce:

  1. Run List(1)
  2. results appear in worksheet
  3. Edit to List(1, 333333, 333333), the new content gets hidden under the evaluated results from step 1

Proposed artifact versions are wrong

Steps to reproduce the problem:

  • Go to « Libraries »
  • Type “scrimage”
  • Select « scrimage / core »
  • In the listbox the proposed versions are for 2.10, not 2.11.

Show runners status

When redeploying or if all sbt instances are dead the user should be notified something is out of the ordinary

Provide a hint on how to hide "Welcome to Scastie!" message

The current HelloWorld example is included with the help expression at the end. This means, every time someone runs the example (or modifications of this example) will get the help (as long they don't remove the expression).
Please add some hint on the "help" page stating something like "to not see this message again, remove the help expression in your code listing."

Accessibility of scastie

Vimperator and similar tools build on the concept that you can browse a website by using keyboard shortcuts to scroll down pages, use input boxes, and links. However, when the evil Javascript comes into play, tools like Vimperator cannot recognize interactive parts of the website and hence fail.

In a nutshell, this means I cannot control Scastie just with my keyboard. I have to move my hand 20 cm away (often I don't have a keyboard) and get the mouse to click on the "Run" or "Libraries" button. Too much.

It would be awesome if Scastie defines those HTML links on the left menu so that the "on click" experience replicates the current JS behaviour.

Code example for Scala libraries.

For example when I search for cats-core in the Scaladex search it would be useful to know how it works. A code example could be fetch on Github to learn about the library.

return of sxr

either via resurrected browse compiler plugin or a macro similar to the one used for worksheet
it greatly helps to see types of expressions and implicit expansions

Running same program twice trigger sbt reload

Steps to reproduce

  1. set cats as dependency
  2. write import cats._
  3. run
  4. wait 11s to reload sbt, as expected
  5. run, without any change to settings or code
  6. waith 10s to reload sbt, unexpected

improve routing to sbt instance

The current strategy is to round robin.

It's slow because we do no reuse the sbt instance. The worst part is that we change the configuration for other users.

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.