Skip to content

Instantly share code, notes, and snippets.

@schaloner
schaloner / Application.java
Last active January 3, 2016 11:09
Load externally-defined data into an in-memory database for Play 2 testing.
package controllers;
import models.Item;
import play.libs.Json;
import play.mvc.Controller;
import play.mvc.Result;
public class Application extends Controller
{
public static Result index()
@schaloner
schaloner / AsyncApplication.java
Created March 28, 2014 13:44
Handling exceptions in Play 2 Java asynchronous controllers. Thinking about ways of specifying Result types from within async blocks.
package controllers;
import play.libs.Akka;
import play.libs.F;
import play.mvc.Controller;
import play.mvc.Result;
import java.util.concurrent.Callable;
public class AsyncApplication extends Controller {

Keybase proof

I hereby claim:

  • I am schaloner on github.
  • I am schaloner (https://keybase.io/schaloner) on keybase.
  • I have a public key whose fingerprint is 3B9A 27FC C097 C0AB E696 5F5D 89EC FBA2 E459 F6F9

To claim this, I am signing this object:

@schaloner
schaloner / GenericValidator.java
Last active August 29, 2015 14:13
Apply a series of validations to an object using a stream, with subsequent validations only applied if earlier ones succeeded.
package be.objectify.example.validators;
import java.util.LinkedList;
import java.util.List;
import java.util.function.Function;
public class GenericValidator<T> implements Function<T, Boolean> {
private final List<Function<T, Boolean>> validators = new LinkedList<>();
@schaloner
schaloner / chartist.radial.js
Last active November 26, 2015 12:41
A combination of a bar chart and a pie chart for Chartist.js
(function(window, document, Chartist) {
'use strict';
/**
* Default options in line charts. Expand the code view to see a detailed list of options with comments.
*
* @memberof Chartist.Radial
*/
var defaultOptions = {
// Specify a fixed width for the chart as a string (i.e. '100px' or '50%')
@schaloner
schaloner / AuthCallback.java
Created December 17, 2015 12:10
Auth0 Play Java callback - basic implementation
package be.objectify.example.controllers;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import be.objectify.example.models.User;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.google.inject.Inject;
import play.cache.CacheApi;
import play.libs.F;
@schaloner
schaloner / JavaGenerator.java
Last active May 18, 2017 08:48
Proof of concept for generating Kotlin classes for jOOQ
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
package be.objectify.tcexample;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public abstract AbstractUserDaoTest {
@Test
public void testFoo() {
assertThat(dao().something()).isEqualTo(whatever);
}
@schaloner
schaloner / JsonBinder.java
Created March 31, 2017 09:55
Supporting PostgreSQL JSON types in jOOQ using Jackson. Adapted from the GSON example found at https://www.jooq.org/doc/3.9/manual/code-generation/custom-data-type-bindings/
package be.objectify.example.jooq;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.sql.Types;
import java.util.Objects;
import com.fasterxml.jackson.databind.JsonNode;
import org.jooq.Binding;
import org.jooq.BindingGetResultSetContext;
import org.jooq.BindingGetSQLInputContext;
@schaloner
schaloner / FasterJooqUserDaoTest.java
Created May 17, 2017 12:56
Increasing test performance using TestContainers
package be.objectify.tcexample.db;
import be.objectify.tcexample.AbstractUserDaoTest;
import be.objectify.tcexample.UserDao;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.testcontainers.containers.PostgreSQLContainer;
import play.db.Database;