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 / intercept.groovy
Created Jan 11, 2016
Standard interceptors ?
View intercept.groovy
class Decorated {
@Intercepted(MyInterceptor.class)
def intercepted(String something) {
println "within method"
}
}
class MyInterceptor implements Interceptor {
@aesteve
aesteve / removeChar.groovy
Created Jan 8, 2016
"Write a method which will remove any given character from a String"
View removeChar.groovy
// "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
View palindrom.groovy
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 Jan 8, 2016
FizzBuzz with meta-programming (for fun only)
View fizzbuzz.groovy
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 Jan 1, 2016
add JAVA_HOME (/etc/profile)
View profile
export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:bin/javac::")
@aesteve
aesteve / MyAsyncTest.groovy
Created Dec 31, 2015
async bdd unit runner
View MyAsyncTest.groovy
class MyAsyncSpec {
@Test
void asyncTestRequest(TestContext context) {
// startsWith async => creates context.async()
def client
setup {
client = vertx.createHttpClient(...)
}
when {
client.getNow('/api')
View AuthorizationLogic.java
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);
}
View GroovyTestBase.groovy
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 Jul 10, 2015
Some example on what we could benchmark
View Perf example
// 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 Apr 3, 2015
vertx-metrics-demo Gradle
View build.gradle
plugins {
id 'java'
id 'eclipse'
id 'idea'
id 'com.github.johnrengelman.shadow' version '1.2.1'
}
repositories {
mavenLocal()
mavenCentral()
You can’t perform that action at this time.