Skip to content

Instantly share code, notes, and snippets.

@ishults
ishults / pi_setup.txt
Last active April 9, 2016 20:48
Basic Pi configuration
# Update Locale/Timezone
Menu -> Preferences -> Raspberry Pi Configuration -> Localisation -> Set Locale... or Set Timezone...
# Change Keyboard Layout
Menu -> Preferences -> Keyboard and Mouse -> Keyboard -> Keyboard Layout
# Change password
Menu -> Preferences -> Raspberry Pi Configuration -> System -> Change Password...
# Access the outside world!
@ishults
ishults / UriFiltersSpec.groovy
Created February 21, 2016 18:05
The working filter unit tests
@Mock(UriFilters)
@TestFor(MyController)// Need a controller to test filters
class UriFiltersSpec extends Specification {
void "myFilter() should set the names of the controller and action"() {
setup:
request.requestURI = '/some/path/here'
when:
withFilters(controller: 'my', action: 'index') { controller.index() }
@ishults
ishults / requestURI.groovy
Created February 21, 2016 18:02
The first step to make our filter work
request.requestURI = '/some/path/here'
@ishults
ishults / UriFiltersSpec.groovy
Created February 21, 2016 17:57
The broken unit tests for our filter
@Mock(UriFilters)
@TestFor(MyController)// Need a controller to test filters
class UriFiltersSpec extends Specification {
void "myFilter() should set the names of the controller and action"() {
when:
withFilters(uri: '/some/path/**') { controller.index() }
then:
response.getHeader('controllerName') == 'my'
@ishults
ishults / UriFilters.groovy
Created February 21, 2016 17:55
A basic URI-based Grails filter
package controller
class UriFilters {
def filters = {
myFilter(uri: '/some/path/**') {
before = {
response.setHeader('controllerName', controllerName)
response.setHeader('actionName', actionName)
// Do something
@ishults
ishults / MyController.groovy
Created February 21, 2016 17:54
A dummy controller
class MyController {
def index() {
render 'success'
}
}
environments {
test {
dataSource {
pooled = true
username = "yourUser"
password = "yourPass"
dbCreate = "create"
url = "jdbc:postgresql://localhost:5432/test_db${System.properties.getProperty('test.suffix') ?: ''}"
jndiName = null
}
@ishults
ishults / jenkins_drop.sh
Last active December 16, 2015 20:02
Sample Jenkins script to drop a database
# Exports
export PSQL_HOME=/Library/PostgreSQL/9.3
export PATH=/Library/PostgreSQL/9.3/bin:$PATH
export PGPASSWORD=yourPass # Ideally this should live in the .pgpass file
# Drop the database
dropdb test_db${BUILD_NUMBER} --username=yourUser --if-exists
@ishults
ishults / jenkins_create.sh
Last active December 16, 2015 20:02
Sample Jenkins script to dynamically create a database and then pass it to Grails
# Exports
export GRAILS_HOME=/path/to/grails
export PATH=$PATH:${GRAILS_HOME}/bin
export PSQL_HOME=/Library/PostgreSQL/9.3
export PATH=$PATH:${PSQL_HOME}/bin
export PGPASSWORD=yourPass # Ideally this should live in the .pgpass file
# Create the database
@ishults
ishults / anotherParam.groovy
Last active December 16, 2015 20:02
Adding a second parameter, even an optional one, means the no-arg method call will fail
void doSomething(def foo, def newParam = null) {
println foo
}
void doSomethingAgain(def baz, def newParam) {
println baz
}
doSomething() // Throws MethodSelectionException
doSomethingAgain('Test') // Throws MissingMethodException