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 / 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 / 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 / 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 / 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 / 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 / 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 / whatsflux.md
Last active January 18, 2016 22:58
What is flux

Flux is an architecture to help client-side application deal with data coming from several endpoints (API endpoints, websockets, user interaction, etc.).

The basic idea is that you're connecting to many endpoints, and when your "connectors" catch a new piece of data, they're dispatching actions (through a dispatcher).

Reducers are listening to these actions. When they catch an event they're interested in (let's say UserReducer catches an USER_DATA_UPDATED event), they "do something" with the action. Most often, they're just storing the data attached to the action somewhere, and returning their new "state". (their state represent a portion of the global store).

Components (views, basically), on the other hand, can be connected to many reducers (or to the whole store). Thanks to a pure function (connect), you'll describe what the component properties will be for a given state of the global store. Let's say your component only needs some users data and not pricing info for instance. You'll c

@aesteve
aesteve / MainVerticle.java
Created January 19, 2016 08:57
Use Future<Void> instead of timers
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;
@aesteve
aesteve / slices.go
Created January 20, 2016 20:57
Slices (with closure)
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 / maps.go
Created January 20, 2016 21:16
Go Map exercise
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)