Skip to content

Instantly share code, notes, and snippets.

Christoph Dähne christoph-daehne

Block or report user

Report or block christoph-daehne

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
View BetterBouquetDsl.groovy
// our configuration model
class BouquetConfiguration extends ArrayList<String> {
int howMany(String flower) {
return this.count { it == flower }
}
String toString() {
return "Bouquet: " + this.toString()
}
@christoph-daehne
christoph-daehne / BouquetDsl.groovy
Last active Aug 29, 2015
Groovy DSL example: Bouquet
View BouquetDsl.groovy
// our configuration model
class BouquetConfiguration {
private final List<String> flowers = []
// method for use at runtime
int howMany(String flower) {
return flowers.count { it == flower }
}
// DSL keyword for use at DSL execution
@christoph-daehne
christoph-daehne / HighlightedHelloWorldDsl.groovy
Last active Oct 20, 2016
Highlighted Groovy DSL example: Hello World
View HighlightedHelloWorldDsl.groovy
class HelloWorldService {
void printHelloWorld() {
println("Hello World")
}
}
class HelloWorldScript {
// by annotating the parameter we gain syntax highlighting and auto-completion
static void execute(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = HelloWorldService) Closure script) {
script.resolveStrategy = Closure.DELEGATE_FIRST
@christoph-daehne
christoph-daehne / HelloWorldDsl.groovy
Last active Aug 29, 2015
Groovy DSL example: Hello World
View HelloWorldDsl.groovy
class HelloWorldService {
// this function becomes a keyword in our DSL
void printHelloWorld() {
println("Hello World")
}
}
class HelloWorldScript {
static void execute(Closure script) {
// here we wire the colure with the service
View gist:f370c9a49dd7d67f9420
assertEquals "incorrect nickname", 'alice', 'alice-wrong'
// we get:
// incorrect nickname expected:<alice[]> but was:<alice[-wrong]>
View IMAPExample.java
package de.sandstormmedia;
import com.sun.mail.imap.IMAPFolder;
import javax.mail.*;
import java.util.Properties;
/**
* This example prints all messages (emails) from an IMAP-folder to the console.
* <p/>
You can’t perform that action at this time.