Skip to content

Instantly share code, notes, and snippets.

@rdmueller
rdmueller / map2Json.groovy
Last active March 1, 2020 21:35
This Gist demonstrate how to serialize a Map to JSON and YAML with Groovy
//Problem:
//languages like tcl can simply switch between the String representation of a map or list and the
//object itself. In Groovy, this could theoretically work, but it doesn't:
def list1 = [1,2,3]
def list2 = ["1, 2, 3"]
assert list1 != list2
assert list1.toString() == list2.toString()
assert Eval.me(list1.toString()) instanceof List
assert Eval.me(list2.toString()) instanceof List
assert Eval.me(list1.toString()) == Eval.me(list2.toString())
// simple script which shows how to read and write YAML with Groovy
@Grab("org.yaml:snakeyaml:1.16")
import org.yaml.snakeyaml.Yaml
def yamlData = """
Time: 2001-11-23 15:01:42 -5
User: a Test
# Multiline String
Warning:
This is an error message
@rdmueller
rdmueller / fetchGithubIssues.groovy
Created March 28, 2016 21:18
An example on how to fetch all open issues of a repository with groovy.
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.6' )
import groovyx.net.http.RESTClient
import groovyx.net.http.EncoderRegistry
def github = new RESTClient( 'https://api.github.com/' )
github.encoderRegistry = new EncoderRegistry( charset: 'utf-8' )
def headers = [
'Content-Type':'application/json; charset=utf-8',
'User-Agent':'rdmueller' // replace with your github user name
]
// Copyright 2015
// Licensed under the Apache License, Version 2.0 (the "License")
// original source https://gist.github.com/rdmueller/acee3a5db5ea3273652b
import org.codehaus.groovy.grails.commons.DefaultGrailsDomainClass
import grails.util.GrailsNameUtils
//includeTargets << grailsScript("_Init")
includeTargets << grailsScript("_GrailsPackage")
includeTargets << grailsScript("_GrailsBootstrap")
GRAILS GROOVY SOURCE
3.0.1
3.0.0 2.4 https://grails.github.io/grails-doc/3.0.x/guide/introduction.html
2.5.0 2.4 http://grails.1312388.n4.nabble.com/ANN-Grails-2-4-5-and-Grails-2-5-0-released-td4658938.html
2.4.5
2.4.4
2.4.3
2.4.2
@rdmueller
rdmueller / gist:6211786
Created August 12, 2013 15:19
oAuth2 as Grails Controller
import grails.converters.JSON
class AuthController {
def login = {
//let's fetch everything which depends on the provider from the config
def config = grailsApplication.config.oauth.providers[params.provider]
def appKey = config.appKey
def secret = config.secret
def scope = config.scope