Skip to content

Instantly share code, notes, and snippets.

@danveloper
danveloper / gist:2782111
Created May 24, 2012
grails-maven-plugin issues
View gist:2782111
http://jira.grails.org/browse/MAVEN-86
- Fixed with commit 6e4e2ad, pull request 15
http://jira.grails.org/browse/MAVEN-118
- Can be closed? grails-webflow no longer exists as a dependency
http://jira.grails.org/browse/MAVEN-84
- Not an issue anymore? java.home is an exposed property from maven, and there are no more references to java.version
http://jira.grails.org/browse/MAVEN-68
@danveloper
danveloper / BigValueType.java
Created Aug 29, 2012
Huge enumeration problem w/ Spring-loaded
View BigValueType.java
// This class WILL be reloaded
enum BigValueType
{
enum0,
enum1,
enum2;
HugeEnum[] hugeEnums;
BigValueType() {
@danveloper
danveloper / html5-thumbnail-iframe.html
Created Sep 27, 2012
HTML5 Thumbnail Processing in IFRAME
View html5-thumbnail-iframe.html
<!DOCTYPE html>
<html>
<head>
<script>
window.onload = function() {
// Must be server-side images; non-origin images will result in a security exception
var images = ["img.jpg"];
for (var i=0;i<images.length;i++) {
thumbnailify(images[i]);
View MarkdownPageCompilerTask.groovy
package com.danveloper.ant.tasks
import grails.build.logging.GrailsConsole
import org.apache.tools.ant.BuildException
import org.apache.tools.ant.DirectoryScanner
import org.apache.tools.ant.taskdefs.MatchingTask
import org.apache.tools.ant.types.Path
import org.apache.tools.ant.types.Reference
import org.codehaus.groovy.control.CompilerConfiguration
import org.codehaus.groovy.grails.web.pages.GroovyPageCompiler
@danveloper
danveloper / gormish.properties
Created Nov 7, 2012
External Properties File
View gormish.properties
datasource.url=jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000
datasource.username=sa
datasource.pooled=true
datasource.driverClassName=org.h2.Driver
datasource.username=sa
datasource.password=
datasource.dbCreate=create-drop
datasource.url=jdbc:h2:mem:devDb;MVCC=TRUE;LOCK_TIMEOUT=10000
@danveloper
danveloper / urlshortener.groovy
Created Nov 8, 2012
The 48-Line Volatile URL Shortener
View urlshortener.groovy
import java.net.ServerSocket
def socket = 8281, password = "danrulz"
enum Database {
INSTANCE;
def table = [:]
def shortCodeTable = [:]
def insert = { String url ->
Sequence.INSTANCE.counter++
def id = Sequence.INSTANCE.counter
def shortCode = new BigInteger(id).toString(36)+BigInteger.valueOf(Math.round(Math.random()*1000)).toString(36)
@danveloper
danveloper / Providers.groovy
Created Dec 11, 2012
This is how I implement the Provider pattern in Groovy.
View Providers.groovy
package com.danveloper.providers
import com.danveloper.support.ApplicationHolder as AH
import org.hibernate.SessionFactory as SF
public interface Provider<T> {
T get()
}
class Support {
@danveloper
danveloper / build.gradle
Created Dec 13, 2012
Compel gradle to never cache -SNAPSHOT dependencies.
View build.gradle
configurations.all {
resolutionStrategy.cacheChangingModulesFor 0, 'seconds'
}
@danveloper
danveloper / dynamicmethods.groovy
Created Dec 20, 2012
Dynamic Method Parameters in Groovy
View dynamicmethods.groovy
def bar(name) {
"bar: $name"
}
def foo(k, name = bar(k)) {
"$name"
}
assert foo("ha") == "bar: ha"
@danveloper
danveloper / EnrollmentRulesEngine.groovy
Created Dec 23, 2012
Example enrollment rules engine
View EnrollmentRulesEngine.groovy
class EnrollmentRulesEngine extends RulesEngineSupport<Student> implements RulesEngine {
def dormHallRule = { obj ->
if (obj.gpa >= 3.5) {
obj.@dormHall = Student.DormHall.Honors
} else if (obj.gpa >= 3.0) {
obj.@dormHall = Student.DormHall.Preferred
} else {
obj.@dormHall = Student.DormHall.Normal
}
}