Skip to content

Instantly share code, notes, and snippets.

View cdeszaq's full-sized avatar
💭
Doing a little wiring...

Rick Jensen cdeszaq

💭
Doing a little wiring...
View GitHub Profile
package com.github.robfletcher.grails.validation
import org.codehaus.groovy.grails.validation.AbstractConstraint
import org.springframework.validation.Errors
class AcyclicConstraint extends AbstractConstraint {
static final String DEFAULT_MESSAGE_CODE = "default.acyclic.violation.message"
static final String NAME = "acyclic"
@cdeszaq
cdeszaq / injectCountExample.groovy
Created May 16, 2012 15:27
Using inject with a map to count occurrences of strings
import groovy.json.JsonOutput
// File is just a list of words, one per line.
def counts = new File("types.txt").readLines().inject([:]) {Map obj, String val ->
// If we hit an empty line, do nothing and just return the map as-is
if (val) {
if (!obj[val]) {
// The key didn't exist, so put it into the map
obj[val] = 1
} else {
@cdeszaq
cdeszaq / MyDomain.groovy
Created December 27, 2012 14:50
Example of how to DRY up complex Grails validation logic and share it across different domain objects.
class MyDomain {
...
static constraints = {
items(validator: requiresAtleastOne)
}
}
@cdeszaq
cdeszaq / RequestPeerEvaluationController.groovy
Created February 7, 2013 19:40
Example of how to have multiple child elements created from a single view. Of note, the `RequestedPeersCommand` object is the part that lets n People be selected to request peer evaluations from.
package edu.wisc.radiology.performanceevaluations
import grails.converters.JSON
import grails.converters.XML
import grails.plugins.springsecurity.Secured
import grails.validation.Validateable
@Secured("hasRole('ROLE_USER')")
class RequestPeerEvaluationController {
@cdeszaq
cdeszaq / gist:5222593
Created March 22, 2013 16:15
Plugins and Dependencies from BuildConfig.groovy
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
// Allows connecting to MySQL DBs
runtime 'mysql:mysql-connector-java:5.1.22'
// For JodaTime plugin
compile "org.jadira.usertype:usertype.jodatime:1.9.1"
// So that spock can work with Grails 2.2

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
var empty_list = function(selector) {
return selector(undefined, undefined, true);
};
var prepend = function(el, list) {
return function(selector) {
return selector(el, list, false);
};
};
var head = function(list) {
@cdeszaq
cdeszaq / Problem.md
Last active December 19, 2015 01:59

TODO: Fill in the problem statement

// isPalindrome - ignore cases, spaces and punctuation
// Empty string is false
// O(1) space, cant modify original string
[1,2,3,4,5,6].each {
println "Running isPalindrome${it}"
assert !"isPalindrome${it}"("") // False
assert !"isPalindrome${it}"(" !,! ") // False
assert "isPalindrome${it}"("M") // True
assert "isPalindrome${it}"("M.") // True
// isPalindrome - ignore cases, spaces and punctuation
// Empty string is false
// O(1) space, cant modify original string
[1,2,3,4,5,6].each {
println "Running isPalindrome${it}"
assert !"isPalindrome${it}"("") // False
assert !"isPalindrome${it}"(" !,! ") // False
assert "isPalindrome${it}"("M") // True
assert "isPalindrome${it}"("MM..M") // True