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
// g100pon #54 duck typing | |
class Dog { | |
void cry() { println "Bowwow!" } | |
} | |
class Cat { | |
void cry() { println "Meow!" } | |
} | |
// DogとCatは共通のスーパークラスもインタフェースも持たないが、以下のように扱える(Javaでは無理) |
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
// g100pon #80 webサーバ(Jetty) | |
// groovyletとテンプレートにも対応した超簡易webアプリケーションサーバ | |
@Grab('org.eclipse.jetty:jetty-server:7.0+') | |
@Grab('org.eclipse.jetty:jetty-servlet:7.0+') | |
import org.eclipse.jetty.server.* | |
import org.eclipse.jetty.server.handler.* | |
import org.eclipse.jetty.servlet.* | |
import groovy.servlet.* | |
server = new Server(8080) |
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
// g100pon #25 tail -f | |
def input | |
if (args.size()) { | |
def file = new File(args[0]) | |
input = new FileReader(file) | |
def pos = file.size() - 80 * 10 // 十行分(かなり適当) | |
if (pos > 0) { | |
input.skip(pos) // ラスト10行あたりまでスキップ | |
input.readLine() // 中途半端な行を空読み |
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
// g100pon #73 AntBuilder | |
// AntBuilderによるファイルダウンロードと解凍 | |
def file = 'groovy-binary-1.7.5.zip' | |
def url = "http://dist.groovy.codehaus.org/distributions/$file" | |
new AntBuilder().with { | |
get(src:url, dest:'.') | |
unzip(src:"./$file", dest:'.') | |
} |
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
String.metaClass.hello = { "Hello, $delegate!" } | |
println "Groovy".hello() |
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('org.twitter4j:twitter4j:2.2.5') | |
@Grab('org.twitter4j:twitter4j-stream:2.2.5') | |
import twitter4j.* | |
def stream = new TwitterStreamFactory().instance | |
def listener = [ | |
onStatus: { st -> println "$st.user.screenName: $st.text" }, | |
onException: { ex -> ex.printStackTrace() }, | |
] as UserStreamAdapter | |
stream.addListener(listener) |
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
// TimeCategory | |
import groovy.time.TimeCategory | |
// 日時計算のための便利なカテゴリ | |
use (TimeCategory) { | |
println 10.hours.ago | |
println 3.days.from.today | |
println 1.year.from.now | |
println((1.minute + 30.seconds).from.now) | |
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 groovyx.javafx.* | |
key = '<YOUR Google+ API KEY HERE>' | |
uid = 110611905999186598367 // user ID | |
url = "https://www.googleapis.com/plus/v1/people/$uid?key=$key".toURL() | |
json = new groovy.json.JsonSlurper().parseText(url.text) | |
GroovyFX.start { | |
def sg = new SceneGraphBuilder() |
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 groovyx.javafx.* | |
GroovyFX.start { | |
def sg = new SceneGraphBuilder() | |
sg.stage(title: "MediaView Demo", width: 640, height: 380, visible: true) { | |
scene(fill: black) { | |
mview = mediaView(fitWidth: 640, fitHeight: 380) { | |
player(autoPlay: true, source: "<URL to movie file(.flv)>") | |
transition = parallelTransition { |
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('org.twitter4j:twitter4j:2.2.5') | |
@Grab('org.twitter4j:twitter4j-stream:2.2.5') | |
import twitter4j.* | |
import groovyx.javafx.* | |
import javafx.scene.control.* | |
import javafx.scene.media.* | |
import javafx.application.Platform | |
final HOTWORD = /(?i)groovy/ |