Skip to content

Instantly share code, notes, and snippets.

View nwillc's full-sized avatar

Nwillc nwillc

View GitHub Profile
@nwillc
nwillc / constructor2.java
Last active November 20, 2017 04:38
Associating the wiring
// Load Schema
final SchemaParser schemaParser = new SchemaParser();
final TypeDefinitionRegistry registry;
try (final InputStream inputStream =
getClass().getClassLoader().getResourceAsStream("schema.graphqls");
final InputStreamReader streamReader = new InputStreamReader(inputStream)) {
registry = schemaParser.parse(streamReader);
} catch (Exception e) {
throw new IllegalStateException("Could not parse graphql schema", e);
}
@nwillc
nwillc / jdk9-build.gradle
Created January 28, 2018 15:55
Gradle snippet to build jdk9 module
plugins {
id 'java-library'
}
repositories {
jcenter()
}
ext.moduleName = 'com.github.nwillc.fluentsee'
version = '1.0.0'
@nwillc
nwillc / build.gradle
Created February 18, 2018 18:15
Gradle build using JUnit5 and Jacoco
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.1.0-RC1'
}
}
apply plugin: "jacoco"
@nwillc
nwillc / GeneratedKeys1.java
Last active April 8, 2018 13:52
JDBC generated keys: Attempt 1
public long create(String sql) throws SQLException {
try (
Connection connection = dataSource.getConnection();
Statement statement = connection.prepareStatement(sql,
Statement.RETURN_GENERATED_KEYS)) {
if (statement.executeUpdate() == 0) {
throw new SQLException("Insert failed, no rows affected.");
}
@nwillc
nwillc / GeneratedKey.sql
Created April 8, 2018 13:57
A table with a generated key
CREATE TABLE WORDS(ID BIGINT AUTO_INCREMENT, WORD CHAR(20))
@nwillc
nwillc / GeneratedKeys2.java
Created April 9, 2018 03:02
Attempt 2 at more portable key retrieval
public long create(String sql, String[] keyColumns) throws SQLException {
try (
Connection connection = dataSource.getConnection();
PreparedStatement statement = connection.prepareStatement(sql, keyColumns)) {
if (statement.execute() == 0) {
throw new SQLException("Insert failed, no rows affected.");
}
try (ResultSet generatedKeys = statement.getGeneratedKeys()) {
@nwillc
nwillc / Before.java
Created April 26, 2018 16:34
A Before Combinator
@FunctionalInterface
public interface Before<T, R>
extends Function<Consumer<T>,
Function<Function<T, R>,
Function<T, R>>> {
static <T, R> Before<T, R> create() {
return before -> function -> argument -> {
before.accept(argument);
return function.apply(argument);
@nwillc
nwillc / BeforeUtil.java
Created April 26, 2018 16:37
Before util in Java
public class BeforeUtil {
static <T, R> Function<T, R> before(Consumer<T> before, Function<T, R> function) {
return arg -> {
before.accept(arg);
return function.apply(arg);
};
}
}
@nwillc
nwillc / build.gradle
Created April 26, 2018 16:57
Fat Sloppy Jar
jar {
manifest {
attributes(
'Main-Class': "${project.group}.foo.Main"
)
}
from configurations.compile.collect { entry -> zipTree(entry) }
}
@nwillc
nwillc / osxApp.groovy
Created May 19, 2018 16:16
Gradle task to build an OS X app
task osxApp {
dependsOn jar
doLast {
def dist = "${buildDir}/app/${project.name}.app"
mkdir("$dist/Contents/MacOS")
mkdir("$dist/Contents/Resources")
ant.copy(file: "src/main/app/Info.plist", todir: "$dist/Contents")
ant.copy(file: "src/main/app/launcher", todir: "$dist/Contents/MacOS") {
filterset {