Skip to content

Instantly share code, notes, and snippets.

@tednaleid
tednaleid / gist:118407
Created May 27, 2009 01:28
adding arguments to GORM save through metaClass
// do this in the plugins doWithDynamic methods on each domain class:
def domainClass = grailsApplication.getDomainClass("Foo")
def clazz = domainClass.clazz
// prime the pump to get the GORM methods actually decorated and available on the meta class
clazz.count()
clazz.metaClass.invokeMethod = { String name, args ->
if (name == "save" && args[0] instanceof Map) {
@tednaleid
tednaleid / gist:118797
Created May 27, 2009 18:18
alternate way to replace GORM save method and add named parms
// do this in the plugins doWithDynamic methods on each domain class:
def domainClass = grailsApplication.getDomainClass("Foo")
def clazz = domainClass.clazz
// prime the pump to get the GORM methods actually decorated and available on the meta class
clazz.count()
def oldSave = clazz.metaClass.getMetaMethod("save", [java.util.Map] as Class[])
clazz.metaClass.save = { java.util.Map args ->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>TerminalColours</string>
<key>CFBundleIdentifier</key>
<string>sh.ciaranwal.terminal-colours</string>
def findResult (collection, closure) {
for ( value in collection) {
def result = closure(value)
if (result != null) return result
}
}
assert "5foo" == findResult([1, 2, 3, 4, 5, 6, 7]) {
if (it >= 5) return "${it}foo"
}
@tednaleid
tednaleid / ipadchrome_alias
Created October 25, 2011 18:43
alias to launch google chrome with the iPad user-agent
alias ipadchrome='open /Applications/Google\ Chrome.app --args -user-agent="Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10"'
@tednaleid
tednaleid / bootstrap_diff
Created July 22, 2012 03:07
removing redundant `packageApp()` call in bootstrap target shaves ~1sec off many grails commands for me
Not sure if this causes issues elsewhere, but `test-app`, `run-app`, and `package` seem fine. The `packageApp()` method is called again in `loadApp()` so this one seems redundant.
Shaves off about a second for me on a larger app as it removes a redundant call. YMMV, put it back if you see any issues:
diff --git a/scripts/_GrailsBootstrap.groovy b/scripts/_GrailsBootstrap.groovy
index 4c44aa3..218a41a 100644
--- a/scripts/_GrailsBootstrap.groovy
+++ b/scripts/_GrailsBootstrap.groovy
@@ -126,7 +126,7 @@ target(monitorApp:"Monitors an application for changes using the PluginMana
}
# execute with `mvimvproject <projname>`
function mvimproject() {
SCRIPT='mvimhere.command'
if [ -n "$1" ]
then
SCRIPT=$1.command
fi
cat <<EOF>$SCRIPT
#! /usr/bin/env sh
BASEDIR=\$(dirname \$0)
@tednaleid
tednaleid / grailsScriptTiming.diff
Created August 28, 2012 16:09
output every grails event with timing
diff --git a/scripts/_GrailsEvents.groovy b/scripts/_GrailsEvents.groovy
index bc0b479..bb8f13e 100644
--- a/scripts/_GrailsEvents.groovy
+++ b/scripts/_GrailsEvents.groovy
@@ -49,13 +49,19 @@ binding.addBuildListener(eventListener)
// Set up the classpath for the event hooks.
classpath()
// Now load them.
eventListener.classLoader = new GroovyClassLoader(classLoader)
@tednaleid
tednaleid / scrape_xkcd_map.sh
Created September 19, 2012 13:56
ZSH Script to scrape all the map tiles from http://xkcd.com/1110/
#! /usr/bin/env zsh
# after writing, found this link on Hacker News:
# DON'T RUN THIS, GO HERE INSTEAD: http://xkcd-map.rent-a-geek.de/
for NS in n s; do
for i in {1..25}; do
for WE in w e; do
for j in {1..25}; do
wget http://imgs.xkcd.com/clickdrag/$i$NS$j$WE.png
@tednaleid
tednaleid / Optional.groovy
Last active December 23, 2015 03:39
Fixing typos/cut paste error in Spec messages. Also changing toString to be just a passthrough to the object (or safe for null) as I think you'd just want the original object string and wouldn't want to pollute your output with the fact that it's wrapped in an Optional.
import groovy.transform.Canonical
import spock.lang.Specification
@Canonical
class Optional<T> {
T reference
T get() {
if (isPresent()) return reference