Skip to content

Instantly share code, notes, and snippets.

View shelajev's full-sized avatar

Oleg Šelajev shelajev

View GitHub Profile
logHolder <- java.type("org.graalvm.demos.springr.LogHolder")
logHolder$log(dataHolder$value, data[90:100])
@shelajev
shelajev / big-integer-demo.c
Last active June 6, 2018 09:52
big-integer-demo.c
#include <stdio.h>
#include <polyglot.h>
int main() {
void *bigInteger = polyglot_java_type("java.math.BigInteger");
void *(*BigInteger_valueOf)(long) = polyglot_get_member(bigInteger, "valueOf");
void *bi = BigInteger_valueOf(2);
void *result = polyglot_invoke(bi, "pow", 256);
char buffer[100];
@shelajev
shelajev / big-integer-demo.shell
Last active June 6, 2018 09:52
big-integer-demo.shell
# shelajev at shrimp.local in /tmp
→ clang -c -O1 -emit-llvm -I$GRAALVM_HOME/jre/languages/llvm big-integer-demo.c
# shelajev at shrimp.local in /tmp
→ lli --jvm big-integer-demo.bc
115792089237316195423570985008687907853269984665640564039457584007913129639936
@shelajev
shelajev / r-plots.r
Last active June 6, 2018 13:51
r-plots.r
library(lattice)
mtcars$cars <- rownames(mtcars)
print(barchart(cars~mpg, data=mtcars))
@shelajev
shelajev / PolyglotTest.java
Created June 10, 2018 23:37
PolyglotTest.java
public class PolyglotTest {
public static void main(String[] args) {
System.out.println("Hello World from Java!");
org.graalvm.polyglot.Context context =
org.graalvm.polyglot.Context.newBuilder().allowAllAccess(true).build();
context.eval("js", "print('Hello World from JavaScript!');");
// context.eval("python", "print('Hello World from Python!')");
@shelajev
shelajev / PolyglotTest.java
Created June 10, 2018 23:47
PolyglotTest.java
public class PolyglotTest {
public static void main(String[] args) {
System.out.println("Hello World from Java!");
org.graalvm.polyglot.Context context = org.graalvm.polyglot.Context.newBuilder().allowAllAccess(true).build();
context.eval("js", "print('Hello World from JavaScript!');");
// context.eval("python", "print('Hello World from Python!')");
// context.eval("R", "print('Hello World from R!')");
@shelajev
shelajev / graal-js-example1.js
Last active June 18, 2018 09:23
graal-js-example1.js
const http = require("http");
var BigDecimal = Java.type('java.math.BigDecimal');
http.createServer(function (request, response) {
 response.writeHead(200, {"Content-Type": "text/html"});
 response.end("Hello Graal.js! " + BigDecimal.valueOf(2).pow(100).toString() );
}).listen(8000, function( ) {
console.log("Graal.js server running at http://127.0.0.1:8000/");
});
@shelajev
shelajev / graal-js-example2.js
Created June 15, 2018 11:48
graal-js-example2.js
const http = require("http");
http.createServer(function (request, response) {
 response.writeHead(200, {"Content-Type": "text/html"});
response.end("Hello Graal.js! " + Polyglot.eval('R', 'runif(100)')[0] );
}).listen(8000, function( ) {
console.log("Graal.js server running at http://127.0.0.1:8000/");
});
@shelajev
shelajev / Streams.java
Created June 26, 2018 12:29
Streams.java
package org.sample;
import java.util.Arrays;
import org.openjdk.jmh.annotations.*;
@State(Scope.Benchmark)
public class Streams {
private double[] values = new double[2000000];
@Benchmark
public double mapReduce() {
return Arrays.stream(values)
.map(x -> x + 1)
@shelajev
shelajev / Parallel-Streams.java
Created June 26, 2018 12:36
Parallel-Streams.java
return Arrays.stream(values).parallel()
.map(x -> x + 1)
.map(x -> x * 2)
.map(x -> x + 5)
.reduce(0, Double::sum);