Skip to content

Instantly share code, notes, and snippets.

View spinscale's full-sized avatar
💻

Alexander Reelsen spinscale

💻
View GitHub Profile
@spinscale
spinscale / gist:2888456
Created June 7, 2012 12:09
Using a morphia entity in several db collections in MongoDB
/**
I have the need to use one morphia entity in several collections, because I use mongodb as a queue
The only solution I have found so far is to create a custom datastore, which maps to a certain db collection. This was my try: In case there is a cleaner solution, feel free to drop me a note
Datastore importDatastore = new CustomDatastore(Product.class, mongo, morphia, "import");
Datastore exportDatastore = new CustomDatastore(Product.class, mongo, morphia, "export");
ProductDao importQueueDao = new ProductDao(Product.class, importDatastore);
ProductDao exportQueueDao = new ProductDao(Product.class, exportDatastore);
@spinscale
spinscale / DropwizardTestServer.java
Created November 25, 2012 19:25
Dropwizard testing rule for 0.6.0 SNAPSHOT
package de.spinscale.test;
import com.yammer.dropwizard.Service;
import com.yammer.dropwizard.bundles.BasicBundle;
import com.yammer.dropwizard.cli.Cli;
import com.yammer.dropwizard.cli.ServerCommand;
import com.yammer.dropwizard.config.Bootstrap;
import com.yammer.dropwizard.config.Configuration;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
@spinscale
spinscale / gist:4713610
Created February 5, 2013 10:34
spark-groovy-jrebel-first-sample
get "/", { Request request, Response response ->
jade "index.jade", [title: 'My page']
}
@spinscale
spinscale / gist:4713618
Created February 5, 2013 10:35
spark-groovy-jrebel-helloworld-java
import static spark.Spark.*;
import spark.*;
public class HelloWorld {
public static void main(String[] args) {
before(new Filter() { // matches all routes
@Override
public void handle(Request request, Response response) {
boolean authenticated;
@spinscale
spinscale / gist:4713622
Created February 5, 2013 10:36
spark-groovy-jrebel-create-project
mkdir groovy-spark
cd groovy-spark
mkdir -p src/main/groovy
mkdir -p src/main/resources
mkdir -p src/test/groovy
mkdir -p src/test/resources
@spinscale
spinscale / gist:4713627
Created February 5, 2013 10:37
spark-groovy-jrebel-build.gradle
apply plugin: 'groovy'
apply plugin: 'idea'
repositories {
mavenCentral()
maven { url "http://www.sparkjava.com/nexus/content/repositories/spark/" }
maven { url "https://raw.github.com/neuland/jade4j/master/releases" }
}
// avoid groovy/jade asm clashes
@spinscale
spinscale / gist:4713635
Created February 5, 2013 10:38
spark-groovy-jrebel-simpler
import spark.*
class WebServer extends SparkGroovy {
static void main(String[] args) {
new WebServer().init();
}
void init() {
before { Request req, Response res ->
@spinscale
spinscale / gist:4713643
Created February 5, 2013 10:40
spark-groovy-jrebel-first-closure-get
def get(String path, Closure closure) {
Spark.get(new Route(path) {
def handle(Request request, Response response) {
closure.delegate = this
return closure.call(request, response)
}
})
}
@spinscale
spinscale / gist:4713646
Created February 5, 2013 10:40
spark-groovy-jrebel-formats
get "/foo.json", { Request request, Response response ->
json([foo: 'bar'])
}
get "/jade", { Request request, Response response ->
jade "test.jade", [foo: 'bar', pageName: 'My page']
}
static JadeConfiguration config = new JadeConfiguration()
static {
config.setTemplateLoader(new FileTemplateLoader("src/main/resources/views/", "UTF-8"))
}
def json(Object obj) {
return JSON.default.toJSON(obj)
}
def jade(String template, Object obj) {