Skip to content

Instantly share code, notes, and snippets.

View graemerocher's full-sized avatar

Graeme Rocher graemerocher

View GitHub Profile
@graemerocher
graemerocher / TickTockController.groovy
Last active July 28, 2016 15:58
RxJava for Grails Async Comet Example
class TickTockController {
def index() {
Observable.create({ Subscriber subscriber ->
task {
for(i in (0..20)) {
if(i % 2 == 0) {
subscriber.onNext(
Rx.render("Tick")
)
@graemerocher
graemerocher / oci-grailsframework-cla.txt
Last active February 15, 2016 13:25
OCi Grails Framework CLA
Grails Framework
Individual Contributor License Agreement
By signing below, you accept and agree to the following terms and conditions for Your present and future Contributions submitted to OCI in connection with the Grails project. In return, OCI shall not use Your Contributions in a way that is contrary to the public benefit or inconsistent with the Apache License v. 2.0. Except for the license granted herein to OCI and recipients of software distributed by OCI, You reserve all right, title, and interest in and to Your Contributions.
1. Definitions. "You" (or "Your") shall mean the copyright owner or legal entity authorized by the copyright owner that is making this Agreement with OCI. For legal entities, the entity making a Contribution and all other entities that control, are controlled by, or are under common control with that entity are considered to be a single Contributor. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of
@graemerocher
graemerocher / boot-gorm-mongodb.groovy
Last active December 24, 2015 03:11
Using GORM for MongoDB in Spring Boot
@Grab("org.grails:gorm-mongodb-spring-boot:1.0.0.RC1")
import grails.persistence.*
import grails.mongodb.geo.*
import org.bson.types.ObjectId
import com.mongodb.BasicDBObject
import org.springframework.http.*
import org.springframework.beans.factory.annotation.Autowired
import static org.springframework.web.bind.annotation.RequestMethod.*
@RestController
@graemerocher
graemerocher / gist:1393603
Created November 25, 2011 14:08
Using GORM from MongoDB from a Groovy Script
@GrabResolver(name='grails-core', root='http://repo.grails.org/grails/core')
@Grab(group='org.grails', module='grails-datastore-gorm-mongo', version='1.0.0.BUILD-SNAPSHOT')
@Grab(group='org.slf4j', module='slf4j-simple', version='1.6.1')
import grails.persistence.*
import org.grails.datastore.gorm.mongo.config.*
MongoDatastoreConfigurer.configure("myDatabase", Book)
Book.withSession {
@graemerocher
graemerocher / compile
Created September 21, 2011 08:27 — forked from jesperfj/compile
Grails LP
#!/usr/bin/env bash
# bin/compile <build-dir> <cache-dir>
# fail fast
set -e
BIN_DIR=$(cd $(dirname $0); pwd) # absolute path
# parse args
BUILD_DIR=$1
CACHE_DIR=$2
import groovy.xml.*
trait MyBuilder {
def build2() {
def mkp = new MarkupBuilder()
mkp.foo {
bar()
}
}
@graemerocher
graemerocher / keybase.md
Created March 24, 2015 11:27
keybase.md

Keybase proof

I hereby claim:

  • I am graemerocher on github.
  • I am graemerocher (https://keybase.io/graemerocher) on keybase.
  • I have a public key whose fingerprint is E9CD A0A0 60BC E2BC 9BE9 9C4B 1BC6 016E FBF4 6539

To claim this, I am signing this object:

@graemerocher
graemerocher / raw-hibernate-vs-gorm-correlated-subqueries.java
Created April 29, 2014 08:49
Raw Hibernate vs GORM for Hibernate Correlated Subqueries
// Raw Hibernate
DetachedCriteria employeeCriteria = DetachedCriteria.forClass(Employee.class);
employeeCriteria.createAlias("region", "region").setFetchMode("region", FetchMode.JOIN);
employeeCriteria.add(forName("region.continent").in("APAC","EMEA"));
employeeCriteria.setProjection(distinct(property("employeeId")));
Criteria salesCriteria = sessionFactory.getCurrentSession().createCriteria(Sale.class)
salesCriteria.add(forName("employeeId").in(employeeCriteria));
salesCriteria.add(Restrictions.gt("total",100000));
salesCriteria.setProjection(distinct(property("employeeId")));
@graemerocher
graemerocher / boot-gorm-hibernate4.groovy
Created April 4, 2014 08:21
Using GORM for Hibernate 4 in Spring Boot
@Grab("org.grails:gorm-hibernate4-spring-boot:1.0.0.RC2")
@Grab("com.h2database:h2:1.3.173")
import grails.persistence.*
import org.springframework.http.*
import static org.springframework.web.bind.annotation.RequestMethod.*
@RestController
class GreetingController {
@RequestMapping(value="/person/greet", method = GET)