Skip to content

Instantly share code, notes, and snippets.

def getBytes(str, encode) {
str.getBytes(encode).collect{
"0x${Integer.toHexString(it & 0xff)}"
}
}
assert getBytes('\uff5e', 'Windows-31J') == ['0x81', '0x60']
@fumokmm
fumokmm / searchFollowingKeywordList.groovy
Created May 23, 2010 13:58
はてなハイク4Jを使ってフォローしているキーワード一覧を取得するサンプル。
// required hatenahaiku4j
// http://d.hatena.ne.jp/fumokmm/20090905/1252143947
import hatenahaiku4j.*
long start = System.currentTimeMillis()
new HatenaHaikuAPILight().with {
getUser('fumokmm').api.followingKeywordList.each { k ->
println k.title
}
}
import groovy.xml.NamespaceBuilder
import groovy.xml.MarkupBuilder
// create 'ivy.xml'
def ivyxml = new StringWriter()
def mkb = new MarkupBuilder(ivyxml)
mkb.doubleQuotes = true
mkb.'ivy-module' (version: '2.0') {
info (organisation: 'apache', module: 'hello-ivy')
dependencies {
import groovy.xml.NamespaceBuilder
import groovy.xml.MarkupBuilder
// create 'ivy.xml' and 'ivysettings.xml'
createIvyXml()
createIvySettingXml()
// invoke ant
def ant = new AntBuilder()
def ivy = NamespaceBuilder.newInstance(ant, 'antlib:org.apache.ivy.ant')
@fumokmm
fumokmm / grapeConfig-mod-for-hatenahaiku4j.xml
Created May 27, 2010 21:35
当ファイルはGroovyのGrapeでhatenahaiku4jを取得できるようにするための設定ファイルです。利用する場合、ファイル名をgrapeConfig.xmlに変更し ${user.home}/.groovy/ に設置して下さい。
<!--
* Copyright 2003-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@fumokmm
fumokmm / grabSampleHatenaHaiku4j.groovy
Created May 27, 2010 21:40
hatehaiku4jを@grabするサンプルです。パブリックタイムラインのユーザIDを標準出力にプリントします。
@Grab('hatenahaiku4j:hatenahaiku4j:latest.integration')
import hatenahaiku4j.*
new HatenaHaikuAPIHTML().publicTimeline.each {
println it.userId
}
@fumokmm
fumokmm / ant-with-groovy.xml
Created June 5, 2010 09:50
Antスクリプト内でGroovyスクリプトを利用するテンプレート。
<?xml version="1.0" ?>
<project name="ant-with-groovy" default="test">
<taskdef name="groovy"
classname="org.codehaus.groovy.ant.Groovy"
classpath="groovy-all-1.7.2.jar" /> <!-- groovy-all-*.jar を指定 -->
<target name="test">
<groovy><![CDATA[
// この中にgroovyスクリプトを自由に記述できる。
// このバインディング内で暗黙的に利用可能な変数は以下。
@fumokmm
fumokmm / ant-with-groovy-mkdir-100times.xml
Created June 5, 2010 10:22
連番フォルダを100個作成する。
<?xml version="1.0" ?>
<project name="ant-with-groovy" default="test">
<taskdef name="groovy"
classname="org.codehaus.groovy.ant.Groovy"
classpath="groovy-all-1.7.2.jar" /> <!-- groovy-all-*.jar を指定 -->
<target name="test">
<groovy><![CDATA[
(1..100).each { no ->
ant.mkdir dir: "test/dir${no.toString().padLeft(3, '0')}"
@fumokmm
fumokmm / ant-with-groovy-copy-in-one-stretch.xml
Created June 5, 2010 10:33
連続でフォルダにコピーする。
<?xml version="1.0" ?>
<project name="ant-with-groovy" default="test">
<taskdef name="groovy"
classname="org.codehaus.groovy.ant.Groovy"
classpath="groovy-all-1.7.2.jar" /> <!-- groovy-all-*.jar を指定 -->
<target name="test">
<groovy><![CDATA[
// 例:古いディレクトリから新しいディレクトリにコピー
def dirMap = [
<?xml version="1.0" ?>
<project name="ant-with-groovy" default="test">
<taskdef name="groovy"
classname="org.codehaus.groovy.ant.Groovy"
classpath="groovy-all-1.7.2.jar" /> <!-- groovy-all-*.jar を指定 -->
<target name="test">
<groovy><![CDATA[
import static java.util.Calendar.*
def isWeekend = { new Date()[DAY_OF_WEEK] in [SATURDAY, SUNDAY] }