Skip to content

Instantly share code, notes, and snippets.

View sbglasius's full-sized avatar

Søren Berg Glasius sbglasius

View GitHub Profile
@sbglasius
sbglasius / initialGrails2Converter.groovy
Created November 8, 2024 09:18
Does the initial work of converting a Grails 2.x application to Grails 3+ (application or plugin)
#!/usr/bin/env groovy
import groovy.cli.picocli.CliBuilder
import groovy.cli.picocli.OptionAccessor
import groovy.json.JsonSlurper
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.util.regex.Pattern
@sbglasius
sbglasius / _merge-git.md
Last active June 4, 2021 09:12
Merge multiple git-repos into one where each repo becomes a sub-directory

What it does

This script is hacket together to make merging multiple repos into one as easy as possible. It clones each sub-project and then uses git-filter-repo to move each repo into a sub directory. Finally it uses https://github.com/robinst/git-merge-repos for the final merge.

In other words, it takes this:

| project-1 (separate repo)
| - dir-1
|   - file-1.txt
| - README.md
@sbglasius
sbglasius / convertGrails2UnitTests
Last active March 4, 2022 13:19
Will take the tedious work out of converting unit tests from Grails 2 style tests to Grails 3 or 4 style tests
#!/usr/bin/env groovy
import java.nio.file.Files
import groovy.cli.picocli.CliBuilder
import groovy.cli.picocli.OptionAccessor
def cli = new CliBuilder(usage: "./${this.class.getSimpleName()}.groovy <directory>")
cli.with {
header = "'directory' is the source directory update unittests. If not given, the process stops"
}
@sbglasius
sbglasius / SpecUtil
Created November 23, 2018 09:04
Attempt to serialize SpecData - not working
package tests
import com.fasterxml.jackson.annotation.JsonFilter
import com.fasterxml.jackson.core.JsonGenerator
import com.fasterxml.jackson.databind.JsonMappingException
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature
import com.fasterxml.jackson.databind.SerializerProvider
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonObjectFormatVisitor
import com.fasterxml.jackson.databind.node.ObjectNode
/* Written by Damián Adams
* October 2016
* https://mianlabs.com/2016/10/09/making-a-4chan-twitter-bot-with-groovy-in-8-easy-steps/
*/
import groovy.json.JsonSlurper
import java.net.URL
import java.text.SimpleDateFormat
@Grab(group='org.twitter4j', module='twitter4j-core', version='4.0.5')
import twitter4j.Status

External configuration in Grails 3


Working on Grails 3 I realized that I no longer can specify external configuration using the standard grails.config.locations property in Config.groovy file.

Reason is obvious! There is no Config.groovy now in Grails 3. Instead we now use application.yml to configure the properties. However, you can't specify the external configuration using this file too!

What the hack?

Now Grails 3 uses Spring's property source concept. To enable external config file to work we need to do something extra now.

Keybase proof

I hereby claim:

  • I am sbglasius on github.
  • I am sbglasius (https://keybase.io/sbglasius) on keybase.
  • I have a public key whose fingerprint is 4430 F93E 75DB 3F72 5E29 6FB3 2E29 0639 BD6C 45F9

To claim this, I am signing this object:

@sbglasius
sbglasius / FindRealUrl.groovy
Created October 16, 2012 14:50
Groovy function that will follow a number of redirects to get the real URL of a webpage/service
def findRealUrl(url) {
HttpURLConnection conn = url.openConnection()
conn.followRedirects = false
conn.requestMethod = 'HEAD'
if(conn.responseCode in [301,302]) {
if (conn.headerFields.'Location') {
return findRealUrl(conn.headerFields.Location.first().toURL())
} else {
throw new RuntimeException('Failed to follow redirect')
}