Skip to content

Instantly share code, notes, and snippets.

View spinscale's full-sized avatar
💻

Alexander Reelsen spinscale

💻
View GitHub Profile
def get(String path, Closure ... closures) {
spark.Spark.get(createClosureBasedRouteForPath(path, closures))
}
private Route createClosureBasedRouteForPath(String path, Closure ... closures) {
new Route(path) {
def handle(Request request, Response response) {
closures*.delegate = this
return closures*.call(request, response).findAll { it }.join()
}
@spinscale
spinscale / gist:4713664
Created February 5, 2013 10:43
spark-groovy-jrebel-closure-chain
def authCheck = { Request request, Response response ->
if (request.session().attribute('userLogin') != request.params(':name')) {
halt(401, "No permissions to check for ${request.params(":name")}\n")
}
}
get "/greet/:name", authCheck, { Request request, Response response ->
return "Hello " + request.params('name') + "\n"
}
@spinscale
spinscale / gist:4713671
Created February 5, 2013 10:44
spark-groovy-jrebel-formats
def jsonClosure = { Request request, Response response ->
if (request.contentType() == 'application/json')
json([name: request.attribute('name')])
}
def xmlClosure = { Request request, Response response ->
if (request.contentType() == 'application/xml')
'<name>' + request.attribute('name') + '</name>\n'
}
@spinscale
spinscale / gist:4713674
Created February 5, 2013 10:45
spark-groovy-jrebel-curl
# curl -v -X POST localhost:4567/login/foo
> POST /login/foo HTTP/1.1
> User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8r zlib/1.2.3
> Host: localhost:4567
> Accept: */*
>
< HTTP/1.1 204 No Content
< Set-Cookie: JSESSIONID=1pouphqxh5z3l1pusx23ewksw6;Path=/
< Expires: Thu, 01-Jan-1970 00:00:00 GMT
@spinscale
spinscale / gist:4713676
Created February 5, 2013 10:45
spark-groovy-jrebel-setup
-Drebel.plugins=/path/to/jrebel-spark-plugin/target/jrebel-plugin-spark-0.1-SNAPSHOT.jar
-Drebel.jr-spark-groovy=true
-Drebel.spark.app.class=de.spinscale.spark.WebServer
-Drebel.spark.app.method=init
@spinscale
spinscale / install-elasticsearch.sh
Created April 8, 2013 12:13
Create an elasticsearch specific versioned instance quickly
#!/bin/bash
set -e
if [ "x$1" == "x-h" ] ; then
echo "Usage: $0 version destdir plugins"
exit
fi
CURRENT="0.90.0.RC1"
@spinscale
spinscale / gist:5466258
Created April 26, 2013 10:09
Geo location reproduction.
curl -X PUT localhost:9200/geotest/
curl -X PUT localhost:9200/geotest/geotest/_mapping -d '{
"geotest": {
"properties": {
"location": {
"type": "geo_point",
"lat_lon": true,
"geohash": true
}
# GET ES
# https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.2.1.zip
# Unzip it
# unzip elasticsearch-1.2.1.zip
# cd elasticsearch-1.2.1
# Look around
# Show structure
@spinscale
spinscale / readme.md
Created July 24, 2014 07:07
Using iTerm2 notification capabilities

Notification of finished builds in iTerm2

iTerm2 has a neat feature called a trigger, which you can use to notify you about finished maven builds (failure or success) or anything else happening in your console.

Install terminal notifier

brew install terminal-notifier
@spinscale
spinscale / app.js
Created January 11, 2015 21:43
simple flash scope using expressjs
// poor mans flash scope
// message appears once, but reloading in the browser makes it vanish
app.use(function(req, res, next){
if (req.session.message !== null) {
res.locals.message = req.session.message
req.session.message = null
}
next();
});