Skip to content

Instantly share code, notes, and snippets.

View andresteingress's full-sized avatar
🎯
Focusing

Andre Steingress andresteingress

🎯
Focusing
View GitHub Profile
@Grab(group='org.gcontracts', module='gcontracts', version='[1.1.0,)')
import org.gcontracts.annotations.Invariant
@Invariant({ firstName != null && lastName != null })
class Person {
String firstName
String lastName
def Person(final String firstName, final String lastName) {
this.firstName = firstName
@Grab(group='org.gcontracts', module='gcontracts', version='[1.1.1,)')
import org.gcontracts.annotations.*
@Invariant({ elements != null })
class Stack {
private List elements
@Ensures({ is_empty() })
public Stack() {
@andresteingress
andresteingress / gist:5370086
Created April 12, 2013 07:06
Groovy Common Extensions not found in groovyConsole and scripts
@Grapes(Grab(group='com.bloidonia', module='groovy-common-extensions', version='0.4.1'))
def f = new File('test.zip')
f.unzip(new File('test'))
@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()
}
}
@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 / 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: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: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: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: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