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 dat = ['NCC_TEST': [1234, 1345, 1232, 1133, 1100], 'NCC_TEST2': [9999,8765, 4321]] | |
println """update tablename set IsEnriched = 999 where ${ | |
dat.collect { name, serials -> | |
"(ServerName = '$name' and ServerSerial in (${ serials.join(', ') }))" | |
}.join(" or ") | |
}""" |
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
// Fixed synthetic class snippet originally from <[email protected]>. | |
import groovyjarjarasm.asm.Opcodes | |
import org.codehaus.groovy.ast.* | |
import org.codehaus.groovy.ast.expr.* | |
import org.codehaus.groovy.control.* | |
import org.codehaus.groovy.tools.GroovyClass | |
CompilationUnit compilationUnit = new CompilationUnit() |
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 evaluator = new CachingEvaluator() | |
assert evaluator.evaluate("1 + 2 * 3") == 7 | |
assert evaluator.evaluate("1 + 2 * ${3}") == 7 | |
assert evaluator.evaluate(new String("1 + 2 * 3")) == 7 | |
assert evaluator.compiledScriptClasses.size() == 1 | |
class CachingEvaluator { | |
GroovyShell shell = new GroovyShell() |
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
// Bind 'out' variable to redirect script printing methods. | |
out = new StringWriter() | |
// Child script inherits our bindings, including 'out'. | |
// def result = evaluate(new File('TargetScript.groovy')) | |
def result = evaluate ''' | |
def a = 42 | |
println "The answer is $a." | |
a ** 2 | |
''' |
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
package groovyx.cli; | |
import groovy.lang.Binding; | |
import groovy.lang.MissingPropertyException; | |
import groovy.lang.Script; | |
import java.util.HashMap; | |
import java.util.Map; | |
/** |
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
import org.codehaus.groovy.ast.ClassNode | |
import org.codehaus.groovy.control.CompilationUnit | |
import org.codehaus.groovy.control.SourceUnit | |
class MyGroovyClassLoader extends GroovyClassLoader { | |
MyGroovyClassLoader(ClassLoader parent) { super(parent) } | |
Map bytecodes = [:] | |
class MyClassCollector extends GroovyClassLoader.ClassCollector { | |
protected MyClassCollector(GroovyClassLoader.InnerLoader cl, CompilationUnit unit, SourceUnit su) { |
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
// A Groovy solution for the Ninth Annual ICFP <http://www.boundvariable.org/task.shtml> by Jim White. | |
import groovy.transform.CompileStatic | |
import java.nio.ByteBuffer | |
UM.load(new File(args[0])).spin(0) | |
@CompileStatic | |
final class UM { |
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
#!/usr/bin/env groovy | |
@Grab(group='org.apache.lucene', module='lucene-analyzers-common', version='4.5.1') | |
import org.apache.lucene.analysis.standard.StandardAnalyzer | |
import org.apache.lucene.document.Document | |
import org.apache.lucene.document.Field | |
import org.apache.lucene.index.DirectoryReader | |
import org.apache.lucene.index.IndexWriter | |
import org.apache.lucene.index.IndexWriterConfig |
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
import org.junit.Test | |
import javax.script.Bindings | |
class Tests | |
{ | |
@Test | |
def void testSP() | |
{ | |
def p = new Foo() |
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
import groovy.swing.SwingBuilder | |
import javax.swing.JTable | |
import javax.swing.table.AbstractTableModel | |
import javax.swing.table.TableModel | |
class MyTableModel extends AbstractTableModel { | |
List<List> queryResult | |
int getRowCount() { queryResult.size() } | |
int getColumnCount() { queryResult[0].size() } |