Skip to content

Instantly share code, notes, and snippets.

View robfletcher's full-sized avatar

Rob Fletcher robfletcher

View GitHub Profile
@robfletcher
robfletcher / gist:5598073
Created May 17, 2013 09:43
Validate HTML files from the terminal with curl
curl http://validator.w3.org/check -i -F output=json -F uploaded_file=@<path-to-html-file>
@robfletcher
robfletcher / _safe-rgba.scss
Created May 17, 2013 08:45
SASS mixin that uses modernizr to output fallback color property for browsers that don't support RGBA.
/*
* Outputs a color property with an opaque fallback for browsers that do not support RGBA.
*/
@mixin safe-rgba($property, $color, $fallback-color: opacify($color, 1)) {
@if opacity($color) == 1 {
#{$property}: $color;
} @else {
#{$property}: $fallback-color;
.rgba & {
#{$property}: $color;
package spock.extensions.state
class StateMachine<E extends Enum> {
private final String name
private E currentState
StateMachine(String name, E initialState) {
this.name = name
currentState = initialState
@robfletcher
robfletcher / YamlEncodingSpec.groovy
Created August 31, 2012 12:03
Demonstrates problem with reading back yaml containing corrupted UTF-8 characters
package yaml.encoding
import org.yaml.snakeyaml.Yaml
import spock.lang.*
@Unroll
class YamlEncodingSpec extends Specification {
Yaml yaml = new Yaml()
File file
UserRole.withCriteria {
createAlias 'user', 'u'
projections {
property 'u.username'
}
eq 'role', role
}
@robfletcher
robfletcher / _Events.groovy
Created June 20, 2012 16:39
Automatically display last deployment time in your Cloud Foundry app
eventCfUpdateStart = {
metadata.'cf.last.deployed' = new Date().format("yyyy-MM-dd'T'HH:mm:ssZ")
metadata.persist()
}
@robfletcher
robfletcher / build.gradle
Created May 16, 2012 08:12
Template Gradle build for projects using Groovy with embedded vert.x
apply plugin: 'groovy'
repositories {
mavenCentral()
// vertxHome must be defined in gradle.properties
flatDir { dirs "${vertxHome}/lib/jars" }
}
dependencies {
groovy 'org.codehaus.groovy:groovy:1.8.6'
@robfletcher
robfletcher / VertxHandler.groovy
Created May 10, 2012 00:16
A Spock extension for automatically registering and unregistering handlers on the Vert.x event bus
package co.freeside.spock.vertx
import org.spockframework.runtime.extension.ExtensionAnnotation
import java.lang.annotation.*
/**
* Add this annotation to any specification fields that should be registered as Vert.x event bus handlers during test
* execution. The field will be registered on the event bus before each feature method and unregistered afterwards. If
* the field is `@Shared` it will be registered and unregistered at the start and end of the spec.
*
@robfletcher
robfletcher / gist:1486156
Created December 16, 2011 14:06
Geb module methods demonstrating how to wait for jQuery animation to complete
void next() {
nextButton.click()
waitForAnimationComplete()
}
private void waitForAnimationComplete() {
waitFor {
js.exec(this.firstElement(), "return \$(arguments[0]).find(':animated').length == 0")
}
}
@robfletcher
robfletcher / DatabaseSchemaSpec.groovy
Created August 18, 2011 16:27
Example of data-driving a Spock specification using database metadata
import grails.plugin.spock.IntegrationSpec
import java.sql.Connection
import javax.sql.DataSource
import spock.lang.*
class DatabaseSchemaSpec extends IntegrationSpec {
@Shared def dataSource
@Shared List<String> tableNames