Skip to content

Instantly share code, notes, and snippets.

View aesteve's full-sized avatar
👋

Arnaud Esteve aesteve

👋
  • Sant Cugat del Vallès, Barcelona, Catalonia, Spain
  • X @arnaudesteve
View GitHub Profile
@aesteve
aesteve / intercept.groovy
Created January 11, 2016 13:15
Standard interceptors ?
class Decorated {
@Intercepted(MyInterceptor.class)
def intercepted(String something) {
println "within method"
}
}
class MyInterceptor implements Interceptor {
@aesteve
aesteve / removeChar.groovy
Created January 8, 2016 11:46
"Write a method which will remove any given character from a String"
// "Write a method which will remove any given character from a String"
// The method will be the 'minus' method 'some string ' - 's' == 'ome tring'
def check() {
assert 'some string' - 's' == 'ome tring'
assert '' - 'a' == ''
assert 'something else' - 'z' == 'something else'
}
// Easy one
@aesteve
aesteve / palindrom.groovy
Created January 8, 2016 11:29
Palindrom
CharSequence.metaClass.getLowerStripped = {
delegate.toLowerCase().replaceAll(/\s/, '')
}
def check() {
assert !''.palindrom
assert !'palindrom'.palindrom
assert 'madam'.palindrom
assert 'Evil is a name of foeman as I live'.palindrom
}
@aesteve
aesteve / fizzbuzz.groovy
Last active January 8, 2016 10:42
FizzBuzz with meta-programming (for fun only)
Integer.metaClass.getBuzzOrFizz = {
String str= ''
if (delegate % 3 == 0) {
str += 'Fizz'
}
if (delegate % 5 == 0) {
str += 'Buzz'
}
if (!str) {
return delegate.toString()
@aesteve
aesteve / profile
Created January 1, 2016 23:09
add JAVA_HOME (/etc/profile)
export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:bin/javac::")
@aesteve
aesteve / MyAsyncTest.groovy
Created December 31, 2015 09:38
async bdd unit runner
class MyAsyncSpec {
@Test
void asyncTestRequest(TestContext context) {
// startsWith async => creates context.async()
def client
setup {
client = vertx.createHttpClient(...)
}
when {
client.getNow('/api')
@aesteve
aesteve / AuthorizationLogic.java
Created December 15, 2015 13:18
centralize auth logic
public static authorize(JsonObject authInfo, Handler<User> onAuthorized, Handler<Throwable> onFailure) {
return res -> {
if (res.succeeded()) {
User user = res.result();
user.isAuthorised("newsletter:edit:13", res2 -> {
if (res2.succeeded()) {
boolean hasPermission = res2.result();
if(hasPermission){
onAuthorized.handle(user);
}
import io.vertx.core.Handler
import io.vertx.groovy.ext.unit.Async
import io.vertx.groovy.ext.unit.TestContext
import io.vertx.groovy.ext.unit.junit.VertxUnitRunner
import org.junit.runner.RunWith
@RunWith(VertxUnitRunner.class)
abstract class GroovyTestBase {
public GroovyTestBase() {
@aesteve
aesteve / Perf example
Created July 10, 2015 08:36
Some example on what we could benchmark
// create an object
public class SomeObject {
public Date someDate;
public Integer someInt;
public String someString;
public Double someDouble;
}
// create vertx handler
router.put("/vertx", ctx -> {
@aesteve
aesteve / build.gradle
Created April 3, 2015 16:41
vertx-metrics-demo Gradle
plugins {
id 'java'
id 'eclipse'
id 'idea'
id 'com.github.johnrengelman.shadow' version '1.2.1'
}
repositories {
mavenLocal()
mavenCentral()