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
package tddbc;
import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
@irof
irof / 処理の差し替え.groovy
Created March 26, 2011 15:44
処理の差し替え
class Hello {void hello(){println "1"}}
def a = new Hello()
def b = new Hello()
b.metaClass.hello = { println "2" }
a.hello()
b.hello()
a.metaClass.hello = {b.metaClass.hello}
a.hello()
@irof
irof / 処理の差し替えと戻し.groovy
Created March 27, 2011 03:22
差し替えた後元に戻す
class Hello {void hello(){println "1"}}
def a = new Hello()
a.hello()
a.metaClass.hello = { println "2" }
a.hello()
a.metaClass.hello = { a.&hello() }
a.hello()
class C {int m(){1}}
C.metaClass.m = {9}
def a = new C()
assert 9 == a.m()
a.metaClass.m = {2}
assert 2 == a.m()
C.metaClass.m = {8}
@irof
irof / replace.groovy
Created May 16, 2011 04:24 — forked from kyonmm/replace.groovy
指定ディレクトリ配下のファイルの改行コードを変換する
new File("src").eachFileRecurse(groovy.io.FileType.FILES) {
def s = it.text.replaceAll(/\r\n?/,'\n')
it.withWriter("UTF-8") {it << s}
}
@irof
irof / gist:1019573
Created June 10, 2011 19:19
リスト名から直近のTweetを取得する
@Grab("org.twitter4j:twitter4j-core:2.2.3")
import twitter4j.*
def twitter = new TwitterFactory().instance
twitter.getUserListStatuses(
twitter.getAllUserLists('kyon_mm').find{it.name == 'groovy'}.id, new Paging()
).each { println "<@${it.user.screenName}> $it.text" }
@irof
irof / gist:1020274
Created June 11, 2011 05:18
twitter4j-streamを使ってみる
@Grab('org.twitter4j:twitter4j-core:2.2.3')
@Grab('org.twitter4j:twitter4j-stream:2.2.3')
import twitter4j.*
def twitter = new TwitterFactory().instance
def stream = new TwitterStreamFactory().getInstance(twitter.OAuthAccessToken)
def print = {println "@${it.user.screenName}: ${it.text}"}
stream.addListener([onStatus:print] as UserStreamAdapter)
stream.user()
@irof
irof / gist:1046394
Created June 25, 2011 11:42
未フォローのフォロワーのリスト
@Grab('org.twitter4j:twitter4j-core:2.2.3')
import twitter4j.*
import twitter4j.conf.*
def conf = new ConfigurationBuilder()
.setOAuthConsumerKey('consumer key')
.setOAuthConsumerSecret('consumer secret')
.setOAuthAccessToken('access token')
.setOAuthAccessTokenSecret('access token secret')
// こちらは以前試していた失敗作
class DoWhile {
def proc
def _do(Closure proc) {
this.proc = proc
return this
}
def _while(Closure cond) {
10.times {
println cond()
@irof
irof / gist:1086016
Created July 16, 2011 04:56
GroovyFX ColorfulCircles #kancon2011
import javafx.animation.Timeline;
import javafx.scene.effect.BoxBlur
import javafx.scene.paint.Color;
import javafx.scene.shape.StrokeType;
import groovyx.javafx.GroovyFX;
import groovyx.javafx.SceneGraphBuilder;
import groovyx.javafx.TimelineBuilder;
GroovyFX.start {stage->