Skip to content

Instantly share code, notes, and snippets.

View spikeheap's full-sized avatar

Ryan Brooks spikeheap

View GitHub Profile
@spikeheap
spikeheap / comms_api.json
Last active August 29, 2015 14:03
JSON structure for CodeRetreat client-server comms
// Connection request from client, and update every time a test set is run
{
"action": "consumeTestsResults",
"payload": {
"session": 0,
"testsRun": 10,
"testsFailed": 5,
"testsIgnored": 2
}
}
@spikeheap
spikeheap / MapConstructorExample.groovy
Last active August 29, 2015 14:02
Refactoring a traditional Java builder to use Groovy's map constructor
// The following
def name = new com.mirth.results.models.NameModel()
name.setPrefix(it[4].toString())
name.setFirst(it[1].toString())
name.setMiddle(it[2].toString())
name.setLast(it[0].toString())
expectedPatient.setName(name)
// Can be written without .toString and using Groovy's map constructor!
expectedPatient.name = new com.mirth.results.models.NameModel(
@spikeheap
spikeheap / comparison.groovy
Last active August 29, 2015 14:02
Simple introspection to dig into model inequality in Spock tests
def expected
def actual
def propertiesToCompare = expected.class.declaredFields.findAll { !(it.name =~ /^__/ || it.name =~ /^\$/ || it.name == "metaClass") }
// For each property prints [equality] : [property name] -> [expected value] -|- [actual value]
propertiesToCompare.each { property ->
println "${expected[property.name] == actual[property.name]} : ${property} -> ${expected[property.name]} -|exp: ${actual[property.name]} "
}
@spikeheap
spikeheap / build.gradle
Created June 17, 2014 12:18
Sample Gradle buildfile for Groovy/IntelliJ support
apply plugin: 'groovy'
apply plugin: 'idea'
project.description = 'something awesome'
project.version = "1.0.0-SNAPSHOT"
project.group = "uk.co.ryanbrooks.example"
repositories {
mavenLocal()
jcenter()
@spikeheap
spikeheap / LittleFunctionSpec.groovy
Created March 27, 2014 14:16
Using Spock and Gradle to test JavaScript running on Rhino. See http://ryanbrooks.co.uk/posts/2014-03-27-testing-rhino-js-spock/ for the context.
package my.package
class LittleFunctionSpec extends Specification{
Context context
Scriptable scope
/**
* Setup, prior to every spec test
*/
void setup(){
@spikeheap
spikeheap / Readme.md
Created February 27, 2014 18:56
Disqus for your homepage

Disqus homepage comments

I really do get on well with docpad. Despite wanting to move to a JVM-based static site generator, docpad does too many things to make me want to leave. It's not perfect, but it has plugins to solve mosts of your basic problems, and is nicely hackable. Plus it's written in CoffeScript, which is always a plus. Adding comments to the homepage blog entry was a little tricky though

The services plugin provides a neat way to inject Disqus comment threads into your pages. It's almost no configuration, and works reliably, but it doesn't work when you're rendering dynamic content, for example the latest blog post on your home page.

Everything worked well until Disqus got confused. First it displayed the comments from a blog post on the homepage when it was no longer correct. Then it just started displaying the comment thread on all pages which didn't have their own threads already. Not so good.

@spikeheap
spikeheap / 1_obvious_approach.groovy
Last active August 29, 2015 13:56
Using Grails 'respond' for HTML, JSON and XML responses
def show(Widget widget){
// renders a blank page for null objects
respond widget, [model: [widget: widget]]
}
@spikeheap
spikeheap / MongoConnection.groovy
Last active August 29, 2015 13:56
Sample mongo connection in Groovy using gmongo
def credential = MC.createMongoCRCredential( "server", "db", "pass".toCharArray() )
def mongoClient = new MongoClient( new ServerAddress("ds033429.mongolab.com", 33429), [ credential ] )
def mongo = new GMongo( mongoClient )
def db = mongo.getDB("CloudFoundry_8sbeqjqe_6hqm0ehp")
map.each { key, value ->
db.riverlevelsgroovy << value
}
@spikeheap
spikeheap / Readme.md
Last active August 29, 2015 13:56
Geb context clicks

Geb context click example

A simple test demonstrating how to do a context click in Geb.

@spikeheap
spikeheap / Readme.md
Last active August 29, 2015 13:56
Demo of double-click event handling in Geb