Skip to content

Instantly share code, notes, and snippets.

View gregopet's full-sized avatar

Gregor Petrin gregopet

View GitHub Profile
@gregopet
gregopet / mergeDocs.groovy
Last active August 29, 2015 14:00
A very simple script that merges api docs from Groovy's GDK and Oracle's JDK using Geb
/**
* This script merges HTML from Groovy GDK docs with Oracle's Javadocs in a (stupid) straightforward way.
* It's meant as half joke, half GEB exercise.
*/
@Grab(group='org.seleniumhq.selenium', module='selenium-api', version='2.14.0')
@Grab(group='org.seleniumhq.selenium', module='selenium-htmlunit-driver', version='2.14.0')
@Grab(group='org.codehaus.geb', module='geb-core', version='0.7.2')
import geb.Browser
enum Section {
@gregopet
gregopet / myByteClass.groovy
Created January 9, 2014 08:50
Helper class for the Coursera Cryptography course
/**
* Represents a byte sequence.
*/
class ByteSeq {
protected List sequence
/**
* Default constructor, creates an empty byte sequence.
*/
@gregopet
gregopet / TestController.groovy
Created December 4, 2013 09:59
Trying to figure out a Grails behaviour
//This happens with the default 2.3.3 Config.groovy:
//curl 'http://localhost:8080/test-accept-header/test/index' -H 'Accept: application/json, */*'
//FIRST BLOCK
//curl 'http://localhost:8080/test-accept-header/test/index' -H 'Accept: application/json'
//WILDCARD BLOCK
class TestController {
def index() {
withFormat {
xml {
@gregopet
gregopet / gist:5361848
Last active December 16, 2015 02:19
An idea for a Grails plugin

Lately I've been using the excellent Middleman static site generator for a few projects, but having a certain distaste for Ruby, I've been giving some thought to building a Grails plugin for this task. A quick search didn't yield any existing plugins that could do this, so I may just give it a go.

The way this would work is to create a normal Grails application and somehow fill it with data (e.g. with the Fixtures plugin or from an actual database) and then call a script provided by this new plugin. This script would start the Grails application and crawl it as defined by a set of conventions and rules, saving the resulting HTML pages in a folder.

My first dilemma is over the best way of defining these rules. One would be to simply use the UrlMappings.groovy file, e.g.

"/book/list"(controller: 'book', action: 'list')
"/book/$book"(controller: 'book', action: 'show')

...would result in single HTML file for the list action and one HTML for each Book instance as returned b

@gregopet
gregopet / gist:3180621
Created July 26, 2012 06:46
I will break you

I was driving to work today listening to one of my favorite bands for the N-th time when it hit me: that song via which I discovered the band in the first place could well be talking about refactoring code! Here are the first few lines:

I will break you
And I will remake you
I will take my time
To get you just right

While the rest of the song doesn't fit the description that snugly, with just a little imagination it still wonderfully describes that activity so familiar to programmers everywhere. Was my geek subconsciousness telling me that this song was cool?

@gregopet
gregopet / gist:3141388
Created July 19, 2012 07:38
Tomcat won't redirect pages to HTTPS

The problem

I had a problem the other day where Tomcat would not redirect users to the HTTPS version of the login page (I am using the Spring Security plugin). It worked in development mode, but not in production.

The solution

The trick was to set both the grails.plugins.springsecurity.portMapper.httpPort and grails.plugins.springsecurity.portMapper.httpsPort properties to sensible values. Defaulting to 8080 and 8443 it makes sense they wouldn't work on prod. I found the answer via this Stack Overflow question