This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.concurrent.ExecutorService | |
| import java.util.concurrent.BlockingQueue | |
| import java.util.concurrent.LinkedBlockingQueue | |
| import java.util.concurrent.Executors | |
| import java.util.concurrent.Callable | |
| def executor = Executors.newSingleThreadExecutor() | |
| // Closure as Interfaceパターン! | |
| def future = executor.submit( { | |
| def list = [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Grab(group='joda-time', module='joda-time', version='*') | |
| import org.joda.time.* | |
| //def rand_date(def fr, def to) { // java... | |
| def rand_date = {fr,to-> // groovy!! | |
| def d = new DateTime(fr) | |
| def range = Days.daysBetween(d, new DateTime(to)).getDays() + 1 | |
| d.plusDays((Integer)Math.floor(Math.random() * range)).toString("yyyy-MM-dd") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def worker = { latch, num -> | |
| println "ready: $num" | |
| latch.countDown() | |
| Thread.sleep(num * 10) | |
| println num | |
| } | |
| def latch = new java.util.concurrent.CountDownLatch(args.size()) | |
| args.each { | |
| Thread.start worker.curry(latch, it as int) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @GrabResolver(name='jsciencerepos', root='http://maven.obiba.org/maven2/') | |
| @Grab('org.jscience:jscience:4.3.1') | |
| import org.jscience.physics.amount.* | |
| def a = Amount.valueOf("1 m") | |
| def b = Amount.valueOf("2 m") | |
| Amount.metaClass.negative { | |
| opposite() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Hello { | |
| void hello(){ println "1" } | |
| } | |
| def a = new Hello() | |
| def b = new Hello() | |
| println '-' * 10 | |
| b.metaClass.hello = { println "2" } | |
| print '[1] '; a.hello() // => 1 | |
| print '[2] '; b.hello() // => 2 (metaClass.hello が呼ばれる) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def array = [] | |
| def tmp = "" | |
| array = ('0'..'9') + ('a'..'z') + ('A'..'Z') + '_' | |
| (1..16).each { | |
| tmp += array[Math.floor(Math.random() * array.size()) as int] | |
| } | |
| println tmp |