Skip to content

Instantly share code, notes, and snippets.

@xnrghzjh
xnrghzjh / rand_date.groovy
Created June 9, 2011 03:35
指定範囲内の日付をランダムに取得
@Grab(group='joda-time', module='joda-time', version='*')
import org.joda.time.*
//def rand_date(def fr, def to) { // java...
def rand_date = {fr,to-> // groovy!!
def d = new DateTime(fr)
def range = Days.daysBetween(d, new DateTime(to)).getDays() + 1
d.plusDays((Integer)Math.floor(Math.random() * range)).toString("yyyy-MM-dd")
}
@xnrghzjh
xnrghzjh / rand_date.groovy
Created June 9, 2011 09:06 — forked from kyonmm/rand_date.groovy
指定範囲内の日付をランダムに取得
@Grab(group='joda-time', module='joda-time', version='*')
import org.joda.time.*
DateTime.metaClass.random ={t->
def range = Days.daysBetween(delegate, new DateTime(t)).getDays() + 1
delegate.plusDays(Math.floor(Math.random() * range) as int).toString("yyyy-MM-dd")
}
rand_date ={f,t ->
new DateTime(f).random(t)
@xnrghzjh
xnrghzjh / rand_date.groovy
Created June 10, 2011 04:15
指定範囲内の日付をランダムに取得(重複選択可)
class DateRange {
def range
def index = 0
DateRange (f, t) {
range = (toDate(f)..toDate(t)).toList().with {
Collections.shuffle(it); it
}
}
// 変換処理
@xnrghzjh
xnrghzjh / GetFiscalMonth.groovy
Created June 13, 2011 06:39
締め日を指定して会計月度を取得
Date.metaClass.getFiscalMonth = { p ->
cal = Calendar.getInstance();
cal.setTime(delegate)
if (cal.get(Calendar.DATE) > p) { cal.add(Calendar.MONTH, 1) }
cal.set(Calendar.DATE, 1)
cal.getTime()
}
Date.metaClass.toString = {
delegate.format('yyyy/MM/dd')
@xnrghzjh
xnrghzjh / FiscalInfoHolder.groovy
Created June 14, 2011 03:11
会計年情報の取得
class FiscalInfoHolder {
def month
def date
def cal = Calendar.getInstance()
// 会計年月度の取得
def getFiscalYearMonth = {
cal.setTime(it)
if (cal.get(Calendar.DATE) > date) { cal.add(Calendar.MONTH, 1) }
cal.getTime()
@xnrghzjh
xnrghzjh / PrinterUtil.groovy
Created June 14, 2011 06:39
プリンタ周りの便利ツール
import javax.print.*;
import javax.swing.*;
class PrinterUtil {
// プリンタ一覧の取得
static def getPrinterList = {
List list = []
PrintServiceLookup.lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE, null).each {
list.add(it.getName())
@xnrghzjh
xnrghzjh / StopWatch.groovy
Created June 14, 2011 09:23
ストップウォッチ
class StopWatch {
def lapTimes = []
def startTime
def stopTime
def cur = { System.currentTimeMillis() }
def start = { startTime = cur() }
def stop = { stopTime = cur() }
def elapsedTime = { stopTime - startTime }
def elapsedLapTime = { lapTimes[it].time - startTime }
@xnrghzjh
xnrghzjh / VirtualBoxControl
Created June 15, 2011 00:34
VirtualBoxの仮想マシンを非表示で管理(wsfから移植)
import javax.swing.*;
// VirtualBoxのパス
path = "C:\\Program Files\\Oracle\\VirtualBox\\"
// 仮想マシンのリスト
list = ['RedMine', 'DokuWiki']
// 引数チェック
if (args.size() == 0) {
@xnrghzjh
xnrghzjh / getSelectedButtonCaption.java
Created June 16, 2011 01:01
ボタングループから選択されているラジオボタンのキャプションを取得
private buttonGroup = new javax.swing.ButtonGroup();
private button1 = new javax.swing.JRadioButton();
private button2 = new javax.swing.JRadioButton();
private button3 = new javax.swing.JRadioButton();
buttonGroup.add(button1);
buttonGroup.add(button2);
buttonGroup.add(button3);
public String getSelectedButtonCaption() {
@xnrghzjh
xnrghzjh / getSelectedButtonCaption.groovy
Created June 16, 2011 01:24
ボタングループから選択されているラジオボタンのキャプションを取得(Groovy)
import javax.swing.*
ButtonGroup.metaClass.getSelectedButtonCaption() {
caption = ""
delegate.getElements().each { if (it.isSelected()) caption = it.getText() }
caption
}
// 実行
buttonGroup = new ButtonGroup()
buttonGroup.add(new JRadioButton("Button1"))