Skip to content

Instantly share code, notes, and snippets.

@nicholashagen
nicholashagen / gist:1779211
Created February 9, 2012 10:45
Groovy Way to Convert List to Map
/**
* Convert any collection to a map by iterating over its contents
* and taking a result of the entry as the key to the map. The
* argument may either be a closure which is invoked once per item
* in the collection, or may be a string identifying the property
* to act as the key for each entry.
*/
Collection.metaClass.asMap = { arg ->
def result = [:]
delegate.each {
@nicholashagen
nicholashagen / gist:1770746
Created February 8, 2012 16:07
Trimming Spaces in Ant
<!-- task to trim spaces on properties in Ant via inline javascript (requires 1.7+) -->
<!-- NOTE that properties in Ant are immutable so you must define the variable with a different name -->
<target name="trim-properties">
<script language="javascript">
<![CDATA[
var myproperty= project.getProperty("myproperty");
if (myproperty!= null) {
project.setProperty("myproperty.trimmed", myproperty.trim())
}
]]>
@nicholashagen
nicholashagen / gist:1760526
Created February 7, 2012 16:23
Java Type Erasure Demonstration
// TEST 1: what happens in this scenario?
List<String> test1 = new ArrayList<String>();
test1.add(new Integer(5));
// TEST 2: what happens and/or is printed in this scenario?
List<String> test2 = new ArrayList<String>();
Method method2 =
test2.getClass().getMethod("add", String.class);
System.out.println(method2);
@nicholashagen
nicholashagen / gist:1677980
Created January 25, 2012 19:13
Maven Set Version Plugin
# run at top level project
mvn3 versions:set -DnewVersion=[x.y.z]
@nicholashagen
nicholashagen / gist:1673053
Created January 24, 2012 22:13
GitHub Updating a Fork
git remote add --track master mleung git://github.com/mleung/feather.git
git fetch mleung
git merge mleung/master
@nicholashagen
nicholashagen / gist:1635634
Created January 18, 2012 21:00
Glassfish Commands
# create a domain with portbase + 80 as the HTTP port
asadmin create-domain --portbase [port] [svc-name]
# create windows service wrapper for glassfish domain
asadmin create-service [svc-name]
@nicholashagen
nicholashagen / PhotoGallery
Created January 7, 2012 07:04
Photo Gallery Example
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<title>Gallery Example</title>
<style type="text/css">