Skip to content

Instantly share code, notes, and snippets.

View pledbrook's full-sized avatar

Peter Ledbrook pledbrook

View GitHub Profile
@pledbrook
pledbrook / compile
Created September 21, 2011 08:45 — forked from jesperfj/compile
Grails LP
#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir>
# fail fast
set -e
BIN_DIR=$(cd $(dirname $0); pwd) # absolute path
# parse args
BUILD_DIR=$1
CACHE_DIR=$2
@pledbrook
pledbrook / BootStrap.groovy
Created May 10, 2012 12:52
Embed Vert.x in Grails
import org.vertx.groovy.core.Vertx
class BootStrap {
def init = { servletContext ->
def vertx = Vertx.newVertx()
def httpServer = vertx.createHttpServer()
vertx.createSockJSServer(httpServer).installApp(prefix: '/events') { sock ->
sock.dataHandler { buff ->
sock << buff
@pledbrook
pledbrook / CommonTagLib.groovy
Created May 16, 2012 07:51
Example map with enum keys
import org.grails.common.ApprovalStatus
import static org.grails.common.ApprovalStatus.*
class CommonTagLib {
static namespace = "common"
static final STATUS_TO_CSS_CLASS = [
(PENDING): "warning",
(REJECTED): "important",
(APPROVED): "success" ].asImmutable()
@pledbrook
pledbrook / Config.groovy
Created May 16, 2012 10:17
Loading runtime config from JSON in Grails
// ... rest of Config.groovy content goes above this line to ensure that
// the JSON overrides existing settings.
ConfigLoader.addEntries(loadJson(fetchJson()), this)
def fetchJson() { return System.getenv("GRAILS_APP_CONFIG") }
def loadJson(content) { return content ? grails.converters.JSON.parse(content) : [:] }
package todosample
import grails.events.Listener
class DebugService {
@Listener
def packageWarStart() {
println "[DebugService] Packaging started"
}
@pledbrook
pledbrook / ApplicationConfig.java
Created August 21, 2012 14:43
Environment-specific cache managers in Spring
package org.example.config;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager
@Configuration
public class ApplicationConfig {
@Bean public ConcurrentMapCacheManager cacheManager() {
return new ConcurrentMapCacheManager();
}
}
@pledbrook
pledbrook / BuildConfig.groovy
Created October 19, 2012 13:37
Base Grails 1.3.3 dependency configuration for new plugin repository
grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"
//grails.project.war.file = "target/${appName}-${appVersion}.war"
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// uncomment to disable ehcache
// excludes 'ehcache'
}
// Grails 2.0.4
grails.project.dependency.resolution = {
// inherit Grails' default dependencies
inherits("global") {
// uncomment to disable ehcache
// excludes 'ehcache'
}
log "error" // log level of Ivy resolver, either 'error', 'warn', 'info', 'debug' or 'verbose'
checksums true // Whether to verify checksums on resolve
@pledbrook
pledbrook / gist:5858308
Created June 25, 2013 13:10
The dependency blocks in your Grails project's BuildConfig.groovy required to `maven-deploy` to [Bintray](http://www.bintray.com). The key is to exclude `wagon-http-lightweight` and include `wagon-http` instead.
dependencies {
build "org.apache.maven.wagon:wagon-http:2.4"
}
plugins {
build ":release:2.2.0", ":rest-client-builder:1.0.3", {
export = false
exclude "wagon-http-lightweight"
}
}
@pledbrook
pledbrook / gist:9e1e6e0e1a520b6a3612
Created June 26, 2014 10:09
Trying to redirect all paths below a given prefix (GET only)
ratpack {
...
handlers {
get {
...
}
prefix("blog") {
handler {
redirect 303, "http://blog.cacoethes.co.uk/${get(PathBinding).pastBinding}"