Skip to content

Instantly share code, notes, and snippets.

View volgar1x's full-sized avatar

Antoine Chauvin volgar1x

View GitHub Profile
interface List<T> {
Option<T> head();
List<T> tail();
int size();
<A> A bind(Function<T, A> fn, Function2<A, A, A> combine);
List<T> join(List<T> list);
static List<T> unit() {
return new List<T>() {

A Better Java

  • lambdas
  • checked exception suppression
  • struct types (scala's AnyVal)
  • proper generics (true variance à la C#, ie. in and out)
  • hygienic macros (auto getters/setters/builder/...)
  • some operator overloading (ie. BigInteger hell)
  • extension methods (in addition to default methods)
package org.heat.login.network;
import io.netty.handler.logging.LogLevel;
import io.netty.handler.logging.LoggingHandler;
import net.engio.mbassy.bus.MBassador;
import net.engio.mbassy.listener.Listener;
import net.engio.mbassy.listener.References;
import org.heat.login.network.netty.NettyLoginClient;
import org.heat.protocol.MessageReceiver;
import org.heat.protocol.messages.HelloConnectMessage;
static if (is (T == float)) {
alias ResultType = double;
} else static if (is (T == double)) {
alias ResultType = real;
} else {
static assert(false, T.stringof ~ " is not supported");
}
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
public class MethodHandlePerfs {
public static interface Task {
void run(int N) throws Throwable;
package org.heat.dofus.datacenter;
import com.google.common.collect.ImmutableSet;
import lombok.NonNull;
import lombok.Value;
import lombok.experimental.Builder;
@Value(staticConstructor = "newD2oClass")
@Builder(builderClassName = "Builder", builderMethodName = "newBuilder")
public class D2oClass {
package org.heat.shared;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Stream;
public interface Either<L, R> {
public static <L, R> Either<L, R> left(L left) { return left(left, null); }
err.visit(AuthError.<NetworkCommand>visitor()
.alreadyConnected(it -> client.write(new IdentificationFailedMessage(
(byte) IdentificationFailureReasonEnum.TOO_MANY_ON_IP.value)))
.banned(it -> client.write(new IdentificationFailedBannedMessage(
(byte) IdentificationFailureReasonEnum.BANNED.value,
it.getEnd().toEpochMilli())))
.wrongCredentials(it -> client.write(new IdentificationFailedMessage(
(byte) IdentificationFailureReasonEnum.WRONG_CREDENTIALS.value)))
@volgar1x
volgar1x / main.rs
Last active August 29, 2015 13:59 — forked from Noxivs/main.rs
use std::io::net::ip::{Ipv4Addr, SocketAddr};
use std::io::net::tcp::{TcpListener, TcpStream};
use std::io::{Acceptor, Listener, IoResult};
struct Client {
stream: TcpStream
}
DEBUG o.h.l.network.frontend.LoginClient - REGISTERED
DEBUG o.h.l.network.frontend.LoginClient - ACTIVE
DEBUG o.h.l.network.frontend.LoginClient - WRITE: org.heat.protocol.messages.ProtocolRequired@5e4e142a
DEBUG o.h.l.network.frontend.LoginClient - WRITE: org.heat.protocol.messages.HelloConnectMessage@71fe7596
DEBUG o.h.l.network.frontend.LoginClient - FLUSH
DEBUG o.h.l.network.frontend.LoginClient - RECEIVED: org.heat.protocol.messages.BasicPingMessage@6835c0b0