Skip to content

Instantly share code, notes, and snippets.

@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">
@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 / 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: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: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: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: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:1989663
Created March 6, 2012 23:09
Groovy Closure to Callable
// anonymously invoke a closure into callable and submit to executor
// this fails w/o the explicit (Callable) since it converts it to Runnable
def executor = java.util.concurrent.Executors.newFixedThreadPool(5)
def future = executor.submit((java.util.concurrent.Callable) {
'TEST'
})
assert('TEST' == future.get())
@nicholashagen
nicholashagen / gist:1993769
Created March 7, 2012 15:22
Git Commands
# control color output via ASCII codes for better visual aspsect in terminal
git config --global color.ui auto
# update line-ending support for win/unix cross-platform (cr/cflf)
# force to be LF in the repo (regardless of OS)
git config --global core.autocrlf input
# force windows t oconvert to platform on checkout and back on commit
git config --global core.autocflf true
# individually control portions of a file (patch mode)
@nicholashagen
nicholashagen / gist:2039581
Created March 14, 2012 21:16
Accessing Temporary Directory in Servlet Container
File tmpDir = (File) servletContext.getAttribute(SERVLET_TMP_DIR);
if (tmpDir == null) {
throw new ServletException("Servlet container does not provide temporary directory");
}
File workDir = new File(tmpDir, "classes");
if (!workDir.mkdirs()) {
throw new ServletException("Unable to create classes temporary directory");
}