Skip to content

Instantly share code, notes, and snippets.

View frangarcia's full-sized avatar

Fran García frangarcia

View GitHub Profile
> Task :dependencies
------------------------------------------------------------
Root project 'testprojectgrails515'
------------------------------------------------------------
agent
No dependencies
@frangarcia
frangarcia / jsonlogic.groovy
Created March 18, 2021 14:51
Json logic with Groovy
/* Some example using a library with json logic
- https://jsonlogic.com/
- https://github.com/jamsesso/json-logic-java
*/
@GrabConfig( systemClassLoader=true )
@Grapes(
@Grab(group='io.github.jamsesso', module='json-logic-java', version='1.0.5')
)
@frangarcia
frangarcia / groovy
Created February 2, 2021 10:12
Passing a closure as a binding property to generate an output string using string template engine
/* Snippet to pass a method as a closure to generate an output string */
import groovy.text.GStringTemplateEngine
import groovy.text.Template
import java.text.SimpleDateFormat
String formatDate(String date, String pattern, String timeZone){
try {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern)
simpleDateFormat.setTimeZone(TimeZone.getTimeZone(timeZone))
@Grapes([
@Grab(group='org.spockframework', module='spock-core', version='1.3-groovy-2.5', scope='test'),
@Grab(group='org.testcontainers', module='spock', version='1.14.2', scope='test'),
])
import spock.lang.*
import org.testcontainers.containers.GenericContainer
import groovy.json.JsonSlurper
@org.testcontainers.spock.Testcontainers
openapi: 3.0.0
info:
title: Sample API
description: Optional multiline or single-line description in [CommonMark](http://commonmark.org/help/) or HTML.
version: 0.1.9
servers:
- url: http://api.example.com/v1
description: Optional server description, e.g. Main (production) server
- url: http://staging-api.example.com
description: Optional server description, e.g. Internal staging server for testing
@frangarcia
frangarcia / countingwordsinpropertiesfile.groovy
Created February 13, 2020 08:34
Counting words in properties file
List<String> files = ["file1.properties", "file2.properties", "file3.properties"]
Long countWords(File propertiesFile) {
Long totalWords = 0
try {
InputStream input = new FileInputStream(propertiesFile)
Properties prop = new Properties();
@frangarcia
frangarcia / googlecloudstorage
Last active July 12, 2018 15:34
Example of how to upload images into a Google Cloud Storage with Groovy
@Grapes([
@Grab(group='com.google.cloud', module='google-cloud-storage', version='1.31.0'),
@Grab(group='com.google.auth', module='google-auth-library-credentials', version='0.9.1')
])
import com.google.cloud.storage.Bucket;
import com.google.cloud.storage.BucketInfo;
import com.google.cloud.storage.Storage;
import com.google.cloud.storage.Storage.BucketGetOption;
import com.google.cloud.storage.Blob;
import com.google.cloud.storage.StorageOptions;
@frangarcia
frangarcia / gist:a14ce1ea1ba03eac57a3aec8c9746b23
Created December 13, 2017 16:58
Remote branches in origin for which I did the last commit
git fetch -p && git branch -r --list origin/hotfix\* origin/feature\* origin/bugfix\* origin/chore\* | while read -r remote_branch; do if [ $(git log -1 $remote_branch --pretty=format:'%ce') == "your@email.com" ]; then echo $(git log -1 $remote_branch --pretty=format:'%d'); fi; done;
@frangarcia
frangarcia / gist:390e4530e105ccb4aef5a8a3ef235435
Created December 13, 2017 16:50
Last author in remote branches
git fetch -p && git branch -r --list origin/\* | while read -r remote_branch; do git log -1 $remote_branch --pretty=format:'%ce';echo ;done | sort | uniq -c | awk '{printf("%s,%s\n",$2,$1)}' > output.csv
@Grapes([
@Grab(group='io.vertx', module='vertx-core', version='3.4.1'),
@Grab(group='io.vertx', module='vertx-lang-groovy', version='3.4.1')
])
import io.vertx.core.*
import io.vertx.core.json.*
JsonObject jo1 = new JsonObject()
assert "jo1 is a ${jo1?.class?.name}" == "jo1 is a io.vertx.core.json.JsonObject"