Skip to content

Instantly share code, notes, and snippets.

@chanwit
chanwit / StudentController.groovy
Created June 5, 2012 19:53
A controller as an OSGi-based micro-service
import org.apache.aries.blueprint.annotation.*
@Inject studentService
get("/students/:id") {
def student = studentService.get(urlparams.id)
"Hello, ${student.name}"
}
{"slot-request":
{"date": "2010-01-04", "doctor": "mjones"}
}
{"slots":[
{"start":"1400", "end":"1450", "doctor":"mjones"},
{"start":"1600", "end":"1650", "doctor":"mjones"}
]}
// A Spock spec to test ZK that I'd like to see.
spec "Test ZK" {
setup:
testFor("a.zul")
when:
$('btnTest').click()
then:
@chanwit
chanwit / gogo.groovy
Created September 1, 2012 05:02
Gogoanime Script
#!/usr/bin/env groovy
@Grab('org.jsoup:jsoup:1.6.1')
import static org.jsoup.Jsoup.*
def doc = connect("http://www.gogoanime.com").get()
def table = doc.select('#content > div.post > div > table')
println table[1].select('td')[0].select('li').collect { it.text() }.join('\n')
@chanwit
chanwit / HibernateProjectionsAlias.groovy
Created September 11, 2012 14:18
GORM Hibernate Projection Alias to Map
import zello.*
import org.hibernate.transform.AliasToEntityMapResultTransformer
new Task(subject:'test 222').save()
Task.createCriteria().get {
projections {
countDistinct('subject', 'count')
}
resultTransformer(AliasToEntityMapResultTransformer.INSTANCE)
class CategoryComposer extends GrailsComposer {
def afterCompose = { window ->
$('#units').append {
for(u in Uom.findAll()) {
comboitem(label: u, value: u)
}
}
class CheckboxComposer extends GrailsComposer {
def afterCompose = {
$('button').on('click', {
for(cb in $('checkbox[checked=true]')) {
alert(cb.label + " :: " + cb.checked)
}
})
}
composer = testFor(ProductComposer, "product.zul")
composer.afterCompose(composer.root)
$('#name').ok()
assert $('#category').is(':focus') == true
mock(Category).static.findAll().returns(["A", "B"])
play {
$('#category').load(Category.findAll())
@chanwit
chanwit / gist:4556080
Last active December 11, 2015 05:58
jQuery extensions
static String preprocess(query) {
query.replaceAll(/:(eq|lt|gt|even|odd)(\(.*?\))?/, { m, s, x ->
if(x) { x = x[1..-2] }
switch(s) {
case "eq": return ":nth-child(${x.toInteger()+1})"
case "lt": return ":nth-child(-n+${x})"
case "gt": return ":nth-child(n+${x})"
case "even": return ":nth-child(2n)"
case "odd": return ":nth-child(2n+1)"
}
def results = TaskList.list() - TaskList.where {
tasks {
priority == 0L && done == false
}
}.list()
/**
def TaskList.where {
notExists {
tasks {
priority == 0L && done == false