Skip to content

Instantly share code, notes, and snippets.

@ishults
ishults / modifiedFilter.groovy
Last active December 16, 2015 20:10
Modified Hibernate stats controller filter
def sessionFactory
// ...
logHibernateStats(controller: '*', action: '*') {
before = {
Statistics stats = sessionFactory.statistics
log.info "\n### In action: $controllerName/$actionName ###"
private static final String START_TIME = 'Hibernate_Start_Time'
def filters = {
logHibernateStats(controller: '*', action: '*') {
before = {
request[START_TIME] = System.currentTimeMillis()
}
afterView = {
Long end = System.currentTimeMillis()
logHibernateStats = 'NEVER'
// ...
development {
logHibernateStats = 'ALWAYS' // From ALWAYS, ALLOWED, NEVER
}
private static final String START_TIME = 'Hibernate_Start_Time'
def sessionFactory
// ...
logHibernateStats(controller: '*', action: '*') {
before = {
String enabledString = grailsApplication.config.logHibernateStats
Statistics stats = sessionFactory.statistics
@ishults
ishults / gitTestModified.sh
Last active February 14, 2017 18:36
Main script
#!/bin/sh
usage(){
echo "Usage: `basename $0` [-h] [-r] [-t testOptions] [<directory>...]\n"
echo ' -h Show this help message.'
echo ' -r Remove the default directories, and only use the ones provided. Without the flag, the provided directories will be appended to the default list.'
echo ' -t Options to pass to "grails test-app". Default: none.'
echo ' See: http://grails.org/doc/latest/ref/Command%20Line/test-app.html'
}
# Parse the arguments
Usage: gitTestModified.sh [-h] [-r] [-t testOptions] [...]</code>
-h Show this help message.
-r Only check the directories provided. Otherwise, the provided directories will be appended to the directory list.
-t Options to pass to "grails test-app". Default: none.
See: http://grails.org/doc/latest/ref/Command%20Line/test-app.html
@ishults
ishults / simple.groovy
Last active December 16, 2015 20:09
Simple multiple assignment in Groovy
def (foo, bar) = ['foo', 'bar'];
assert foo == 'foo'
assert bar == 'bar'
@ishults
ishults / limitation.groovy
Last active December 16, 2015 20:09
Limitation of multiple assignment
(p.firstname, p.lastname) = "My name".split()
@ishults
ishults / example.groovy
Last active December 16, 2015 20:09
Simple class and enum
class Dog {
Integer age
String name
Color color
}
enum Color {
BLACK,
GOLD,
WHITE
@ishults
ishults / beforeWith.groovy
Last active December 16, 2015 20:09
Regular assignment
Dog dog = new Dog()
//...
dog.name = 'Rex'
dog.age = 2
dog.color = Color.BLACK