Skip to content

Instantly share code, notes, and snippets.

@nemo-kaz
nemo-kaz / dentaku.groovy
Created June 24, 2012 04:37
dentaku 電卓
#!/usr/bin/groovy
import groovy.util.Eval
if (args.length ==0) {
println """Groovy電卓 使用例: dentaku 1+2*3
第一引数に 計算式をスペース無しで指定してください"""
return
}
@nemo-kaz
nemo-kaz / TimerOneMin.groovy
Created June 24, 2012 04:28
one minute timer
import java.text.*
Timer timer = new Timer();
println "Start:"
timer.schedule( new TimerTask() {
public void run() {
println new SimpleDateFormat("yyyyMMdd-HH:mm:ss.S").format(new Date())
}
}, 0, 60*1000);
@nemo-kaz
nemo-kaz / CleanDropbox.groovy
Created June 23, 2012 07:58
Dropbox duplicated file cleaner
new AntBuilder().sequential {
echo "Conflict files of Dropbox will be moved"
move(todir: /c:\var\DUPLICATED_DROPBOX/, //Target Directory of Conflict files
verbose:true) {
fileset(dir: /c:\Dropbox/, // Directory of Dropbox
includes: '**/*conflicted*copy*',
includes: '**/*上の問題のあるコピー*',
excludes: '**/*dropbox*cache*'
)
}
@nemo-kaz
nemo-kaz / introfx.groovy
Created June 8, 2012 13:42 — forked from ksky/introfx.groovy
Self introduction by Google+ API and GroovyFX
import groovyx.javafx.*
key = '<YOUR Google+ API KEY HERE>'
uid = 110611905999186598367 // user ID
url = "https://www.googleapis.com/plus/v1/people/$uid?key=$key".toURL()
json = new groovy.json.JsonSlurper().parseText(url.text)
GroovyFX.start {
def sg = new SceneGraphBuilder()
@nemo-kaz
nemo-kaz / ImageConverter.groovy
Created May 5, 2012 23:16
Automatic jpeg file converter (resize, rotate, rename to the date of the picture)
@Grab('net.java.dev.jna:jna:3.4.0') // since Java does not have directory moving function
import com.sun.jna.*;
import com.sun.jna.win32.*;
interface Kernel32Library extends StdCallLibrary {
Kernel32Library INSTANCE = Native.loadLibrary("kernel32", Kernel32Library.class);
boolean SetCurrentDirectoryA(String dir);
}
@nemo-kaz
nemo-kaz / StringRandomize.groovy
Created November 5, 2011 07:29
文字列の並び順をランダムに入れ替える
// 文字列の拡張メソッド
// 元々の文字列の並び順をランダムに並び替える
String.metaClass.randomize = { ->
Math.random()
return delegate.toList().sort { Math.random()}.join()
}
println "abcdefg".randomize()
@nemo-kaz
nemo-kaz / Top.groovy
Created November 23, 2010 07:27
Top command for Windows
// Top command:
// Windows依存です、CPU負荷の高い順に10プロセス表示します
def command = "cmd /c tasklist.exe /v> output.txt"
command.execute()
List rated=[]
List cputime=[]
new File("output.txt").eachLine{line ->
cputime=line.split(' +')
rated.add(cputime)
// g100pon #19 為替情報の取得
@Grab(group='net.sourceforge.nekohtml', module='nekohtml', version='1.9.14')
import org.cyberneko.html.parsers.SAXParser
class dummy {} // ver1.6 互換の為の class annotationとしての@grap
url = 'http://ja.exchange-rates.org/converter/JPY/BRL/100'
def parser = new XmlSlurper(new SAXParser())
def HTML = parser.parse(url)
// g100pon #67 実行中のクラス/メソッド名を取得
def getMyInfo() {
def the_thisClassName = getClass().getName()
def the_inThisObject = new Throwable().getStackTrace().findAll {
the_stackTraceElement ->
the_thisClassName.equals(the_stackTraceElement.getClassName())
}
println "className = "+ the_inThisObject[0].getProperties().className
println "methodName = "+ the_inThisObject[0].getProperties().methodName
@nemo-kaz
nemo-kaz / FizzBuzz
Created October 10, 2010 05:28
FizzBuzz.groovy
// g100pon #61 FizzBuzz
1.upto(100) {
ans =""
if (it%3 == 0) {ans ="Fizz"}
if (it%5 == 0) {ans += "Buzz"}
if (ans == "") {println it} else println ans
}