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 method = request.method | |
if (!session) { | |
session = request.getSession(true) | |
} | |
if (!session.groovlet) { // Podemos tener variables guardadas en session | |
session.groovlet = 'Groovlets rock!' | |
} |
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 name = '"Desveloper"' | |
def map = [:] // java.util.LinkedHashMap | |
def elements = [1, // java.lang.Integer | |
11111111111, // java.lang.Long | |
11111111111111111111, // java.math.BigInteger | |
0.1, // java.math.BigDecimal | |
0..5, // groovy.lang.IntRange | |
'x'..'p', // groovy.lang.ObjectRange | |
"Normal String", // java.lang.String |
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
// Give execution permission | |
⇒ chmod +x random_password.groovy | |
// Show help | |
⇒ ./random_password.groovy -h | |
usage: random_password -[has] | |
-a,--alphabet <arg> A set of characters to generate the password | |
-h,--help Usage Information | |
-s,--size <arg> Size of the output password |
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 | |
String source = args[0] | |
String target = args[1] | |
println "Copy file [$source] into [$target]" | |
File sourceFile = new File(source) | |
new File(target).bytes = sourceFile.bytes |
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 MySampleClass { | |
Map props = [:] | |
def propertyMissing(String propertyName, String value) { | |
props[propertyName] = value | |
} | |
def propertyMissing(String propertyName) { | |
props[propertyName] |
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 methodMissing(String name, args) { | |
Closure closure = actions[name] | |
if(closure) { | |
closure.call(args) | |
} else { | |
throw new MissingMethodException(name, ActionExecutor.class, args) | |
} | |
} |
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
<script type="text/javascript"> | |
$(document).ready(function(){ | |
$("#yourId").change(function () { | |
$.ajax({ | |
url: "${g.createLink(controller:'yourContrller',action:'yourAjaxAction')}", | |
dataType: 'json', | |
data: {}, | |
success: function (data) { | |
alert(data) | |
}, |
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
git branch -m new-name # If you are on the branch you want to rename | |
git branch -m old-name new-name # If you are on a different branch | |
git push origin :old-name new-name # Delete the old-name remote branch and push the new-name local branch. | |
git push origin -u new-name # Reset the upstream branch for the new-name local branch. |
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 | |
version = '2.2.0' | |
release = '2.11-2.2.0' | |
url = "http://apache.claz.org/kafka/${version}/kafka_${release}.tgz" | |
tempDir = "/tmp/groovy_workshop" | |
destDir = "/Users/obautista/Documents/workspace-public/GroovyWorkshopExamples/src/main/resources/download" | |
def ant = new AntBuilder() |
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
// app.groovy | |
@RestController | |
class ThisIsAnExample { | |
@RequestMapping('/{name}') | |
String sayHello(@RequestParam(value = "name", | |
required = false) String name){ | |
"Hello ${name ?: 'World'} from Spring Boot + Groovy" | |
} | |
} |