This file contains 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
println "Hello ${args.join(',')}." |
This file contains 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
Object.metaClass { | |
//indent | |
indent << {String indentString, int indentLevel, boolean skipIndent -> | |
(indentString * (skipIndent ? 0 : indentLevel)) + delegate | |
} | |
//prettyPrint | |
prettyPrint << { -> | |
delegate.prettyPrint(' ') | |
} | |
prettyPrint << {String indentString -> |
This file contains 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
@Grapes( | |
@Grab(group='org.glassfish', module='javax.json', version='1.0.2') | |
) | |
import groovy.json.DateFormatThreadLocal | |
import groovy.json.JsonBuilder | |
import groovy.json.JsonDelegate | |
import java.text.SimpleDateFormat | |
import javax.json.Json |
This file contains 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
@Grapes( | |
@Grab(group='org.glassfish', module='javax.json', version='1.0.2') | |
) | |
import java.io.FileReader | |
import javax.json.Json | |
import javax.json.JsonArray | |
import javax.json.JsonBuilderFactory | |
import javax.json.JsonNumber | |
import javax.json.JsonObject | |
import javax.json.JsonReader |
This file contains 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 groovy.lang.Binding; | |
import groovy.lang.GroovyShell; | |
import groovy.lang.Script; | |
import java.io.File; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.Map; | |
/** |
This file contains 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
@Grapes([ | |
@Grab("org.apache.pivot:pivot-core:2.0"), | |
@Grab("org.apache.pivot:pivot-wtk:2.0"), | |
@Grab("org.apache.pivot:pivot-wtk-terra:2.0") | |
]) | |
import org.apache.pivot.wtk.* | |
//メソッドはバインディング変数(クロージャ)で作成しないといけない | |
createLabel = { window -> | |
def label = new Label() |
This file contains 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
@GrabResolver(name='gretty', | |
root='http://groovypp.artifactoryonline.com/groovypp/libs-releases-local') | |
@Grab('org.mbte.groovypp:gretty:0.4.302') | |
import org.mbte.gretty.httpserver.GrettyServer | |
//Grettyのサンプル - 割り勘計算機 | |
// http://localhost:8080/[割られる数]/[割る数] -> 割り算の結果を返す | |
// http://localhost:8080/[メッセージ] -> 'Hello, [メッセージ]!'を返す | |
//割り算の結果を返す | |
def createDivResponse = { p -> | |
def calcResult = p.dividend.toBigDecimal() / p.divisor.toBigDecimal() |
This file contains 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
//JsonSlurperのサンプル | |
import groovy.json.JsonOutput | |
import groovy.json.JsonSlurper | |
//JSON文字列 | |
def text = '''{ | |
"people": { | |
"person": { | |
"firstName": "Yasuharu", | |
"lastName": "Hayami", |
This file contains 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
//StreamingJsonBuilderのサンプル | |
import groovy.json.JsonOutput | |
import groovy.json.StreamingJsonBuilder | |
def data = { | |
people { | |
person { | |
firstName 'Yasuharu' | |
lastName 'Hayami' | |
// Named arguments are valid values for objects too |
This file contains 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
//JsonBuilderを使う際に間違いやすい部分のサンプル | |
def json = new groovy.json.JsonBuilder() | |
//サンプル1 | |
json numbers:[1,2,4] | |
def sample1 = json.toString() | |
println sample1 | |
//サンプル2 | |
json { numbers 1,2,4 } |
NewerOlder