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 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 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 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 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
| File file = new File('your-dir-here') | |
| def fileNames = [] | |
| file.eachFile { | |
| if(it.isFile()) { | |
| fileNames << it.name | |
| } | |
| } |
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
| # ~/.ssh/config | |
| # For any configuration different than defined hosts | |
| Host * | |
| IdentityFile ~/.ssh/id_rsa | |
| User obautista | |
| # Github | |
| Host github.com | |
| HostName github.com | |
| User git |
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
| List months = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", | |
| "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"] | |
| def today = Date.parse("dd-MM-yyyy", "3-11-2020") | |
| def clonedDate = today.clone() | |
| def yesterday = today - 1 | |
| def tomorrow = today + 1 | |
| clonedDate++ | |
| assert clonedDate == tomorrow |
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
| Closure square = { num -> | |
| num * num | |
| } | |
| Closure pow = { num, index -> | |
| num.power(index) | |
| } | |
| List numbers = [2,5,20,10] |
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
| @Grab(group = "org.reflections", module = "reflections", version = "0.9.11") | |
| @Grab(group = "org.slf4j", module = "slf4j-simple", version = "1.7.25") | |
| import groovy.json.JsonOutput | |
| import org.codehaus.groovy.reflection.GeneratedMetaMethod | |
| import org.reflections.Reflections | |
| def reflections = new Reflections("org.codehaus.groovy.runtime") | |
| def json = reflections.getSubTypesOf(GeneratedMetaMethod).collect { |
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
| import groovy.transform.ToString | |
| @ToString | |
| class Person { | |
| String name | |
| String lastname | |
| int age | |
| } | |
| def person = new Person(name:'Omar', lastname:'Bautista', age:33) |
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
| import groovy.util.XmlSlurper | |
| String xml = ''' | |
| <people> | |
| <person age='33'> | |
| <name>Omar</name> | |
| </person> | |
| <person age='30'> | |
| <name>Maria</name> | |
| </person> |
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
| import groovy.json.JsonSlurper | |
| String json = '{ "name" : "Omar", "lastname": "Bautista", "age" : 33 }' | |
| def object = new JsonSlurper().parseText(json) | |
| assert object instanceof Map | |
| assert object.name == 'Omar' |