Skip to content

Instantly share code, notes, and snippets.

@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
}
@nemo-kaz
nemo-kaz / findEncryptedZipFile.groovy
Created December 22, 2017 09:44
Recursively find encrypted zip file
// run findEncryptedZipFile.groovy in the root directory of Encrypted zip files
// to find out encrypted zip files recursively.
// run this code at the top directory of zip files.
// Output directory is d:\WORK\ENCRYPTED, modify the location to meet your environmnet
// Using maven https://mvnrepository.com/artifact/net.lingala.zip4j/zip4j
@Grapes(
@Grab(group='net.lingala.zip4j', module='zip4j', version='1.3.2')
)
@echo off
rem this batch will call some batch file "updateIt.bat" at each 10 days
rem one line of log.txt is like 2017012 ("2017 Jan 20thday") and so on, if the last line of log.txt
rem is different from now, the next batch file will ba called.
rem So we can invoke updateIt.bat at each 10 days
rem Good for some cleanup acitivity
FOR /F "delims=," %%a IN (log.txt) DO (
IF %%a == %date:~0,4%%date:~5,2%%date:~8,1% (
goto DONE
@nemo-kaz
nemo-kaz / recursiveGrep.groovy
Created October 20, 2016 03:28
recursively grep with one or two keywords.
// g100pon recursively grep various filetype files with one or two keywords
// lastly invoke Hidemaru editor
startDir = "."
filePattern = /(\.asm.*$|\
\.awk$|\
\.bat$|\
\.BMS$|\
\.c$|\
\.cbl.*$|\
// 文字コード判定
// ソースコードのコードページを再帰的に判定し続ける
import com.ibm.icu.text.CharsetDetector
@Grab(group='com.ibm.icu', module='icu4j', version='56.1')
def detector = new CharsetDetector()
// UTF-8, UTF-16 UTF-32, Windows-31j
// ISO-8859-2, windows-1252, windows-1250, ISO-8859-2, ISO-8859-1, Big5, UTF-16LE
@nemo-kaz
nemo-kaz / fileSpaceRenamer.groovy
Created January 12, 2014 22:24
Remove space and special character from file name
// File Space Renamer
// Renames any file which has %20 %40 (space) : ;
// %20 -> _
// %40 -> @
// (space) -> _
// eg "Hello World.txt%40" -> "Hello_World@.txt"
new File(".").eachFile { file ->
if(file.isFile()){
curName = file.getPath().replaceAll(/.\\(.*)/) {m0,m1 -> m1}
newFileN = URLDecoder.decode(curName, "UTF-8").replaceAll(/%20/,"_").replaceAll(/%40/,"@").replaceAll(/ /,"_").replaceAll(/:/,"_").replaceAll(/;/,"_")
@nemo-kaz
nemo-kaz / PDFRenamer
Created December 21, 2013 04:59
PDFRenamer.groovy renames PDF file to the file by its Title metadata.
// PDF Renamer : Rename PDF file from the metadata Title
// 1: set PATH to pdftk
// 2: plase PDFRenamer.groovy (this file to same directory of pdftk )
// 3: move to the root of target PDF directory
// 4: start PDFRenamer.groovy in pdftk directory
@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.*;
@nemo-kaz
nemo-kaz / FREE.groovy
Created November 16, 2013 07:47
FREE command shows free space of each drive for Windows
//println "drv [ free ]G [ total ]G [free]%"
println "drv [ 空き ]G [ 計 ]G [Free]%"
allFree=0
allTotal=0
for (drive in "B".."Z") {
file = new File("${drive}:/")
BigDecimal free = file.getFreeSpace()/1000000000
allFree=allFree+free
BigDecimal total= file.getTotalSpace()/1000000000
allTotal=allTotal+total
@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);