This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # docker build . -t graalvm-ce-nightly | |
| from ubuntu:latest as GRAALVM-BUILD | |
| ENV DEBIAN_FRONTEND noninteractive | |
| ENV JVMCI_VERSION_CHECK ignore | |
| WORKDIR graalvm-build | |
| RUN apt-get update \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const readline = require('readline'); | |
| var GenericContainer = Java.type('org.testcontainers.containers.GenericContainer'); | |
| var container = new GenericContainer("nginx"); | |
| container.setExposedPorts([80]); | |
| container.start(); | |
| console.log(container.getContainerIpAddress() + ':' + container.getMappedPort(80)); | |
| const rl = readline.createInterface({ | |
| input: process.stdin, | |
| output: process.stdout | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| import org.graalvm.polyglot.proxy.*; | |
| public class Pojo { | |
| public static Object getMap() { | |
| Map mapOuter = new HashMap(); | |
| Map mapInner = new HashMap(); | |
| List arrayInner = new ArrayList(); | |
| mapInner.put("1", 3); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const readline = require('readline'); | |
| var GenericContainer = Java.type('org.testcontainers.containers.GenericContainer'); | |
| var container = new GenericContainer("nginx").withExposedPorts([80]); | |
| container.start(); | |
| console.log(container.getContainerIpAddress() + ':' + container.getMappedPort(80)); | |
| const rl = readline.createInterface({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class RJavaBench { | |
| public int intField; | |
| public double doubleField; | |
| public int intFunction(int a, int b) { return a - b; } | |
| public RJavaBench objectFunction(RJavaBench a) { | |
| RJavaBench result = new RJavaBench(); | |
| // ... | |
| return result; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Context ctx = Context.newBuilder("R").allowAllAccess(true).build(); | |
| Value rFunction = context.eval("R", | |
| "function(table) { " + | |
| " table <- as.data.frame(table);" + | |
| " cat('The whole data frame printed in R:\n');" + | |
| " print(table);" + | |
| " cat('---------\n\n');" + | |
| " cat('Filter out users with ID>2:\n');" + | |
| " print(table[table$id > 2,]);" + | |
| "}"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static final class User { | |
| public final int id; | |
| public final String name; | |
| // ...usual constructor | |
| } | |
| public static class NameColumn implements ProxyArray { | |
| private final User[] users; | |
| public NameColumn(User[] users) { | |
| this.users = users; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Context ctx = Context.newBuilder("R").allowAllAccess(true).build(); | |
| ctx.eval("R", "sum").execute(new int[] {1,2,3}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| svg() | |
| print(histogram(...)) | |
| svgCode <- svg.string() | |
| png('/path/to/image.png') | |
| print(histogram(...)) | |
| dev.off() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # load the R package lattice and open a window for plotting | |
| polyglot.eval(string="library(lattice); awt()", language="R") | |
| # Create R function that draws a histogram | |
| plot = polyglot.eval(string="function(y) {print(histogram(~as.vector(y), main='Hello from Python to R', xlab='Python List')) }", language="R") | |
| # invoke the R function from Python | |
| plot(result) |