Skip to content

Instantly share code, notes, and snippets.

View SiAust's full-sized avatar
🏠
Open to new opportunities

Simon Aust SiAust

🏠
Open to new opportunities
View GitHub Profile
@SiAust
SiAust / FunctionalStream.java
Created September 22, 2020 08:38
A functional stream example with Comparator, BiConsumer and Optional
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
class MinMax {
public static <T> void findMinMax(
Stream<? extends T> stream,
Comparator<? super T> order,
@SiAust
SiAust / BaseActor.java
Created October 1, 2020 13:12
Weird git merge issue. Duplicated class BaseActor, add "<<< HEAD" to top and my version of BaseActor below, hash at bottom of file.
<<<<<<< HEAD
package com.mygdx.game;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.*;
@SiAust
SiAust / Direction_Enum.java
Created October 19, 2020 08:40
Enum example
class Move {
public static void main(String[] args) {
Robot robot = new Robot(0,0, Direction.UP);
System.out.printf("robotX: %d robotY: %d\n", robot.getX(), robot.getY());
moveRobot(robot, 10, 0);
System.out.printf("robotX: %d robotY: %d\n", robot.getX(), robot.getY());
}
public static void moveRobot(Robot robot, int toX, int toY) {
@SiAust
SiAust / StaticBuilder.java
Created October 24, 2020 10:27
Example builder pattern in static class.
import java.util.Scanner;
class Robot {
private String CPU;
private int legs;
private int hands;
private int eyes;
Robot(String CPU, int legs, int hands, int eyes) {
@SiAust
SiAust / Builder.java
Created October 24, 2020 10:28
Example builder pattern with interface and concrete builder.
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
* ConcreteComponent - Geek.
**/
class Geek {
private String type;
private List<String> languages;
@SiAust
SiAust / scratch_7.java
Created December 9, 2020 10:11
Java Reflection API example
// Do not remove imports
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.WildcardType;
import java.util.Set;
import java.util.Scanner;
class ListParameterInspector {
// Do not change the method
@SiAust
SiAust / SandwichBuilder.java
Created December 11, 2020 09:57
Example of Builder pattern.
import java.util.Scanner;
class Sandwich {
private String bun;
private int salad;
private int cheese;
private int cucumber;
private int ham;
@SiAust
SiAust / JUnitTest.java
Created March 16, 2021 10:07
Simple example of JUnit
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import java.util.Arrays;
public class JUnitTest {
@Test
public void CalculatorTest() {
Calculator calculator = new Calculator();
assertEquals(10, calculator.sum("1234"));
@SiAust
SiAust / Comparator example
Created April 18, 2021 09:51
Sort a list by odd first, then odd asc, even desc
public static List<Integer> sortOddEven(List<Integer> numbers) {
// sort odd and even
// then sort odd asc, even desc
Comparator<Integer> byOddFirst = (i1, i2) -> (i1 | 1) == i1 ? -1 : (i2 | 1) > i2 ? 1 : 0;
Comparator<Integer> byOddAscEvenDesc = (i1, i2) -> {
if ((i1 | 1) == i1 && (i2 | 1) == i2) {
return Integer.compare(i1, i2);
} else if ((i1 | 1) > i1 && (i2 | 1) > i2) {
return Integer.compare(i1, i2) * -1;
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.example.web_quiz_app.WebQuizAppApplication];
nested exception is org.springframework.context.annotation.ConflictingBeanDefinitionException:
Annotation-specified bean name 'securityConfig' for bean class [com.example.web_quiz_app.Security.SecurityConfig]
conflicts with existing, non-compatible bean definition of same name and class [io.github.siaust.web_quiz_app.Config.SecurityConfig]
at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:188) ~[spring-context-5.2.7.RELEASE.jar:5.2.7.RELEASE