Skip to content

Instantly share code, notes, and snippets.

View shelajev's full-sized avatar

Oleg Šelajev shelajev

View GitHub Profile
@Entity
@NamedEntityGraph(name = "graph.AuthorBooks", attributeNodes = @NamedAttributeNode("books"))
public class Author implements Serializable {
EntityGraph graph = entityManager.getEntityGraph("graph.AuthorBooks");
List<Author> authorsWithBooks = entityManager
.createQuery("SELECT DISTINCT a FROM Author a", Author.class)
@shelajev
shelajev / GenerateGarbage.java
Created April 2, 2017 18:55
Sample Java class that generates some garbage, then proceeds to stop generating it.
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Märt Bakhoff
*/
public class GenerateGarbage {
private static final String loremIpsum = "" +
package org.shelajev;
import java.util.ArrayList;
import java.util.List;
public class LukasChallenge {
public static void main(String[] args) {
LukasChallenge lukasChallenge = new LukasChallenge();
List<Pair> aaa = lukasChallenge.subPalindromes("ababa");
@shelajev
shelajev / Component.java
Created November 21, 2017 13:29
Rubah test classes
package com.shelajev.updates;
import rubah.Rubah;
public class Component {
private static DataHolder data = new DataHolder(0);
public String wrangle(int i, String s) {
Rubah.update("wrangle");
$ js
> 1 + 2
3
> print(“undefined is not a function”)
undefined is not a function
library(ggplot2)
data <<- numeric(100)
function(v) {
svg()
data <<- c(data[2:100], v)
plot <- ggplot(data = data.frame(systemLoad = data, time = -99:0),
aes(x=time, y=systemLoad, group=1)) +
geom_line(color="orange") +
expand_limits(x=0, y=0)
print(plot)
@Bean
public Context getGraalVMContext() {
return Context.newBuilder().allowAllAccess(true).build();
}
@Value(value = "classpath:plot.R")
private Resource rSource;
@Bean
Function<Double, String> getPlotFunction(@Autowired Context ctx)
throws IOException {
Source source = Source.newBuilder("R", rSource.getURL()).build();
return ctx.eval(source).as(Function.class);
}
@RequestMapping(value = "/load", produces = "image/svg+xml")
public ResponseEntity<String> load() {
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.set("Refresh", "1");
return new ResponseEntity<String>(
plotFunction.apply(
ManagementFactory.getOperatingSystemMXBean()
.getSystemLoadAverage()),
responseHeaders,
HttpStatus.OK);
public class LogHolder {
private static final Log LOG =
LogFactory.getLog(SpringRApplication.class);
public static void log(double value, Object... args) {
LOG.info(String.format("Logging (value = %s): %s", value,
Arrays.toString(args)));
}
}