This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
assertEquals "incorrect nickname", 'alice', 'alice-wrong' | |
// we get: | |
// incorrect nickname expected:<alice[]> but was:<alice[-wrong]> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// our configuration model | |
class BouquetConfiguration extends ArrayList<String> { | |
int howMany(String flower) { | |
return this.count { it == flower } | |
} | |
String toString() { | |
return "Bouquet: " + this.toString() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BouquetConfiguration extends ArrayList<String> { | |
int howMany(String flower) { | |
return this.count { it == flower } | |
} | |
String toString() { | |
return "Bouquet: " + this.toString() | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// our configuration model | |
class BouquetConfiguration extends ArrayList<String> { | |
int howMany(String flower) { | |
return this.count { it == flower } | |
} | |
String toString() { | |
return "Bouquet: " + this.toString() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Grab(group='io.reactivex', module='rxjava-reactive-streams', version='0.5.0') | |
import rx.Observable | |
def in1 = Observable.from([1, 3, 5]).map { a -> a - 1 } | |
def in2 = Observable.from([2, 4, 6]).map { a -> a - 1 } | |
def in3 = Observable.error(new Exception("BAM!")) | |
def sumTimes2 = Observable.zip(in1, in2) { a, b -> | |
a + b | |
}.map { a -> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.github.jknack.handlebars.Context | |
import com.github.jknack.handlebars.Helper | |
import com.github.jknack.handlebars.Options | |
/** | |
* filters a list and adds a variable to the context | |
* | |
* options: | |
* - assignTo: name of the variable to add to the context | |
* - field: (optional) filter by "trueness" of the given property (this is default) |
OlderNewer