This file contains 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() | |
latch.await() | |
Thread.sleep(num * 10) | |
println num | |
} | |
def latch = new java.util.concurrent.CountDownLatch(args.size()) | |
args.each { |
This file contains 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
final COUNT_TO_WRITE = 5 | |
def lineNo = 1 | |
def writableCount = 0 | |
System.in.eachLine { | |
if (it =~ /hoge/) { | |
writableCount = COUNT_TO_WRITE | |
} | |
if (writableCount > 0) { |
This file contains 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
String.metaClass.replace << { int i, String s -> | |
assert s.size() == 1 | |
delegate.value[i] = s as char | |
} | |
def x = 'groovy' | |
x.replace(3, 'X') | |
assert x == 'groXvy' |
This file contains 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
#!/bin/sh | |
echo $* | |
echo 1: $1 | |
echo 2: $2 | |
echo 3: $3 | |
echo 4: $4 | |
echo 5: $5 |
This file contains 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
@GrabConfig(systemClassLoader=true) | |
@Grab('org.twitter4j:twitter4j-core:[2.1,)') | |
import twitter4j.* | |
if (!args) { | |
System.err.println "usage: groovy lottery.groovy <KEYWORDS>..." | |
System.exit 1 | |
} | |
// 強制除外する人を列挙する |
This file contains 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
// http://golf.shinh.org/ | |
// 46 byte: $ cat input.txt | groovy -n arecibo.groovy | |
line.findAll('.'*23){println it.tr('01','.#')} | |
// 56 byte: $ cat input.txt | groovy arecibo.groovy | |
System.in.text.findAll('.'*23){println it.tr('01','.#')} |
This file contains 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
// http://d.hatena.ne.jp/fumokmm/20110815/1313405510 | |
def fizzBuzz(List<Integer> nums, Map<Integer, String> dict) { | |
nums.each { int n -> | |
println dict.findAll{ n % it.key == 0 }.collect{ dict[it.key] }.join() ?: n | |
} | |
} | |
def convertDict(List dict) { | |
assert dict.size() % 2 == 0 | |
(0..<dict.size()).step(2).collectEntries{ [dict[it], dict[++it]] } | |
} |
This file contains 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 PathResolver { | |
String relativePath(String path1, String path2) { | |
[path1, path2].each{ checkPath(it) } | |
def (from, to) = cutCommonBaseDir(path1, path2) | |
(baseDir(from).replaceAll('[^/]+/', '../') ?: './') + to | |
} | |
private checkPath(path) { |
This file contains 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 l = ["", *"A".."Z"] | |
def combinations = [l, l].combinations().collect{ it.join() }.unique() - '' | |
combinations.each { | |
println it | |
} |
This file contains 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
#!/bin/sh | |
GRADLE_FILE_NAME=pmd.gradle | |
RULE_FILE_NAME=pmd-rules.xml | |
if [ -f ./$GRADLE_FILE_NAME ]; then | |
echo "WARN: $GRADLE_FILE_NAME already exists" | |
exit 1 | |
fi | |
if [ -f ./$RULE_FILE_NAME ]; then |