Skip to content

Instantly share code, notes, and snippets.

<a onclick="view.person.showPerson(); return false;">Show person</a>
<div id="person-div"></div>
define('view/person', ['domain/person', 'jQuery', 'window'], function(Person, $, Win) {
var person = Person.createPerson();
return {
showPerson: function() {
$('#person-div').html(person.name);
Win.alert('Person updated!');
}
};
@jurberg
jurberg / requirejs.gsp
Last active December 12, 2015 02:29
Use different Require.JS main when running in a war
<script src="js/lib/require-2.1.2.js"
data-main="js/bootstrap${grailsApplication.isWarDeployed() ? '-build' : ''}">
</script>
@jurberg
jurberg / requirejs.groovy
Last active December 12, 2015 02:29
Run the Require.JS optimizer when creating a war file.
eventCreateWarStart = { warName, stagingDir ->
def curDir = new File('Scripts');
ant.exec(outputproperty: "cmdOut", errorproperty: "cmdErr", resultproperty: "cmdExit", failonerror: "false", executable: "java") {
arg(line: "-cp ${new File(curDir, 'js.jar').absolutePath}")
arg(line: "org.mozilla.javascript.tools.shell.Main")
arg(line: "${new File(curDir, 'r.js').absolutePath}")
arg(line: "-o")
arg(line: "name=bootstrap")
arg(line: "baseUrl=${stagingDir}/js")
arg(line: "out=${stagingDir}/js/bootstrap-build.js")
@jurberg
jurberg / eventWebXmlEnd.groovy
Created January 24, 2013 04:02
Adding a context-param to the beginning a Grails app web.xml
eventWebXmlEnd = { String tmpfile ->
def contextParam = '''<context-param>
<description>Spring Expression Language Support</description>
<param-name>springJspExpressionSupport</param-name>
<param-value>false</param-value>
</context-param>'''
def root = new XmlParser().parse(webXmlFile)
root.children().add(0, new XmlParser().parseText(contextParam))
new XmlNodePrinter(new PrintWriter(new FileWriter(webXmlFile))).print(root)
}
@jurberg
jurberg / Jaxb-no-jxc.groovy
Created December 2, 2012 01:19
Generate JAXB classes without jaxb-jxc on your classpath
Ant.java(classname: "com.sun.tools.internal.xjc.XJCFacade") {
arg(value: "-d")
arg(value: "src/java")
arg(value: "-p")
arg(value: "com.microsoft.books")
arg(value: "etc/schema/books.xsd")
}
@jurberg
jurberg / GenerateSources.groovy
Created November 28, 2012 02:41
Groovy script to generate JAXB classes from an XSD
// Add the following to BuildConfig.groovy:
// build('com.sun.xml.bind:jaxb-xjc:2.1')
// build('com.sun.xml.bind:jaxb-impl:2.1')
target('generateSources': "Generate JAXB classes from a schema") {
def classpath = grailsSettings
.getBuildDependencies()
.join(System.getProperty("path.separator"))
Ant.taskdef(name: "xjc",
classname: "com.sun.tools.xjc.XJCTask",
classpath: classpath)
@jurberg
jurberg / drop_constraints.sql
Created November 28, 2012 02:14
Drop all table constraints in Oracle
-- Drop all table constraints:
BEGIN
FOR c IN
(SELECT c.owner, c.table_name, c.constraint_name
FROM user_constraints c, user_tables t
WHERE c.table_name = t.table_name
AND c.status = 'ENABLED'
ORDER BY c.constraint_type DESC)
LOOP
dbms_utility.exec_ddl_statement('alter table "' || c.owner || '"."' || c.table_name || '" disable constraint ' || c.constraint_name);
@jurberg
jurberg / XmlToFlatFileMapping.groovy
Created November 11, 2012 21:09
Convert XML to Flat File Mapping
def mapping = [[closure: { book.@id.text() }, length: 5],
[closure: { book.author.text().split(',')[0] }, length: 15],
[closure: { book.author.text().split(',')[1] }, length: 10]]
@jurberg
jurberg / XmlToFlatFileTest.groovy
Created November 11, 2012 20:12
Convert XML to Flat File Test
def sep = System.getProperty('line.separator')
def expected =
"bk101Gambardella Matthew " + sep +
"bk102Ralls Kim " + sep +
"bk103Corets Eva " + sep
void testParsing() {
def books = new XmlSlurper().parseText(data)
assertEquals expected, xmlToFlatFile(books, 'book', mapping)
}