Skip to content

Instantly share code, notes, and snippets.

@berngp
berngp / cleanApp.groovy
Created March 11, 2011 07:11
Grails cleanApp scripts, removes what Clean would except the plugins at ~/.grails/<version>/projects/<your project>
/*
* Copyright 2004-2005 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@berngp
berngp / ThrowableXMLMarshaller.groovy
Created April 13, 2011 19:26
ThrowableXMLMarshallerSpec.groovy
package org.osscripters.grails.common.web.converters.marshaller
import grails.converters.XML
import org.codehaus.groovy.grails.web.converters.exceptions.ConverterException
import org.codehaus.groovy.grails.web.converters.marshaller.NameAwareMarshaller
import org.gcontracts.annotations.Requires
/**
* User: berngp
* Date: 4/12/11
@berngp
berngp / MarshallerSpecSupport.groovy
Created April 14, 2011 17:53
Unit Testing Custom Object Marshallers with Spock in Grails
package org.osscripters.grails.common.web.converters.marshaller
import grails.plugin.spock.ControllerSpec
import org.codehaus.groovy.grails.support.MockApplicationContext
import org.codehaus.groovy.grails.web.converters.ConverterUtil
import org.codehaus.groovy.grails.web.converters.configuration.ConvertersConfigurationInitializer
import org.springframework.validation.Errors
import org.springframework.web.context.WebApplicationContext
/**
@berngp
berngp / SomeLegacyStatus.groovy
Created April 19, 2011 19:27
Trying to simplify access to a legacy Lookup Table
package org.some.package
class SomeLegacyStatus {
enum Status {
NONE,
ACTIVE,
PENDING,
SUSPENDED,
BANNED,
@berngp
berngp / setup.groovy
Created April 22, 2011 01:33
Missing renderer for Unit Testing within Grails
controller.metaClass.render = {Map map, Closure closure ->
renderArgs.putAll(map)
switch(map.contentType) {
case null:
break
case 'application/xml':
case 'text/xml':
def smb = new StreamingMarkupBuilder()
if (map.encoding){
@berngp
berngp / grails-app.conf.JMSSpringBeans.groovy
Created May 3, 2011 19:19
Splitting SpringBeans files in Grails (Examples with JMS and JMX Bean files)
//grails-app/conf/JMSSpringBeans.groovy
import grails.util.Environment
import org.apache.activemq.spring.ActiveMQConnectionFactory
import org.springframework.jms.connection.SingleConnectionFactory
import grails.util.Environment
import org.apache.activemq.spring.ActiveMQConnectionFactory
import org.springframework.jms.connection.SingleConnectionFactory
beans {
0. Sudo
1. Setup your Clojure distributions, including clojure-contrib
e.g.
root@bowman-europa:/usr/local/clojure# ll
total 8
drwxr-xr-x 8 root root 4096 2011-07-14 19:32 clojure-1.2.1
drwxr-xr-x 6 root root 4096 2010-08-19 11:02 clojure-contrib-1.2.0
lrwxrwxrwx 1 root root 13 2011-07-14 19:37 current -> clojure-1.2.1
lrwxrwxrwx 1 root root 21 2011-07-14 20:50 current-contrib -> clojure-contrib-1.2.0
@berngp
berngp / gist:1358895
Created November 11, 2011 19:06
Lift RestHelper and the SI-1133
/**
* Fails with https://issues.scala-lang.org/browse/SI-1133
* Workaround: Split the <i>cases</i> inside <i>serve</i> into two or more
* <i>serve</i> blocks.
*
* Note: To avoid noise all cases bellow are returning a NotFoundResponse().
*/
object CategoryAdminResource extends RestHelper with Loggable {
@berngp
berngp / Meta.scala
Created November 21, 2011 06:10
Lift MongoMapField with support of embedded collections.
package com.ign.lift.record
import java.util.{Calendar, Date, GregorianCalendar, UUID}
import java.util.regex.Pattern
import net.liftweb.json.JsonAST._
import net.liftweb.json.Formats
import com.mongodb.{BasicDBList, BasicDBObject, DBRef}
import scala.collection.JavaConversions._
import org.bson.types.ObjectId
@berngp
berngp / Measurable.scala
Created January 4, 2012 01:32
Trait with NewRelic and Scala Metrics.
import com.newrelic.api.agent.NewRelic
import collection.mutable.{HashMap, SynchronizedMap}
import com.yammer.metrics.{Timer, MetricsGroup}
trait Measurable {
protected lazy val metricsGroup = new MetricsGroup(this.getClass)
private val timers = new HashMap[String, Timer] with SynchronizedMap[String, Timer]