Posts

Showing posts from February, 2019

git info over actuator

<!-- generates a resources/git.properties file that exposes git properties over /actuator/info endpoint --> <plugin> <groupId> pl.project13.maven </groupId> <artifactId> git-commit-id-plugin </artifactId> <version> 2.2.5 </version> <executions> <execution> <goals> <goal> revision </goal> </goals> <phase> initialize </phase> </execution> </executions> <configuration> <dotGitDirectory> ${project.basedir}/.git </dotGitDirectory> <generateGitPropertiesFile> true </generateGitPropertiesFile> <generateGitPropertiesFilename> ${project.basedir}/src/main/resources/git.properties </generateGitPropertiesFilename> <prefix> git </prefix> <format> properties </format> <failOnUnableToExt...

Java Midi

I'm a musician in my spare time. When I started programming I wanted to make music with code. I managed to produce some notes through the java Synthesizer class. So I thought it would be fun to revisit it after working as a software engineer for almost a year. I started with the same set of websites, with StackOverflow as hub to more resources. It's amazing to see the paralels between midi and present day async web messaging. Especially if you realize that MIDI was standardized in 1983, :D. MIDI basically works through a MidiEvents triggering sounds on a MidiSynthesizer. A MidiFile is thus a Sequence of MidiEvents that you can play through a Sequencer on a Synthesizer. This is reflected in the data structure of the relevant classes. Here is some code to get started: /* Create a new Sythesizer and open it. Most of * the methods you will want to use to expand on this * example can be found in the Java documentation here: * https://docs.oracle.c...

Getting the Type from generic type parameter, Within a class

Guava makes it easier to get the type of a generic type parameter. I personally feel it's ugly to request the Class given through the generic interface <T>, even though the class should already be aware of it. Even though browsing seems to turn up that asking for Class<T> in your constructor seems like the most standard way. protected Class< T > clazz ; protected final MongoTemplate mongoTemplate ; protected ExtendedMongoTemplate (MongoTemplate mongoTemplate) { this . mongoTemplate = mongoTemplate ; final TypeToken<? extends T > typeToken = new TypeToken<>( this .getClass()){} ; final Type type = typeToken.getType() ; if (type instanceof Class) { clazz = (Class< T >) type ; } else { throw new RuntimeException( this .getClass() + ": failed to retrieve generic parameter  class in " + ExtendedMongoTemplate. class .getSimpleName() + "." ) ; } } /** * if the present way o...

Spring boot batch & MongoDB

Spring boot batch is too opinionated out of the box to gel well with mongodb, it ads the sql focussed jpa and jdbc dependenties. Excluding it will at least make your application run again, I haven't tested batching yet in this context. <dependency> <groupId> org.springframework.boot </groupId> <artifactId> spring-boot-starter-batch </artifactId> <exclusions> <exclusion> <groupId> org.springframework.boot </groupId> <artifactId> spring-boot-starter-jdbc </artifactId> </exclusion> </exclusions> </dependency>