Skip to content

Instantly share code, notes, and snippets.

View mbjarland's full-sized avatar

Matias Bjarland mbjarland

  • Rursus AB
  • Sweden / USA
View GitHub Profile
@mbjarland
mbjarland / stacktrace
Created August 14, 2020 18:46
okhttp 3.12.12 stacktrace when running with java 7
Exception in thread "main" java.lang.NoClassDefFoundError: java/time/Duration
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2625)
at java.lang.Class.privateGetPublicMethods(Class.java:2743)
at java.lang.Class.getMethods(Class.java:1480)
at java.beans.Introspector.getPublicDeclaredMethods(Introspector.java:1280)
at java.beans.Introspector.getTargetMethodInfo(Introspector.java:1141)
at java.beans.Introspector.getBeanInfo(Introspector.java:416)
at java.beans.Introspector.getBeanInfo(Introspector.java:163)
at groovy.lang.MetaClassImpl$15.run(MetaClassImpl.java:3328)
@mbjarland
mbjarland / JIRA query json response
Last active March 3, 2017 10:33
Sample JIRA rest json response
{
"expand": "schema,names",
"issues": [
{
"changelog": {
"histories": [
{
"author": {
"active": true,
@mbjarland
mbjarland / 0_README.md
Last active January 13, 2021 16:59
Groovy: find line in file backwards

What is this?

This is a short groovy snippet showing how you can define a couple of new methods for iterating and searching backwards in a file. The methods traverse the file from the last line towards the first without loading the entire file contents into memory.

The methods use the commons-io ReversedLinesFileReader class.

This gist was created in response to stackoverflow thread:

http://stackoverflow.com/questions/42229090/groovy-read-file-backwards

@mbjarland
mbjarland / sample run
Last active October 27, 2015 09:04
Groovy / Java retrieve all subsets of size k given a list of size n

What is this?

There are a number of threads on the internet discussing performant ways of picking subsets out of a List or a Set in java / groovy. As I could not find any answers which felt clean to me, I did a bit of research and found the apache commons math Combinations class which seems quite performant, exists in mavenCentral and offers a clean interface.

For a random reference, picking sets of 10 from a list of 30 (about 30M combinations) takes about 500ms on my workhorse machine which is more or less up to date. That is just the apache commons piece which only gives back the indicies into the source (i.e. it sends out sets [1,2], [1,3], [2,3] if you tell it to pick 2 out of a set of 3, you can not ask it for subsets of length 2 for list ['a', 'b', 'c']) list/set.

In the below code we add the ability to work directly with lists and ask for subsets in groovy which means a performance hit, but I would guess that the convenience is in most cases worth the loss in performance.

I'm posting this in

@mbjarland
mbjarland / Gradle Script File Locking.md
Last active December 24, 2015 23:49
This gist demonstrates an issue with concurrent gradle executions. This issue has been tested to exist on gradle 1.8 and a number of versions below.

This gist demonstrates an issue with concurrent gradle executions. This issue has been tested to exist on gradle 1.8 and a number of versions below.

This gist was created as a response to on the following gradle forum thread:

http://forums.gradle.org/gradle/topics/why_is_the_build_script_cache_global?utm_content=topic_link&utm_medium=email&utm_source=reply_notification#reply_13065577

To replicate, create an empty gradle project and drop the contents of 'build.gradle' below into it. If you feel like using the gradle wrapper, start by executing: