Skip to content

Instantly share code, notes, and snippets.

Avatar

Søren Berg Glasius sbglasius

View GitHub Profile
@sbglasius
sbglasius / _merge-git.md
Last active Jun 4, 2021
Merge multiple git-repos into one where each repo becomes a sub-directory
View _merge-git.md

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 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
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
* 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
View external_configuration_in_grails_3.md

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.

View keybase.md

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 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')
}