Skip to content

Instantly share code, notes, and snippets.

View xlson's full-sized avatar

Leonard Gram xlson

View GitHub Profile
@xlson
xlson / updating-xml-with-XmlParser-and-NodeBuilder.groovy
Created March 19, 2010 08:41
Example of updating xml with Groovy using XmlParser and NodeBuilder.
def exampleXmlString = '''<?xml version="1.0" encoding="UTF-8"?>
<persons>
<person>
<name>John</name>
<lastname>Doe</lastname>
<age>38</age>
</person>
</persons>'''
def exampleXml = new XmlParser().parseText(exampleXmlString)
@xlson
xlson / TimeredMessage.groovy
Created May 27, 2010 12:46
Timered message used in a pomodoro. (Inspired by http://twitter.com/mahnve)
import javax.swing.*
def showTimeredMessage(String message, int afterSeconds = 600) {
sleep (afterSeconds*1000)
JOptionPane.showMessageDialog(null, message)
}
showTimeredMessage("Pomodoro over, get back to work! :)", 300)
@xlson
xlson / createplaceholders.groovy
Created June 3, 2010 17:07
Create placeholders before checking in a new project to git or your versioning system of choice.
#!/usr/bin/env groovy
assert args.size() == 1 : "Specify the path of the folder that needs placeholders."
def projectFolder = new File(args[0])
projectFolder.eachDirRecurse { dir ->
if(dir.list().size() == 0) {
def placeholder = new File(dir, '.PLACEHOLDER')
println "Creating: $placeholder.absolutePath"
placeholder.createNewFile()
@xlson
xlson / setgrails.groovy
Created June 14, 2010 08:24
Script used to easily change grails version on the commandline in OS X
#!/usr/bin/env groovy
/* setgrails: Script used to easily change grails version on the commandline in OS X
*
* My setup:
* /User/leo/Apps/grails Folder where all versions of grails are installed
* /User/leo/Apps/grails/grails A symlink pointing to the version of grails I'm currently using
* /User/leo/Apps/grails-1.3.1 One of the installed versions
*
* in ~/.profile
@xlson
xlson / ProblemWithGroovyTruth.groovy
Created June 18, 2010 09:21
Groovy custom truth and equals()
class Predicate {
boolean value
boolean asBoolean() { value }
}
// Works:
assert new Predicate(value: true)
assert !new Predicate(value: false)
assert (new Predicate(value: true) as Boolean == true)
assert (new Predicate(value: false) as Boolean == false)
@xlson
xlson / gist:542696
Created August 21, 2010 18:54
Example of using groupBy and collect together
// Example of using groupBy and collect together
def values =
[[lastname: "Anderson", age: 30],
[lastname: 'Bergstrom', age: 24],
[lastname: 'Anderson', age: 45],
[lastname: 'Bergstrom', age: 40],
[lastname: 'Brown', age: 25]]
// Find average age by lastname:
@xlson
xlson / Weceem 0.9.2 search stacktrace
Created September 30, 2010 11:45
Stacktrace from searching in a fresh install of Weceem 0.9.2 in Grails 1.3.4
Grails Runtime Exception
Error Details
Error 500: Executing action [show] of controller [org.weceem.controllers.WcmContentController] in plugin [weceem] caused exception: groovy.lang.MissingMethodException: No signature of method: org.weceem.services.WcmContentRepositoryService.resolveSpaceAndURI() is applicable for argument types: ([Ljava.lang.String;) values: [[/views/search-results, /]] Possible solutions: resolveSpaceAndURI(java.lang.String)
Servlet: grails
URI: /try-weceem/grails/wcmContent/show.dispatch
Exception Message: No signature of method: org.weceem.services.WcmContentRepositoryService.resolveSpaceAndURI() is applicable for argument types: ([Ljava.lang.String;) values: [[/views/search-results, /]] Possible solutions: resolveSpaceAndURI(java.lang.String)
Caused by: No signature of method: org.weceem.services.WcmContentRepositoryService.resolveSpaceAndURI() is applicable for argument types: ([Ljava.lang.String;) values: [[/views/search-results, /]] Possible solutions: resolveSpaceAndURI(java.lan
@xlson
xlson / LazyCollect.groovy
Created September 30, 2010 21:05
Implementation of a list.lazyCollect that will defer execution of the collect closure until get(i) is called
// Impl of a lazyCollect method that will not execute
// until you actually ask for the value
class LazyCollectList extends AbstractList {
private Closure collectClosure
private List backingList
private Map cached = [:]
@xlson
xlson / mp4it
Created October 7, 2010 14:29
Groovy script that uses ffmpeg to convert an avi file into a mp4 for viewing on an iPhone or iPod
#!/usr/bin/env groovy
// Validating arguments
assert args.size() == 1 : "mp4it takes 1 argument: the path to the file to be conerted into mp4"
assert new File(args[0]).exists() : "The file you specified could not be found."
def videoFilePath = args[0]
def outputFilePath = videoFilePath.replaceAll(/\.avi$/, '.mp4')
assert !new File(outputFilePath).exists()
@xlson
xlson / gist:647043
Created October 26, 2010 14:57
Add as bookmark for "New Tab"-functionality in Safari on the iPad
javascript:window.open('about:blank')