Skip to content

Instantly share code, notes, and snippets.

🇫🇷

Arnaud Esteve aesteve

🇫🇷
  • Lille
Block or report user

Report or block aesteve

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
@aesteve
aesteve / JSXTransform
Last active Apr 9, 2018
Transforming JSX with nashorn
View JSXTransform
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
View CheckParams.java
public interface RouteDSL {
RouteDSL param(String paramName, Handler<RoutingContext> checker)
default<T> RouteDSL param(String paramName, Function<String, T> checker) {
return param(paramName, ctx -> {
String p = ctx.request().getParam(name);
try {
ctx.put(paramName, checker.apply(p));
ctx.next();
@aesteve
aesteve / HandlerExtension.kt
Created Oct 11, 2016
Extension method in Kotlin to handle a method reference as a Handler
View HandlerExtension.kt
// It's weird it doesn't work ootb since Handler<T> is a functional java interface
// I must have missed something
fun <T> asHandler(handler: (T) -> Unit): Handler<T> =
Handler { event -> handler(event) }
@aesteve
aesteve / InterceptorExample.java
Created Oct 11, 2016
Creating interceptor-like logic just with handlers
View InterceptorExample.java
public class InterceptorExample extends AbstractVerticle {
public final static String API_PATH = "/api/v1/";
public final static String STATIC_FILES = "/static/";
// ...
private Router router;
@Override
public void start(Future<Void> future) {
@aesteve
aesteve / WhatWeCouldDo.groovy
Last active May 24, 2016
AST transform on AsyncResult methods
View WhatWeCouldDo.groovy
// Let's imagin you have such a service
class TodoMongoService {
void fetchById(String todoId, Handler<AsyncResult<Todo>> handler) {
mongo.find(id) { res ->
if(res.succeeded) {
handler.handle(Future.suceededFuture(res.result))
} else {
handler.handle(Future.failedFuture(res.cause))
}
}
@aesteve
aesteve / Uh oh
Created May 8, 2016
exception happening on CI only while testing Nubes with 3.3.0-SNAPSHOT
View Uh oh
java.lang.IllegalStateException: Uh oh! Event loop context executing with wrong thread! Expected null got Thread[Test worker,5,main]
at io.vertx.core.impl.ContextImpl.lambda$wrapTask$3(ContextImpl.java:343)
at io.vertx.core.impl.ContextImpl.executeFromIO(ContextImpl.java:240)
at io.vertx.core.http.impl.ConnectionManager$ConnQueue.http1xConnected(ConnectionManager.java:422)
at io.vertx.core.http.impl.ConnectionManager$ConnQueue.lambda$internalConnect$159(ConnectionManager.java:384)
at io.vertx.core.http.impl.ConnectionManager$ConnQueue$1.lambda$connect$157(ConnectionManager.java:282)
at io.vertx.core.net.impl.AsyncResolveBindConnectHelper.addListener(AsyncResolveBindConnectHelper.java:43)
at io.vertx.core.http.impl.ConnectionManager$ConnQueue$1.connect(ConnectionManager.java:280)
at io.vertx.core.http.impl.ConnectionManager$ConnQueue.internalConnect(ConnectionManager.java:395)
at io.vertx.core.http.impl.ConnectionManager$ConnQueue.createNewConnection(ConnectionManager.java:226)
View Handlers.java
List<Handler<RoutingContext>> handlers = /* ... */;
handlers.forEach(router.route("/a/b/")::handler); // KO : "You're attaching a handler to a route more than once"
handlers.forEach(handler -> router.route("/a/b").handler(handler)); // works
@aesteve
aesteve / maps.go
Created Jan 20, 2016
Go Map exercise
View maps.go
package main
import (
"golang.org/x/tour/wc";
"strings";
)
func WordCount(s string) map[string]int {
count := make(map[string]int)
words := strings.Fields(s)
@aesteve
aesteve / slices.go
Created Jan 20, 2016
Slices (with closure)
View slices.go
package main
import "golang.org/x/tour/pic"
func mult(x, y int) uint8 {
return uint8( x * y )
}
func mid(x, y int) uint8 {
return uint8( (x + y) / 2 )
@aesteve
aesteve / MainVerticle.java
Created Jan 19, 2016
Use Future<Void> instead of timers
View MainVerticle.java
package com.github.vertx.node.example;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Vertx;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;
You can’t perform that action at this time.