Skip to content

Instantly share code, notes, and snippets.

View andresteingress's full-sized avatar
🎯
Focusing

Andre Steingress andresteingress

🎯
Focusing
View GitHub Profile
@andresteingress
andresteingress / gist:11226958
Created April 23, 2014 18:22
ConditionalOnExpression - A conditional EhCache manager configuration
@Configuration
@EnableCaching
@ConditionalOnExpression("${spring.cacheable.cache}")
public class EhCacheConfiguration {
@Autowired
private net.sf.ehcache.CacheManager cacheManager;
@Bean(name = "cacheManager")
public CacheManager ehCacheCacheManager()
@andresteingress
andresteingress / gist:9697217
Last active August 29, 2015 13:57
Memoizer in JDK 8
public class Memoizer {
public static class MemoizeFunction<T, R> implements Function<T, R> {
private final Map<List, R> cache = new HashMap<>();
private final Function<T, R> function;
public MemoizeFunction(Function<T, R> function) {
Objects.requireNonNull(function);
this.function = function;
@andresteingress
andresteingress / gist:9685650
Last active August 29, 2015 13:57
TestHelper's shouldFail in JDK 8
import java.util.Arrays;
import java.util.List;
public class TestHelper {
public static Throwable shouldFail(Runnable code) {
try {
code.run();
} catch (Throwable ex) {
return ex;
@andresteingress
andresteingress / gist:9588171
Last active August 29, 2015 13:57
Andrey's JSON Benchmark - Results
Benchmark Mode Thr Count Sec Mean Mean error Units
g.j.Benchmark.complexTestBoon thrpt 1 20 1 16050.900 232.105 ops/s
g.j.Benchmark.complexTestGroovy thrpt 1 20 1 1132.776 29.978 ops/s
g.j.Benchmark.complexTestGson thrpt 1 20 1 6149.003 111.183 ops/s
g.j.Benchmark.complexTestJackson thrpt 1 20 1 15056.591 307.194 ops/s
g.j.Benchmark.complexTestNewGroovy thrpt 1 20 1 12886.050 113.192 ops/s
g.j.Benchmark.javaObjectsTestGroovy thrpt 1 20 1 18.706 0.207 ops/s
g.j.Benchmark.javaObjectsTestGson thrpt 1 20 1 188.108 3.821 ops/s
g.j.Benchmark.javaObjectsTestJackson thrpt 1 20 1 353.901 5.103 ops/s
@andresteingress
andresteingress / gist:9278441
Created February 28, 2014 19:49
Groovy - Getting Closure Shared Variable Names
// convert a method name to a variable name (remove ‘get’ and uncapitalize)
def toVariableName = { String methodName ->
if (!methodName || !methodName.startsWith('get')) return methodName
def variableName = methodName - 'get'
return "" + Character.toLowerCase(variableName.charAt(0)) + variableName.substring(1);
}
// some closure shared variables
def x = 42
@andresteingress
andresteingress / gist:9140595
Last active August 29, 2015 13:56
Json Parser Benchmark
Result : 567399.330 ?(99.9%) 4926.983 ops/s
Statistics: (min, avg, max) = (555682.417, 567399.330, 576296.450), stdev = 6156.507
Confidence interval (99.9%): [562472.347, 572326.313]
Benchmark Mode Thr Count Sec Mean Mean error Units
g.j.Benchmark.characterJsonParserGroovy thrpt 1 20 1 567399.330 4926.983 ops/s
g.j.Benchmark.fastJsonParserGroovy thrpt 1 20 1 584611.082 18457.878 ops/s
g.j.Benchmark.parserGson thrpt 1 20 1 271117.797 6513.312 ops/s
g.j.Benchmark.parserJackson thrpt 1 20 1 243472.297 1353.115 ops/s
@andresteingress
andresteingress / gist:8687069
Last active January 4, 2016 22:19
Cucumber Grails integration
/**
* Enables code completion for Geb inside Cucumber step implementations.
*/
def forwardedMethods = ["go", "to", "via", "at",
"waitFor",
"withAlert", "withNoAlert", "withConfirm", "withNoConfirm",
"download", "downloadStream", "downloadText", "downloadBytes", "downloadContent",
"report", "reportGroup", "cleanReportGroupDir"]
def scriptContext = context(filetypes: ['.groovy'], pathRegexp: ".*/test/cucumber/.*", scope: closureScope())
@andresteingress
andresteingress / gist:8595350
Created January 24, 2014 10:53
my personal clj wordpress to jekyll import
(ns clj-wp-import.core
(:require [clojure.java.io :as jio]
[clojure.string :as str]))
(defn post-files
[f]
(file-seq (jio/file f)))
(defn remove-pre-code
[txt]
@andresteingress
andresteingress / gist:6905156
Created October 9, 2013 17:40
Groovy Continuations
def factorial
factorial = { n, c ->
if (n == 1)
c(1)
else
factorial(n - 1, { m -> c(n * m) })
}
def result = null
factorial(4, { x -> result = x })
@andresteingress
andresteingress / SwingBuilderTestCaseUtils.groovy
Last active December 16, 2015 06:19
Another reason to love Groovy.
@BeforeClass void setup() {
SwingUtilities.metaClass.static.invokeLater = { Runnable runnable ->
runnable.run()
}
Thread.metaClass.static.start = { Runnable runnable ->
runnable.run()
}
}