Skip to content

Instantly share code, notes, and snippets.

@sbrady
sbrady / 1standard_fizzBuzz.go
Last active August 29, 2015 14:14
The evolution of a FizzBuzz in Golang
//Print the numbers 1..100
//For multiples of 3, print "Fizz" instead of the number
//For multiples of 5, print "Buzz" instead of the number
//For multiples of 3 and 5, print "FizzBuzz" instead of the number
package main
import "fmt"
import "strconv"
@sbrady
sbrady / decorator_pattern.groovy
Created January 15, 2015 05:57
Example decorator pattern in Groovy using @DeleGate
class Person {
String firstName
String lastName
}
class PersonDecorator {
private @Delegate Person person
def fullName() {
"$firstName $lastName"
}
@sbrady
sbrady / decorator_pattern.rb
Created January 15, 2015 05:03
Example decorator pattern in Ruby using simple delegate
class Person
attr_accessor :first_name, :last_name
def initialize(first_name, last_name)
self.first_name = first_name
self.last_name = last_name
end
end
require 'delegate'
class PersonDecorator < SimpleDelegator
@sbrady
sbrady / UrlMappings.groovy
Last active August 29, 2015 14:13
Give Grails more rails like RESTful routes
"/$controller"(parseRequest: true) {
action = [GET: "index", POST: "save"]
}
"/$controller/$id"(parseRequest: true) {
action = [GET: "show", PUT: "update", POST: "update", DELETE: "delete"]
constraints {
id matches: /\d+/
}