Skip to content

Instantly share code, notes, and snippets.

View xlson's full-sized avatar

Leonard Gram xlson

View GitHub 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 / 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 / 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 / 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 / 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)