Skip to content

Instantly share code, notes, and snippets.

View irof's full-sized avatar
🏠
Working from home

irof irof

🏠
Working from home
View GitHub Profile
@irof
irof / gist:1142079
Created August 12, 2011 13:56
お題:文字列を先頭から見て同じところまで除去
def hoge(String... args) {
def i = -1, v = ''
while(++i < args*.size().min() && args.every{it[i] == args[0][i]}) {
v += args[0][i]
}
args*.minus(v)
}
assert hoge('123', '123') == ['','']
assert hoge('112233', '123123') == ['12233', '23123']
(1..100).each{i->println i%15?i%5?i%3?i:'Fizz':'Buzz':'FizzBuzz'}
@irof
irof / irof.groovy
Created November 5, 2011 05:34
jggugcamp2011の自己紹介
def file = new File('./outout.html')
String.metaClass.each = { Closure c -> c(delegate) }
def map = [
なまえ:'@irof',
年齢:'0x10代',
生息地:'大阪',
しごと:['主にJava','だけど1.4とか…。','超レガシー',],
クラスタ?:['関西ジャバエンジニアの会','TDDBC'],
Groovy:['@kiy0takaさんに釣られて…','けどあまり使えてませんorz'],
@irof
irof / g100pon_3.groovy
Created November 5, 2011 07:20
Groovyのリスト操作
// g100pon #3 リスト操作(上級編)
// 1から10まで連番のリストを作成する
def list = [*1..10]
assert list == [1,2,3,4,5,6,7,8,9,10]
// 逆順にする
assert list.reverse() == [10,9,8,7,6,5,4,3,2,1]
// 後ろから5個とりだす
@irof
irof / filecopy.groovy
Created November 5, 2011 11:27
ファイルのコピーをいくつか
// ファイルコピー
// まずコピー元ファイルを作成
def src = new File('src.txt')
src.text = 'jggugcamp2011'
"chmod 777 src.txt".execute()
// readBytes
new File('dest.txt') << new File('src.txt').getBytes()
@irof
irof / gist:1361388
Created November 13, 2011 00:57
JUnitでAssertを使わずSystem.out.printlnするひとに警告する
System.setOut(new PrintStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
throw new RuntimeException("Assert使え(#゚Д゚)ゴルァ!!");
}
}));
@irof
irof / SystemOutRule.java
Created November 13, 2011 01:21
System.outをassertするためのRule
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import org.junit.rules.MethodRule;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.Statement;
public class SystemOutRule implements MethodRule {
private ByteArrayOutputStream baos;
@irof
irof / gist:2056720
Created March 17, 2012 08:35
Git 初心者用Boot Camp - 演習回答例
git init
echo a>A.txt
git add A.txt
git commit -m'A'
echo b>B.txt
git add B.txt
git commit -m'B'
@irof
irof / gist:3154261
Created July 21, 2012 02:24
コメントをコメントアウトされたでござる
// 2012/07/21 irof 修正開始
//// 2012/07/21 削除開始
//// // 間違ったコメント
//// 2012/07/21 削除終了
// 2012/07/21 irof 削除開始
// // 間違ったコメント
// 2012/07/21 irof 削除終了
// 2012/07/21 irof 修正終了
someMethod(arg);
@irof
irof / gab_km.hs
Created August 3, 2012 03:35
gab_kmさんは関数だったらしい
type Tuna = String
type Tea = String
type Ginger = String
gab_km :: Tuna -> Tea -> Ginger
gab_km "中トロ" "緑茶" = "ガリ"
gab_km "中トロ" _ = "緑茶よこせ"
gab_km _ "緑茶" = "中トロよこせ"
gab_km _ _ = "こんなもん喰えるか!"