Skip to content

Instantly share code, notes, and snippets.


Søren Berg Glasius sbglasius

View GitHub Profile
sbglasius /
Last active Jun 4, 2021
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 for the final merge.

In other words, it takes this:

| project-1 (separate repo)
| - dir-1
|   - file-1.txt
| -
sbglasius / convertGrails2UnitTests
Last active Mar 4, 2022
Will take the tedious work out of converting unit tests from Grails 2 style tests to Grails 3 or 4 style tests
View convertGrails2UnitTests
#!/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 / SpecUtil
Created Nov 23, 2018
Attempt to serialize SpecData - not working
View SpecUtil
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
View 4chan-twitter-bot.groovy
/* Written by Damián Adams
* October 2016
import groovy.json.JsonSlurper
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 ( 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 / FindRealUrl.groovy
Created Oct 16, 2012
Groovy function that will follow a number of redirects to get the real URL of a webpage/service
View FindRealUrl.groovy
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')