Skip to content

Instantly share code, notes, and snippets.

View benweidig's full-sized avatar

Ben Weidig benweidig

View GitHub Profile
@benweidig
benweidig / blog-java-for-shell-scripting_build.gradle
Last active February 13, 2017 07:49
(Blog) Java for shell scripting
ext.mainClass = "com.example.Main"
import java.nio.file.Files
import java.nio.file.Paths
task shellScript(type: Jar) {
// Create fat Jar
doFirst {
from {
@benweidig
benweidig / blog-docker-runner.sh
Created February 20, 2017 08:38
(Blog) docker-runner.sh
#!/usr/bin/env bash
# Author: Benjamin Weidig <ben@netzgut.net>
# Version: 1 (2017-02-19)
# A helper shell script for starting a Docker container in a more flexible way.
# A container might not start if all the linked containers or ports are not
# available, so now we are able to specify optional resources.
# This script is used at Netzgut to start desktop applications with Docker.
@benweidig
benweidig / AppModule.java
Created May 10, 2018 09:14
Custom jQuery / jQueryUI in Tapestry 5.4
@Core
@Contribute(JavaScriptStack.class)
public static void overrideJquery(OrderedConfiguration<StackExtension> conf) {
conf.override("jquery-library", StackExtension.library("classpath:META-INF/assets/jquery/jquery-3.3.1.min.js"));
}
@Contribute(ModuleManager.class)
public static void contributeModuleManager(MappedConfiguration<String, JavaScriptModuleConfiguration> conf,
@Inject @Symbol(SymbolConstants.PRODUCTION_MODE) boolean productionMode,
AssetSource assetSource) {
@benweidig
benweidig / 00-README-Build-Tapestry-5.5-from-source-with-Eclipse-Photon-and-Java-9-in-a-Docker-container.md
Last active May 5, 2019 13:31
Build Tapestry 5.5 from Source with Eclipse Photon and Java 9 in a Docker container

Build Tapestry 5.5 from source with Eclipse Photon and Java 9 in a Docker container

To have a constant and easy reproducible dev environment we're using Eclipse in a Docker container.

Build Container

  1. Save Dockerfile and docker-entrypoint.sh somewhere in the same folder
  2. Run docker build -t desktop/eclipse:tapestry . in that folder
  3. Wait...

Preprare for Container run

let name: String? = articles?.first?.author?.name
let name: String = articles?.first?.author?.name ?? "n/a"
// Case 1: We know there's a value
Optional<String> withValue = Optional.of("definitly a string");
// Case 2: We 're not sure
Optional<String> maybeValue = Optional.ofNullable(null);
// Case 3: We're sure there's no value
Optional<String> noValue = Optional.empty();
Optional<String> withValue = Optional.of("definitly a string");
if (withValue.isPresent()) {
System.out.println("There's definitly something there!");
}
Optional<String> noValue = Optional.empty();
if (noValue.isPresent() == false) {
System.out.println("No, nothing...");
}
Optional<String> withValue = Optional.of("definitly a string");
String s1 = withValue.get();
Optional<String> noValue = Optional.empty();
String s2 = noValue.get();
// ^^^^^^^^^^^^^ this throws NoSuchElementException!
String result = this.buildResult();
if (result == null) {
return "n/a";
}
return result.toUpperCase();