This file contains 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.io.IOException; | |
import java.net.URI; | |
import java.net.URISyntaxException; | |
import java.net.http.HttpClient; | |
import java.net.http.HttpRequest; | |
import java.nio.file.Files; | |
import java.nio.file.Path; | |
import java.nio.file.Paths; | |
import java.time.LocalDateTime; | |
import java.util.Base64; |
This file contains 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
With sessions it might be necessary to logout on password change. Also the Logout button from UI should additionally logout on the server. | |
https://stackoverflow.com/questions/44359792/log-out-user-by-admin-spring-security | |
https://docs.spring.io/spring-security/site/docs/current/reference/html5/#jc-logout | |
// in WebSecurityConfigurerAdapter |
This file contains 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 Functional { | |
@FunctionalInterface | |
public interface CheckedFunction<T, R> { | |
R apply(T t) throws Exception; | |
} | |
public static <T, R> Function<T, R> uncheck(CheckedFunction<T, R> checkedFunction) { | |
return t -> { | |
try { |
This file contains 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 static java.util.stream.IntStream.rangeClosed; | |
import static java.util.stream.Collectors.toCollection; | |
List<Integer> randomList(int firstInclusive, int lastInclusive) { | |
List<Integer> numbers = rangeClosed(firstInclusive, lastInclusive).boxed().collect(toCollection(()->new ArrayList<Integer>())); | |
java.util.Collections.shuffle(numbers, new java.security.SecureRandom()); | |
return numbers; | |
} | |
// usage: randomList(1,10); |
This file contains 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
<!DOCTYPE html> | |
<html> | |
<body> | |
<canvas id="myCanvas" width="1000" height="500" style="border:1px solid #000000;"> | |
Your browser does not support the HTML5 canvas tag. | |
</canvas> | |
<script> | |
This file contains 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
// Math.max overflows if array is too big, use reduce instead | |
const fastMin = (array) => array.reduce( (a,b) => (a < b) ? a : b ); | |
const fastMax = (array) => array.reduce( (a,b) => (a > b) ? a : b ); |
This file contains 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.beans.PropertyDescriptor; | |
import java.lang.reflect.Field; | |
import java.lang.reflect.InvocationTargetException; | |
import java.util.ArrayList; | |
import java.util.Collection; | |
import java.util.LinkedList; | |
import java.util.List; | |
import org.springframework.beans.BeanUtils; | |
This file contains 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
# -*- mode: ruby -*- | |
# vi: set ft=ruby : | |
$script = <<SCRIPT | |
export DEBIAN_FRONTEND=noninteractive | |
apt-get -q -y update | |
apt-get -q -y install emacs |
This file contains 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 org.hibernate.Hibernate; | |
import org.hibernate.proxy.HibernateProxy; | |
public class HibernateUnproxifier<T> { | |
@SuppressWarnings("unchecked") | |
public T unproxy(T entity) { | |
if (entity == null) { | |
throw new NullPointerException("Entity passed for initialization is null"); |
This file contains 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
Map<String,String> eqs = new HashMap<String,String>(); | |
eqs.put("piApprox(k)","8*cumsum(ChebyshevTerm(k))"); | |
eqs.put("ChebyshevTerm(k)","( (-1)^k * (sqrt(2)-1)^(2*k+1)) / (2*k+1)"); | |
eqs.put("absError(k)", "abs(pi-piApprox)"); | |
EquationProcessor k = new EquationProcessor(eqs); | |
Map<String,String> defs = new HashMap<String,String>(); | |
defs.put("k","[0:20]"); | |