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
// g100pon #50 回帰分析 | |
// y = intercept + slope * x | |
// see: http://commons.apache.org/math/userguide/stat.html | |
@Grab(group='commons-math', module='commons-math', version='1.2') | |
import org.apache.commons.math.stat.regression.SimpleRegression | |
def reg = new SimpleRegression() |
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
// g100pon #29 growlみたいなの | |
// telnet等で50000番に接続し、メッセージを送信すると、タスクトレイから表示されます。 | |
// Icon画像は適当に用意して下さい。 | |
// (いろいろバグが残っていますが、ご笑納ください。。。) | |
// | |
// 参考リンク: | |
// http://www.javainthebox.net/laboratory/JavaSE6/trayicon/trayicon.html | |
// http://marcinfo.blogspot.com/2007/01/groovy-in-system-tray-as-of-java-1.html |
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
// g100pon #42 お手軽JMXビューア | |
// 詳細は以下の文献を参照するとよいです | |
// http://groovy.codehaus.org/Groovy+JmxBuilder | |
// http://groovy.codehaus.org/Groovy+and+JMX | |
// http://download.oracle.com/javaee/1.4/api/javax/management/MBeanServerConnection.html | |
// http://www.javainthebox.net/laboratory/J2SE1.5/MonitoringAndManagement/JMX/JMX2.html | |
import groovy.jmx.builder.* | |
// MBean Serverに接続 |
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
// g100pon #49 閏年 | |
// see http://d.hatena.ne.jp/orangeclover/20091225/1261752620 for detailed | |
def isLeapYear(int year){ | |
Calendar.getInstance().isLeapYear(year) | |
} | |
assert isLeapYear(2000) == true | |
assert isLeapYear(1900) == false | |
assert isLeapYear(1996) == true |
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
// g100pon #74 日付の解析とフォーマット | |
def date = new Date().parse('yyyy/MM/dd HH:mm:ss', '2010/10/10 18:59:59') | |
assert date.class.name == 'java.util.Date' | |
assert date.format('yyyy/MM/dd HH:mm:ss') == '2010/10/10 18:59:59' |
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
// g100pon #92 TimeCategory | |
def now = new Date() | |
use (groovy.time.TimeCategory) { | |
//このクロージャの内部のみ、Integer型にメソッドが追加されたことになる | |
//例えば以下のようにして9時間5分後を求めることが可能 | |
tgt = now + 9.hours + 5.minutes | |
} |
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
// g100pon #77 CliBuilder | |
def cli = new CliBuilder(usage:'groovy CliBuilderSample.groovy -f filename [-d]') | |
cli.h(longOpt:'help', 'ヘルプ') | |
cli.f(longOpt:'file', required:true, args:1, '処理対象ファイル名') | |
cli.d(longOpt:'debug', 'デバッグモード') | |
def options = cli.parse(args) |
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
// g100pon #40 XMLの読み書きを色んな方法で(DOMBuilder->XmlUtil) | |
import groovy.xml.XmlUtil | |
import groovy.xml.dom.DOMCategory | |
import groovy.xml.DOMBuilder | |
// DOMBuilderを使うとパースが簡単にできる | |
// パース結果のオブジェクトはDOM | |
def doc = DOMBuilder.parse( | |
new InputStreamReader(new FileInputStream('sample.xml'),'UTF-8') ) |
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
// g100pon #44 DBとテーブル名を引数指定して標準入力から読み取ったCSV/TSVデータをinsert | |
import groovy.sql.Sql | |
import groovy.grape.Grape | |
if(args.size()<2){ | |
println "Usage: groovy Text2DB.groovy <DB> <TABLE> < <CSV|TSV>" | |
System.exit(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
// g100pon #98 DerbyでGroovySQL | |
import groovy.sql.Sql | |
import groovy.grape.Grape | |
Grape.grab(group:'org.apache.derby', module:'derby', version:'[10.5.3,)', | |
classLoader:this.class.classLoader.rootLoader) | |
def sql = Sql.newInstance('jdbc:derby:memory:testdb;create=true', | |
'user', 'password', 'org.apache.derby.jdbc.EmbeddedDriver') |