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 file = "input.txt" | |
// just to heat up the jvm :) | |
new File(file).eachLine{ | |
it.toUpperCase() | |
} | |
// with closure | |
start = System.nanoTime() | |
new File(file).eachLine{ | |
it.toUpperCase() |
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
/** | |
* Problem: to find if any word exists in *every* line in input | |
*/ | |
def input = """This is big line | |
This is another big big line | |
There is something common here | |
""" | |
/* APPROACH ONE : order of O(n) |
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
println System.properties.grep ({it.key.contains("proxy")}) | |
// print all system properties | |
// System.properties.each {k,v-> println "$k=$v"} |
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
// define the url | |
def url = "http://news.google.com/news?ned=us&topic=h&output=rss" | |
def rss = new XmlSlurper().parse(url) | |
println rss.channel.title | |
rss.channel.item.each { | |
println "- ${it.title}" | |
} |
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
// saving from url to a file (append) | |
new File("output.xml") << new URL ("http://some.url/some/path.xml").getText() |
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
// MarkupBuilder is a lot cleaner way of generating valid xml/html markup | |
// than writing tags as string and forgetting to close one ;) | |
def writer = new StringWriter() // html is written here by markup builder | |
def markup = new groovy.xml.MarkupBuilder(writer) // the builder | |
markup.html{ | |
table { | |
tr { | |
td(class:"row", "hello world!") |
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
// following process executes 'mvn compile' from a groovy script | |
// it can be replaced with any system program | |
Process compile = "cmd /c mvn compile".execute() // 'cmd /c' works only on win platform | |
compile.waitForProcessOutput(out, err) | |
if (out) println "out:\n$out" | |
if (err) println "err:\n$err" | |
exitValue = compile.exitValue() |
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 file_path = "C:/path/to/excel/file.xlsx" | |
def read_only = true | |
// Unfortunately this will work only on windows because of this driver :( | |
def connection_url= """jdbc:odbc:Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)}; | |
DBQ=$file_path;READONLY=$read_only""" | |
if (!new File(file_path).exists()) return "invalid file" | |
def sql = groovy.sql.Sql.newInstance(connection_url, '', '') |
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
... | |
<reporting> | |
<plugins> | |
<!-- checks the test coverage --> | |
<plugin> | |
<groupId>org.codehaus.mojo</groupId> | |
<artifactId>cobertura-maven-plugin</artifactId> | |
<version>${cobertura.version}</version> | |
</plugin> |
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
<plugin> | |
<groupId>org.mortbay.jetty</groupId> | |
<artifactId>maven-jetty-plugin</artifactId> | |
<version>6.1.24</version> <!-- TODO upgrade to version 7 --> | |
<configuration> | |
<stopPort>9669</stopPort> | |
<stopKey>${appname}</stopKey> | |
<!-- Redeploy every x seconds if changes are detected, | |
0 for no automatic redeployment --> | |
<scanIntervalSeconds>3</scanIntervalSeconds> |
OlderNewer