Skip to content

Instantly share code, notes, and snippets.

@kanemu
kanemu / gist:441561
Created June 17, 2010 01:59
[groovy]クロージャの使い方
def c = { x, y -> println("${x}, ${y}!") }
c.call("Hello", "kanemu") //Hello kanemu!
c("Hello", "kanemu") //Hello kanemu!
@kanemu
kanemu / gist:441558
Created June 17, 2010 01:53
[groovy]splitの奇妙な動作
//splitを使った場合
assert '0.8'.split('.') == []
//こういう場合はtokenizeを使う
assert '0.8'.tokenize('.') == ['0', '8']
@kanemu
kanemu / gist:448160
Created June 22, 2010 08:05
[groovy]switch文で正規表現の例
def hoge = 'test.pdf'
switch(true){
case (hoge=~/\.pdf$/) as Boolean:
println "pdfです"
break
case (hoge=~/\.xls$/) as Boolean:
println "えくせるです"
break
default:
alert('できるよ!');
@kanemu
kanemu / gist:460943
Created July 2, 2010 04:46
[groovy]mapのremoveの使い方
def map = [
test:"これはテストです",
include:[
a:"あれ",
b:"これ",
c:"それ"
],
name:[
firstName:"SHIGEO",
lastName:"NAGASHIMA"
@kanemu
kanemu / gist:462765
Created July 3, 2010 19:16
[textmate]開いている.groovyをiTermで走らせるtextmateコマンド
osascript -e "tell application \"iTerm\"
activate
if (count current terminal) is 0 then
set myterm to (make new terminal)
tell myterm
launch session \"Default\"
end tell
end if
tell the current session of the current terminal
write text \"groovy \" & \"'${TM_FILEPATH}'\"
@kanemu
kanemu / gist:462772
Created July 3, 2010 19:25
[textmate]開いている.groovyをターミナルから走らせるTextmateコマンド
osascript -e "tell application \"Terminal\"
activate
do script \"groovy \" & \"'${TM_FILEPATH}'\"
end tell"
@kanemu
kanemu / replace.groovy
Created July 8, 2010 09:40
[groovy]テキスト処理
def inputCharCode = "UTF8" //入力側文字コード
def outputCharCode = "UTF8" //出力側文字コード
//変換マップ
def replaceTable=[
/^/:"<p>",
/$/:"</p>",
/\n/:"</p><p>",
/|{0,1}([一-龠]+?)《([ぁ-ん]+?)》/:{ m0, m1, m2 -> "<ruby><rb>$m1</rb><rt>$m2</rt></ruby>" },
"。":"んぬ。"
@kanemu
kanemu / parentDoc.jsx
Created July 28, 2010 13:24
[indesign][extendscript]そのアイテムを持つドキュメントを取る
//InDesign そのアイテムを持つドキュメントを取る
function parentDoc(obj){
var sp=obj.toSpecifier().split('/');
if(sp.length<2||!/^document/.test(sp[1]))return;
return resolve(sp.slice(0,2).join('/'));
};
var obj=app.activeDocument.selection[0];
var doc = parentDoc(obj);
$.writeln(doc);
@kanemu
kanemu / oro.groovy
Created August 1, 2010 20:06
[groovy]apache oro でデリミタを含んだsplit。
//apache oro でデリミタを含んだsplit。
import org.apache.oro.text.perl.Perl5Util;
@Grab(group='oro', module='oro', version='2.0.8')
def perl = new Perl5Util()
def list = []
perl.split(list, '/(<.+?>)/', 'わたしは<b>野球賭博</b>で捕まった人たちとは<b>関係がありません</b>。')
assert list==["わたしは","<b>","野球賭博","</b>","で捕まった人たちとは","<b>","関係がありません","</b>","。"]