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
// Case #1 | |
// 2乗を計算する | |
// 5^2 = 25 | |
// 引数も結果も Double | |
assert Math.pow(5, 2) == 25 | |
// Case #2 | |
// 累乗(N の M 乗)を計算する |
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
// Case #1 | |
// 10進数を16進数にする | |
assert Integer.toHexString(129) == '81' | |
// Case #2 | |
// 10進数を2進数にする | |
assert Integer.toBinaryString(129) == '10000001' |
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
// Case #1 | |
// 短縮URLを展開する | |
// 短縮URLが存在しない場合には、groovyx.net.http.HttpResponseException をthrowする | |
import groovyx.net.http.HttpURLClient | |
assert 'https://gyakubiki-groovy.rhcloud.com/' == expandURL("http://bit.ly/gyakubikigroovy") | |
public String expandURL(String urlStr) { | |
HttpURLClient http = new HttpURLClient(followRedirects:false) |
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
// Case #1 | |
// URIエスケープする(URLエンコードとかURIエスケープとか言われたりする) | |
def str = 'http://www.asahi.com/q="test aaa&1344"' | |
def result = new URLEncoder().encode(str) | |
assert result == 'http%3A%2F%2Fwww.asahi.com%2Fq%3D%22test+aaa%261344%22' | |
// Case #2 |
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
println expandURL("http://j.mp/dankogai") | |
public String expandURL(String urlStr) { | |
HttpURLClient http = new HttpURLClient(followRedirects:false) | |
def params = [ url:urlStr, | |
headers:['User-Agent':'Mozilla/5.0'] ] | |
def resp = http.request( params ) | |
return resp.headers.'Location' | |
} |
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 org.eiji.list | |
// Case #1 | |
// リストを空にする | |
def list1 = ['a', 'b', 'c'] | |
list1.clear() | |
assert list1 == [] |
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
Last Updated: February 28, 2013 | |
Yammer Privacy Statement | |
Microsoft and the Yammer team are committed to protecting your privacy. This privacy statement applies to the data collected by Microsoft through use of Yammer services (the “Service” or “Services”); it does not apply to other online or offline Microsoft sites, products, or services. | |
Yammer Networks | |
A “Yammer Network” is the network for using the Services defined by your organization’s email domain. For example, all users who sign up with a “contoso.com” email address would be part of the Contoso Yammer Network. In addition, a company may invite users with different email domain names to their Yammer Network as “guest users” or as participants in external networks associated with that Yammer Network. |
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
// Case #1 | |
// マップに要素を追加する | |
def map1 = [:] | |
map1.put('犬1', 'taro') | |
map1.put('猫1', 'tama') | |
map1['犬2'] = 'jiro' | |
println map1 |
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
// Case #1 | |
// リスト要素の順列組合せを得る | |
def list1 = ['a', 'b', 'c'] | |
def list2 = list1.permutations() | |
// Collections.permutations() の結果は HashSet になるので、比較のために ArrayListに変換している | |
assert list2 as ArrayList == [['c', 'b', 'a'], ['a', 'c', 'b'], ['c', 'a', 'b'], | |
['b', 'c', 'a'], ['b', 'a', 'c'], ['a', 'b', 'c']] |
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
// Case #1 | |
// リストからランダムに1つだけ要素を選ぶ | |
def list1 = ['a', 'b', 'c', 'd'] | |
def item = list1[new Random().nextInt(list1.size())] | |
println item | |
// 実行結果例(実行する度に結果が異なる) | |
// c |