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.time.TimeCategory | |
use(TimeCategory) { | |
Date date = new Date("12/10/2008") | |
Date datePlus10Min = date + 30.minutes | |
Date dateMinus1Year = date - 1.years | |
Date datePlus10Hours = date + 10.hours | |
println date // now | |
println datePlus10Min // now + 10 min |
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.yaml.YamlSlurper | |
def slurper = new YamlSlurper() | |
def configuration = ''' | |
version: 3.0 | |
environment: "dev" | |
context: | |
path: "/test" | |
endpoints: |
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' |
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.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
@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
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
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
# ~/.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
File file = new File('your-dir-here') | |
def fileNames = [] | |
file.eachFile { | |
if(it.isFile()) { | |
fileNames << it.name | |
} | |
} |
NewerOlder