Skip to content

Instantly share code, notes, and snippets.

import groovy.transform.*
class Event {
int version
}
@Immutable class ItemActivated extends Event {
int id
}
@bodiam
bodiam / switch.sh
Created July 10, 2014 11:28
Switch Java version
export JAVA_HOME=$(/usr/libexec/java_home -v 1.6)
@bodiam
bodiam / NoStackTrace.groovy
Created July 29, 2014 20:46
Using a Groovy Trait to make exceptions usable for flow control.
@Grab(group='org.gperfutils', module='gbench', version='0.4.2-groovy-2.1')
import java.lang.String
trait NoStackTrace {
Throwable fillInStackTrace() {
return this
}
}
class ExpensiveException extends RuntimeException { }
@Grab(group = "org.twitter4j", module = "twitter4j-core", version = "4.0.2")
import twitter4j.*
Twitter twitter = new TwitterFactory().instance
def user = twitter.verifyCredentials()
println "Nb followers de ${user.name} (alias ${user.screenName}) : ${user.followersCount}"
long cursor = -1
def followers = twitter.getFollowersList(user.screenName, cursor, 200)
followers.each {println "${it.screenName} - ${it.name}"}
void "test filter with find on name"() {
setup:
new Conference(
name: 'test',
startdate: new Date()
).save(flush: true)
expect:
service.filterConferences(new FilterCommand(name: name)).size() == expected
@Grab(group='org.gperfutils', module='gbench', version='0.4.2-groovy-2.1')
import java.lang.String
trait NoStackTrace {
Throwable fillInStackTrace() {
return this
}
}
class ExpensiveException extends RuntimeException { }
@bodiam
bodiam / benchmark.java
Created November 22, 2014 23:32
AsciiDoc benchmark for JDK 1.6 and JDK 1.8
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
import java.io.FileReader;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException, ScriptException {
ScriptEngineManager manager = new ScriptEngineManager();
@bodiam
bodiam / asciidoc.css
Last active August 29, 2015 14:19 — forked from imjasonh/markdown.css
Render HTML as unrendered Asciidoc - See http://jsbin.com/mifepiqosa/1/edit?html,css,output
* {
font-size: 12pt;
font-family: monospace;
font-weight: normal;
font-style: normal;
text-decoration: none;
color: black;
cursor: default;
}
@bodiam
bodiam / gist:5998377
Last active December 19, 2015 18:28 — forked from erdi/gist:5998112
Gradle script to prints the file location of the produced artifact. Can be put in ~/.gradle/init.gradle so it can be used across projects.
allprojects {
tasks.withType(AbstractArchiveTask) { task ->
outputs.upToDateWhen { false }
task.doLast {
println "\nOutput location: ${archiveName}\n"
}
}
}
@bodiam
bodiam / gist:5999047
Last active December 19, 2015 18:29
Marcin is a crazy fish.
def artifacts = []
addListener(new TaskExecutionAdapter() {
void afterExecute(Task task, TaskState state) {
if(task in AbstractArchiveTask) {
artifacts << task.outputs.files.singleFile
}
}
})