Contribute to this site!  (no login required)...      or  
Groovy 3

Directions (hide this section)

1. Click (memorize) in a memorizable table below, to begin a flashcard-like process
Try clicking (memorize) in both columns (to decide which side to start with)
2. Guess the answer in your head
3. Click the buttons and follow the directions at the bottom of the table
See Help for more detailed directions

Ant

Question (memorize) Answer (memorize)
<groovy>
println "hi"
</groovy>
run groovy code from ant
<groovyc destdir="classes"
srcdir="src"
listfiles="true" />
compile groovy code from ant
new AntBuilder().echo( "hi" ) run ant echo (from groovy)
new AntBuilder().delete() { fileset( dir:".",
  includes:"**/*.abc" ) }
run ant delete (from groovy)
new AntBuilder().scp( file:"foo.txt",
  todir:"user:pass@server.com:.", trust:"true" )
run ant scp (from groovy)

Closures

Question (memorize) Answer (memorize)
c = { println "foo ${it}" } create a closure
c = { a, b -> println "foo ${a} ${b}" } create a closure (with 2 args)
c( "hey" )
c.call( "hey" )
call a closure
l.collect( { ... } ) apply closure to list
m.each( { key, value ->
  println key + "=" + value } )
apply closure to map elements
"abc".replaceAll( "b", { ... } ) Search and replace (using a closure)
"a aa".eachMatch( /a+/, {
  println "foo ${it[0]}" } )
processing multiple matches (using closure)

 

Misc advanced

Question (memorize) Answer (memorize)
sql = groovy.sql.Sql.newInstance(
  "jdbc:axiondb:foo", "", "",
  "org.axiondb.jdbc.AxionDriver" )
get db connection works for all any jdbc driver
sql.execute("insert into t values ('a')") insert db record
sql.eachRow("select * from t") { println "row ${it[0]}" } execute db select
new org.codehaus.groovy.scriptom.ActiveXProxy(
  "Shell.Application" ).MinimizeAll()
minimize all windows
new org.codehaus.groovy.scriptom.ActiveXProxy(
  "WScript.Shell" ).popup( "Groovy popup!!" )
popup dialog
http://groovy.codehaus.org/COM+Scripting page showing install instructions

More misc advanced

Question (memorize) Answer (memorize)
println "pwd".execute().text run shell command
xml = new XmlSlurper().parseText(text) parse xml
xml.elementA.elementB.text() get element text from xml
for( e in xml.depthFirst() ) { ... } traverse xml deapth-first
groovy -l 1960 -e "println line.reverse()" listen on a port and run code on every line

 

 

this section is inserted from the Groovy page

Pages

♦ Groovy
♦ Groovy 2
♦ Groovy 3

See also

 

 

 

Add a section to this page!

- Click this button to contribute to this page (by adding a section here).
♦  Feel free to experiment. Your edits won't immediately show up to everyone.

Memorize all (on this page)

Combines all tables on this page into one large table, and begins the memorization process:
 
the flashcard wiki anyone can edit!
the flashcard wiki anyone can edit!
working...
Terms of Use      Copyright memorizable.com 2007