Skip to content

Instantly share code, notes, and snippets.

View frangarcia's full-sized avatar

Fran García frangarcia

View GitHub Profile
@frangarcia
frangarcia / gist:8a74107f47f476ede89f
Last active August 29, 2015 14:20
Replacing surrogates chars by html entities
@Grapes(
@Grab(group='commons-lang', module='commons-lang', version='2.6')
)
/*@Grapes(
@Grab(group='org.apache.commons', module='commons-lang3', version='3.3')
)*/
import org.apache.commons.lang.StringEscapeUtils
@Grapes(
@Grab(group='de.inetsoftware', module='jlessc', version='1.1')
)
import com.inet.lib.less.*
String lessContent = new File("example.less")?.text
Long time1 = new Date().time
String css = Less.compile( null, lessContent, true );
@frangarcia
frangarcia / groovyatbrowserstack.groovy
Created July 28, 2016 09:54
end-2-end test with groovy at browserstack
@Grab(group="org.seleniumhq.selenium", module="selenium-java", version="2.53.1")
import org.openqa.selenium.*
import org.openqa.selenium.remote.DesiredCapabilities
import org.openqa.selenium.remote.RemoteWebDriver
String USERNAME = "<USERNAME>"
String AUTOMATE_KEY = "<AUTOMATE_KEY>"
String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "@hub-cloud.browserstack.com/wd/hub"
@frangarcia
frangarcia / gist:8e2cf247f48a185506e1a28b7cf98de0
Last active October 10, 2016 15:00
Spock specification to test a REST API endpoint
@GrabExclude('org.codehaus.groovy:groovy-all')
@Grab(group='org.spockframework', module='spock-core', version='1.1-groovy-2.4-rc-2')
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1')
import spock.lang.*
import groovyx.net.http.RESTClient
@Stepwise
class MyFirstSpec extends Specification {
@Shared
@Grapes([
@Grab(group='org.grails', module='grails-web-common', version='3.1.10')
])
import org.grails.web.json.JSONObject
import org.grails.web.json.JSONArray
String tagList = "tag1,tag2"
JSONObject jsonObject1 = new JSONObject([id:1,tags:tagList?.split(",")])
assert jsonObject1.get("tags").size()==2
@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"
@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
@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 / 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 / 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();