Object Audit with Java and Javers

Just a quick snippet Maven Integration pom.xml <dependency> <groupId>org.javers</groupId> <artifactId>javers-core</artifactId> <version>${javers.version}</version> </dependency> Calculate Changes in Object Graph package io.hascode; import org.javers.core.Changes; import org.javers.core.Javers; import org.javers.core.JaversBuilder; import org.javers.core.diff.Diff; public <T> Changes diff(T snapshot, T latest) { Javers javers = JaversBuilder.javers().build(); Diff diff = javers.compare(snapshot, latest); return diff.getChanges(); } Resources Javers Website

September 18, 2023 · 1 min · 50 words · Micha Kops

Forwardings Requests to static content in Spring Boot Webflux

The following WebFilter redirects incoming requests for / to a static HTML file, index.html. ToIndexPageRedirection.java package com.hascode.tutorial; import org.springframework.stereotype.Component; import org.springframework.web.server.ServerWebExchange; import org.springframework.web.server.WebFilter; import org.springframework.web.server.WebFilterChain; import reactor.core.publisher.Mono; @Component public class ToIndexPageRedirection implements WebFilter { @Override public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) { if (exchange.getRequest().getURI().getPath().equals("/")) { return chain.filter( exchange.mutate().request( exchange.getRequest().mutate().path("/index.html").build() ).build() ); } return chain.filter(exchange); } } Ressources: JavaDocs WebFilter

August 16, 2022 · 1 min · 59 words · Micha Kops

Fast Link Checks using Filiph Linkchecker and Docker

This Linkchecker claims to be way faster than blc and wummel/linkchecker. Using Docker, we may validate our site’s links in no time and without complex setup. docker run --rm tennox/linkcheck hascode.io Resources https://github.com/filiph/linkcheck

May 2, 2022 · 1 min · 33 words · Micha Kops

Setting up multiple Postgresql Instances with docker-compose

A simple setup when two Postgres databases prefilled with schema/data needed. docker-compose.yml version: '3.6' services: postgres1: image: postgres restart: always environment: - DATABASE_HOST=127.0.0.1 - POSTGRES_USER=root - POSTGRES_PASSWORD=root - POSTGRES_DB=root ports: - "15432:15432" volumes: - ./postgres1-init.sql:/docker-entrypoint-initdb.d/docker_postgres_init.sql postgres2: image: postgres restart: always environment: - DATABASE_HOST=127.0.0.1 - POSTGRES_USER=root - POSTGRES_PASSWORD=root - POSTGRES_DB=root ports: - "25432:25432" volumes: - ./postgres2-init.sql:/docker-entrypoint-initdb.d/docker_postgres_init.sql And our sample init scripts: CREATE USER tester WITH PASSWORD 'tester' CREATEDB; CREATE DATABASE testdb WITH OWNER = tester ENCODING = 'UTF8' LC_COLLATE = 'en_US.utf8' LC_CTYPE = 'en_US.utf8' TABLESPACE = pg_default CONNECTION LIMIT = -1; ...

February 8, 2022 · 1 min · 90 words · Micha Kops

Factory Reset for Google Pixel-C Android Tablet

Steps Reboot the system by pressing "Power" and "Volume down" simultaneously Boot menu should appear, use "Volume up/down" to select the menu item "Android Recovery", "Power" to confirm System reboots, a screen appears with a message "No command" - this is no error though it looks like one Press "Power" and "Volume up" together and a menu "Android Recovery" appears Use "Volume up/down" to select the menu item "Wipe data/factory reset", "Power" to confirm User data on the device is deleted and the original meu is shown Select the menu item "Reboot system now" and confirm by pressing the "Power" Button The device reboots and you may configure the Android system …​ ...

June 13, 2021 · 1 min · 112 words · Micha Kops

Setting up an OAuth2 Authorization Server and Resource Provider with Spring Boot

OAuth2 is a frequently used standard for authorization and with Spring Boot it is easy to set up authorization and resource server in no time. In the following short tutorial I’d like to demonstrate how to set up an OAuth2 authorization server as well as a connected and secured resource server within a few minutes using Java, Maven and Spring Boot. Figure 1. OAuth2 Flow with Spring Boot in Action...

March 13, 2016 · 6 min · 1125 words · Micha Kops

JAX-RS Server API Snippets

Because a lot of my current projects are using JAX-RS in different versions I’d like to write down and share some frequently used snippets for implementing RESTful web-services with the JAX-RS specification here. Using RegEx in Path Expressions Sometimes we need to extract multiple parameters from a path expression e.g. in the following example where year, month and day are fragments if the path. @GET @Path("/orders/{year:\\d{4}}-{month:\\d{2}}-{day:\\d{2}}") @Produces(MediaType.TEXT_PLAIN) public Response getOrders(@PathParam("year") final int year, @PathParam("month") final int month, @PathParam("day") final int day) { return Response.ok("Year: " + year + ", month: " + month + ", day: " + day).build(); } ...

September 28, 2014 · 5 min · 924 words · Micha Kops

Snippet: Mixing Scala, Java in a Maven Project

Having just returned from the Atlassian Camp 2012 I just toyed around with Java and Scala and wanted to share the following snippet that demonstrates how to mix code from both languages in a Maven project using the maven-scala-plugin. Setting up the Maven Project First create a new Maven project in your IDE or by running mvn archetype:generate. In the next step, add the dependency for scala-library and the scala maven repositories to your pom.xml and hook the maven-scala-plugin to Maven’s lifecycle. My pom.xml finally looks like this one: ...

March 23, 2012 · 2 min · 327 words · Micha Kops

How to create an Android App using Google’s App Inventor

Today we’re going to take a look at Google’s App Inventor feature that offers programming-novices a nice possibility to enter the fabulous world of Android App programming without deeper knowledge of the API or complex SDK installations. So lets build some stuff .. Prerequisites Java 6 JDK App Inventors Extras Software A Google App Inventor Beta Account – request one here What we are going to build We are building a simple GUI with a Textbox and a button A click on the button starts an event that queries the acceleration sensor for coordinates If the sensor is active and enabled then the coordinates are displayed in the text box ...

August 4, 2010 · 4 min · 749 words · Micha Kops

Creating a simple Gesture App with Android

The integration of gestures into your android app adds some nice functionality and is made very easy using Google’s GestureBuilder application and the integrated GestureLibrary and Gesture Overlay API – so let’s build a sample app. If you need some basic information regarding gestures on android first – take a look at this article. Creating a gesture library First you need to define the gestures that should be captured in the application later. For this reason there’s the GestureBuilder delivered with the Android SDK. You can find the app in the samples directory of your android sdk – e.g. <installation-directory>/android-sdk-linux_86/platforms/android-2.1/samples/GestureBuilder. ...

May 14, 2010 · 3 min · 635 words · Micha Kops