Skip to content

Instantly share code, notes, and snippets.

View ddelponte's full-sized avatar

Dean Del Ponte ddelponte

View GitHub Profile
@ddelponte
ddelponte / controllerAndServiceValidationHandling.groovy
Created December 5, 2012 16:14
Grails Service: Validation Errors and Rollback
Validation Errors and Rollback
A common use case is to rollback a transaction if there are validation errors. For example consider this service:
import grails.validation.ValidationException
class AuthorService {
void updateAge(id, int age) {
def author = Author.get(id)
author.age = age
if (!author.validate()) {
@ddelponte
ddelponte / jQueryOnload.js
Last active October 13, 2015 16:38
jQuery onLoad
jQuery(document).ready(function() {
// Handler for .ready() called.
});
@ddelponte
ddelponte / intellij-runapp
Created January 15, 2013 19:45
IntelliJ run-app settings
-XX:MaxPermSize=512m -Xmx4096m
public Map generateAssignments(List<String> participants) {
def assignees = participants.clone()
Collections.shuffle(participants)
Collections.shuffle(assignees)
def assignments = [:]
participants.each { participant ->
def assignee = assignees.find{ it != participant}
assignments[assignee] = participant
@ddelponte
ddelponte / MaxPermSize.sh
Created March 8, 2013 16:13
Run this to avoid PermGen errors when running Grails integration tests at the command line
export JAVA_OPTS="-XX:MaxPermSize=512m"
@ddelponte
ddelponte / Create database
Created March 8, 2013 16:19
Create MySQL database
CREATE DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;
or
CREATE DATABASE dbname CHARACTER SET utf8 COLLATE utf8_bin;
@ddelponte
ddelponte / rowCount.groovy
Created March 15, 2013 17:45
Groovy SQL example of counting rows
def countRows = db.firstRow("select count(*) as numberOfRows from languages")
assert 4 == countRows.numberOfRows
@ddelponte
ddelponte / Associated inputs on form
Created March 26, 2013 19:31
Handling associated form inputs in Grails
// A form with associated inputs
<g:form action="seed">
<g:each in="${teams}" status="i" var="team">
<input type="hidden" name="teams.${i}.id" value="${team.id}">
<input type="text" size="2" name="teams.${i}.seed" value="${team.seed}">
</g:each>
@ddelponte
ddelponte / git goodness
Created April 9, 2013 12:42
Push a new local branch to a new remote branch
git push -u origin your_branch
@ddelponte
ddelponte / ErrorMessage.groovy
Created April 30, 2013 12:07
How to get the error message from a ValidationException
def errorMessages = ex.errors.collect { g.message(error:it) }