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
String getSHA1(String source) { | |
java.security.MessageDigest md = java.security.MessageDigest.getInstance('SHA-1') | |
md.update(source.getBytes('UTF-8')) | |
md.digest().collect{ String.format('%02x', it) }.join() | |
} | |
def list = (1..10).collect{ | |
[it, getSHA1(it.toString())] | |
} | |
println list |
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
def template = '○○と●●●は違う' | |
def list = ['○○', '●●●'] | |
def translator = list.inject([:]){ result, item -> result[item] = getList(item); result } | |
// こうなる↓ | |
//def translator = [ | |
// '○○' : ['1', '2', '3', '4', '5'], | |
// '●●●' : ['あああ', 'いいい', 'ううう', 'えええ', 'おおお'] | |
//] |
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 hatenahaiku4j.* | |
api = new HatenaHaikuAPILight() | |
str = """ | |
def konna = api.getHotKeywordList().first() | |
def konnaUsers = konna.api.getTimeline()*.user | |
def konnaKeyword = konnaUsers.collect{ | |
it.api.getTimeline()*.keyword | |
}.flatten().unique() |
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
// http://ja.wikipedia.org/wiki/特別:おまかせ表示 | |
def url = 'http://ja.wikipedia.org/wiki/%E7%89%B9%E5%88%A5:%E3%81%8A%E3%81%BE%E3%81%8B%E3%81%9B%E8%A1%A8%E7%A4%BA' | |
def html = new URL(url).getText('UTF-8') | |
def word = html.replaceAll(/(?s)^.+<title>| - Wikipedia<\/title>.+$/, '') | |
println word |
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 HelloWorld { | |
def main(args: Array[String]): Unit = { | |
System.out.println("Hello, scala!") | |
} | |
} |
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
scala> val list = List(1, 2, 3) | |
list: List[Int] = List(1, 2, 3) | |
scala> val List(a, b, c) = list | |
a: Int = 1 | |
b: Int = 2 | |
c: Int = 3 | |
scala> a | |
res1: Int = 1 |
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
def prop = new Properties() | |
new File('/temp.properties.xml').withInputStream{ inStream -> | |
prop.loadFromXML(inStream) | |
} | |
prop.each { | |
println "${it.key} => ${it.value}" | |
} |
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, World!!' |
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
def getBytes(str, encode) { | |
str.getBytes(encode).collect{ | |
"0x${Integer.toHexString(it & 0xff)}" | |
} | |
} | |
assert getBytes('\uff5e', 'Windows-31J') == ['0x81', '0x60'] |
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
/* | |
* Copyright 2002-2007 the original author or authors. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software |