Skip to content

Instantly share code, notes, and snippets.

💭
🕉 Coding...

Daniel Dietrich danieldietrich

💭
🕉 Coding...
Block or report user

Report or block danieldietrich

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View mvn release:perform
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Javaslang 1.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-release-plugin:2.4.2:perform (default-cli) @ javaslang ---
[INFO] Checking out the project to perform the release ...
[INFO] Executing: /bin/sh -c cd /Users/daniel/git/rocketscience-projects/javaslang/target && git clone --branch javaslang-1.0.0 git@github.com:rocketscience-projects/javaslang.git /Users/daniel/git/rocketscience-projects/javaslang/target/checkout
[INFO] Working directory: /Users/daniel/git/rocketscience-projects/javaslang/target
View NestedFunWithLambda.java
interface NestedFunWithLambda {
default String spaces(int count) {
final BiFunction<String, Integer, String> spaces =
// compiler complains that spaces may not have been initialized
(s, i) -> (i < 1) ? s : spaces.apply(s + " ", i - 1);
return spaces.apply("", count);
}
View SafeExitJVM_snippet.java
/**
* Exits the JVM using {@code Runtime.getRuntime().exit(status)} (which is equivalent to
* {@code System.exit(0)}). If something goes wrong while running the finalizers and shutdown
* hooks, or the timeout is reached, the JVM is forced to be terminated by calling
* {@code Runtime.getRuntime().halt(status)}.
*
* @param status the exit status, zero for OK, non-zero for error
* @param timeout The maximum delay in milliseconds before calling
* {@code Runtime.getRuntime().halt(status)}.
*
@danieldietrich
danieldietrich / Assertions.java
Last active Aug 29, 2015
Assert that a block of code is throwing
View Assertions.java
public final class Assertions {
/**
* This class is not intended to be instantiated.
*/
private Assertions() {
throw new AssertionError(Assertions.class.getName() + " cannot be instantiated.");
}
public static RunnableAssert assertThat(Runnable test) {
@danieldietrich
danieldietrich / Example
Last active Aug 29, 2015
Antlr Parse Result Printer
View Example
$ alias antlr=./antlr.sh
$ antlr Issue118 start
Please enter input to be parsed and press <Ctrl>-D when finished.
a 1 b
<Ctrl>-D
(start a 1 b)
$ echo "a 1 b" > test.txt
$ antlr Issue118 start test.txt
@danieldietrich
danieldietrich / Iterators.java
Last active Aug 29, 2015
Use javaslang.Option instead of java.util.Optional if null is permitted
View Iterators.java
/** / \____ _ ______ _____ / \____ ____ _____
* / \__ \/ \ / \__ \ / __// \__ \ / \/ __ \ Javaslang
* _/ // _\ \ \/ / _\ \\_ \/ // _\ \ /\ \__/ / Copyright 2014 Daniel Dietrich
* /___/ \_____/\____/\_____/____/\___\_____/_/ \_/____/ Licensed under the Apache License, Version 2.0
*/
package javaslang.collection;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.function.Predicate;
@danieldietrich
danieldietrich / Monad.java
Last active Aug 29, 2015
The most sophisticated generic Java type I ever wrote
View Monad.java
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
/**
* The Monad interface.
*
* @param <M> The type of the monad, e.g. {@code class Foo<A> extends Monad<Foo<?>, A, Foo<A>>}.
* @param <A> Component type of {@code M}.
*/
@danieldietrich
danieldietrich / Example.java
Last active Aug 29, 2015
Java Shared Types
View Example.java
/*
* Java Quest
* ==========
*
* Write a method in two different contexts (read: Types)
* which takes a function which returns an object of the current type.
*
* T1<A> { <B> T1<B> m(f: A -> T1<B>); }
* T2<A> { <B> T2<B> m(f: A -> T2<B>); }
*
View DefaultMethodProxyExample.java
package labs;
import java.lang.invoke.MethodHandles;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Arrays;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.stream.Collectors;
@danieldietrich
danieldietrich / StableDate.java
Last active Aug 29, 2015
A Date which is stable regarding hashCode, equals and compareTo
View StableDate.java
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
/**
* A UTC date, consisting of a year, a month and a day component. Compared to {@linkplain java.util.Date}
* a StableDate is stable regarding {@linkplain java.lang.Object#equals} and {@linkplain java.lang.Object#hashCode}.
*/
public class StableDate implements Comparable<StableDate>, Serializable {
You can’t perform that action at this time.