Skip to content

Instantly share code, notes, and snippets.

View joeRinehart's full-sized avatar

Joe Rinehart joeRinehart

  • Asheville, NC
View GitHub Profile
@joeRinehart
joeRinehart / BootStrap2.groovy
Created August 16, 2012 18:34
Spring Beans in Bootstrap
import org.springframework.web.context.support.WebApplicationContextUtils
class BootStrap {
def init = { servletContext ->
// Get spring
def springContext = WebApplicationContextUtils.getWebApplicationContext( servletContext )
}
}
@joeRinehart
joeRinehart / BootStrapSnip.groovy
Created August 16, 2012 18:46
Custom JSON marshalling
// Custom marshalling
springContext.getBean( "customObjectMarshallers" ).register()
package angulartodo
import org.springframework.dao.DataIntegrityViolationException
import grails.converters.JSON
class TodoController {
static allowedMethods = [ajaxList: "GET", ajaxSave: "POST", ajaxComplete: "POST"]
/**
@joeRinehart
joeRinehart / Album1.groovy
Created August 18, 2012 13:13
GrailsModelsPart2
package recordstore
class Album {
String name
static constraints = {
}
}
@joeRinehart
joeRinehart / Album.groovy
Created August 18, 2012 15:42
GrailsModelsPart2_2
package recordstore
class Album {
// Mappings
static hasMany = [
songs : Song
]
@joeRinehart
joeRinehart / Album.groovy
Created August 25, 2012 21:17
GrailsModelsPart3
package recordstore
class Album {
// Mappings
static hasMany = [
songs : Song,
artists : Artist
]
@joeRinehart
joeRinehart / Thing1.groovy
Created August 26, 2012 12:45
CustomMapping
package recordstore
class Thing {
static mapping = {
version false
autoTimestamp false
}
}
@joeRinehart
joeRinehart / snippet1.groovy
Created September 2, 2012 15:52
GrailsValidation
static constraints = {
name( blank: false )
}
@joeRinehart
joeRinehart / Closure.groovy
Created October 18, 2012 11:27
Grails for the Wicked Smaht 1
def outerVariable = "foo"
def closure = { closureArgument ->
println "$closureArgument $outerVariable"
}
(1..10).each{ i ->
closure.call( i ) //prints "1 foo", "2 foo", etc.
}
@joeRinehart
joeRinehart / DataAccess.groovy
Created October 18, 2012 11:52
Grails for the Wicked Smaht 2
def company = new Company( "Acme" )
def person = new Person( firstname : "Bob", lastname : "Bobbyson", age : 80 )
company.addToPeople( person )
company.save()
person.findByFirstName( "Bob" ) // finds all "Bob"s
person.findAll( "from Person where Company = :company", [ company: company ] )