Skip to content

Instantly share code, notes, and snippets.

View shelajev's full-sized avatar

Oleg Šelajev shelajev

View GitHub Profile
# 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 \
@shelajev
shelajev / app.js
Last active March 25, 2019 17:54
Using test-containers from node.js app (GraalVM)
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
});
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);
@shelajev
shelajev / app.js
Created December 5, 2018 16:33
Running testcontainers-java from node.js
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({
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;
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,]);" +
"}");
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;
}
Context ctx = Context.newBuilder("R").allowAllAccess(true).build();
ctx.eval("R", "sum").execute(new int[] {1,2,3});
svg()
print(histogram(...))
svgCode <- svg.string()
png('/path/to/image.png')
print(histogram(...))
dev.off()
# 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)