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
from datetime import datetime | |
datestr = {0:%Y%m%d_%H%M%S}'.format(datetime.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 os | |
csv_dir='./' | |
l:list = list(filter(lambda x: x.endswith('.py'), os.listdir(path=csv_dir))) | |
l.sort (key=lambda x: int(os.path.getctime(csv_dir + '/' + x)), | |
reverse=True) | |
print(l) |
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
public class CloseTest { | |
public static void main(String... args) { | |
try (TestResource rs = new TestResource()){ | |
System.out.println("try:start"); | |
throw(new Exception()); | |
} catch (Exception e) { | |
System.out.println("catch:start"); | |
e.printStackTrace(); | |
System.out.println("catch:end"); | |
} finally { |
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
@Memoized | |
def fibo(n) { | |
def result = (n == 0 || n == 1) ? 1G : fibo(n - 2) + fibo(n - 1) | |
println "$n: $result" | |
result | |
} | |
println "result:" + fibo(5) |
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 s = 'Go! ' | |
assert s * 3 == 'Go! Go! Go! ' | |
// 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
// Case #1 | |
// 複数行の文字列(改行を含んだ文字列)を定義するには"""を使う。 | |
def name = "文字列" | |
def str = """こんにちは | |
${name}さん | |
複数行に渡る | |
文字列です。""" |
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
def str="1" | |
// Case #1 | |
// 0埋めの文字列として出力する | |
assert "001"==str.padLeft(3, "0") | |
// Case #2 | |
// 空白文字で左埋めするには(埋める文字列を指定しないと空白になる) | |
assert " 1"==str.padLeft(3) |
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 | |
// 文字列の末尾から何文字目までを取り出す(BasicのRight関数の動き) | |
def rightStr(String string, int cutLength) { | |
string.substring(string.length() - cutLength) | |
} | |
assert rightStr("12345678",3) == "678" | |
// Case #2 | |
// 文字列の末尾から何文字目までを取り出す。Stringにメソッド追加。 |
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 | |
// 文字列の先頭から何文字目までを取り出す(BasicのLEFT関数の動き) | |
def leftStr(String string, int length) { | |
string.substring(0, length) | |
} | |
assert leftStr("12345678",3) == "123" | |
// 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
// Case #1 | |
// 階乗(n!)を計算する(再帰バージョン) | |
def BigInteger fact(n) { | |
if (n == 0) return 1 | |
return n * fact(n - 1) | |
} | |
// 4! = 24 | |
assert fact(4) == 24 |
NewerOlder