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 / 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 / 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,
import java.util.*;
import java.util.stream.LongStream;
class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String name = scanner.nextLine();
Optional<String> optAddress = AddressBook.getAddressByName(name);
@SiAust
SiAust / FuntionalComposition.java
Created September 20, 2020 13:33
Composing functions with default method combine.
import java.security.MessageDigest;
import java.util.Base64;
import java.util.Scanner;
import java.util.function.Function;
class ChainOfResponsibilityDemo {
/**
* Accepts a request and returns new request with data wrapped in the tag <transaction>...</transaction>
*/
@SiAust
SiAust / FunctionalSupplier.java
Created September 19, 2020 09:59
A functional supplier that returns incremented int
import java.util.function.*;
class FunctionUtils {
public static Supplier<Integer> getInfiniteRange() {
int[] n = {0};
return new Supplier<Integer>() {
@Override
public Integer get() {
@SiAust
SiAust / HashingExample.java
Created September 11, 2020 13:03
Example hashing using bytes
class HashingFun {
public static void main(String[] args) throws NoSuchAlgorithmException {
MessageDigest hasher = MessageDigest.getInstance("SHA-256");
long count = 0;
Random random = new Random();
byte[] data = new byte[258 / 8];
while (true) {
@SiAust
SiAust / Serialization.java
Created September 5, 2020 09:45
Example of Serializing some classes.
import javax.imageio.IIOException;
import javax.swing.*;
import java.io.*;
public class HyperSkill {
public static void main(String[] args) {
Person simon = new Person("simon", 21, new Address("stillwater", "uk"));
String fileName = "C:\\users\\si_au\\desktop\\simon.data";
try {
@SiAust
SiAust / AbstractFactory.java
Created September 4, 2020 13:11
Example Abstract factory design pattern
class TestDrive {
public static void main(String[] args) throws InterruptedException {
Phone phone;
PhoneFactory iphoneFactory = new IphoneFactory();
PhoneFactory samsungFactory = new SamsungFactory();
System.out.println("-Hello, I need Android phone");
System.out.println("-Okay! Please wait for a sec, - Calling to the SamsungFactory. -Bring me the Samsung Galaxy S10");
Thread.sleep(1500);
@SiAust
SiAust / Enum.java
Created September 3, 2020 14:20
Example of an enum class.
public enum DayOfWeek {
MONDAY(1,true),
TUESDAY(2,true),
WEDNESDAY(3,false),
THURSDAY(4,false),
FRIDAY(5,true),
SATURDAY(6,false),
SUNDAY(7,true);
private final boolean sunny;
@SiAust
SiAust / TemplatePattern.java
Created September 2, 2020 13:13
A simple example of Template pattern.
class Scratch {
public static void main(String[] args) {
Worker programmer = new Programmer();
Worker carpenter = new Carpenter();
programmer.goToWork();
carpenter.goToWork();
}
}