Skip to content

Instantly share code, notes, and snippets.

View agentgt's full-sized avatar

Adam Gent agentgt

View GitHub Profile
@agentgt
agentgt / gist:1081569
Created July 13, 2011 23:22
AspectJ filed ending in .java fails maven javadoc.
/var/lib/hudson/jobs/evocatus-web/workspace/src/main/java/com/evocatus/aop/DomainNotifyAdvice.java:22: class, interface, or enum expected
public void DomainNotify.postPersist() {
@agentgt
agentgt / AppendableAspect.aj
Created July 13, 2011 23:27
AspectJ to make appendable easier to use
package com.evocatus.aop;
import java.io.IOException;
import java.lang.Appendable;
public aspect AppendableAspect {
pointcut appendCall(): call(* Appendable.append(..));
declare soft : IOException : appendCall();
@agentgt
agentgt / gist:1081576
Created July 13, 2011 23:29
Maven snippet for google zxing
<repositories>
<repository>
<id>mvn-adamgent</id>
<url>http://mvn-adamgent.googlecode.com/svn/maven/release</url>
<name>Adam Gent Maven Repository</name>
</repository>
</repositories>
<dependencies>
<dependency>
@agentgt
agentgt / gist:1082008
Created July 14, 2011 05:55
Why I hate JSP
javax.el.ELException: Cannot convert [] of type class com.google.common.collect.Collections2$FilteredCollection to interface java.util.List
at org.apache.el.lang.ELSupport.coerceToType(ELSupport.java:434)
@agentgt
agentgt / SimpleContextListenerConfig.java
Created July 14, 2011 18:35
Simple way to do configuration for a web app.
package com.evocatus.util;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class SimpleContextListenerConfig /*extend ResourceBundle */ implements ServletContextListener{
private ServletContext servletContext;
@agentgt
agentgt / gist:1100030
Created July 22, 2011 18:15
Parse URI Query Parameters
public static Map<String, String> parseQueryParameters(String uri, String encoding) {
URI url = toURI(uri);
if (url == null) return null;
List<NameValuePair> nvps = URLEncodedUtils.parse(url, encoding);
LinkedHashMap<String, String> m = new LinkedHashMap<String, String>();
for (NameValuePair nvp : nvps) {
m.put(nvp.getName(), nvp.getValue());
}
return m;
}
@agentgt
agentgt / gist:1100035
Created July 22, 2011 18:19
Gracefully downgrading a UTF-8 String with weird characters to ASCII
public static String toAscii(String str) {
if (str == null) return null;
return Normalizer.normalize(str, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]","");
}
@agentgt
agentgt / attribute.tagx
Created July 26, 2011 12:33
Conditionally set attribute in JSPX element.
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<jsp:output omit-xml-declaration="yes"/>
<jsp:directive.attribute name="name" type="java.lang.String" required="true" rtexprvalue="true" description="Name"/>
<jsp:directive.attribute name="value" type="java.lang.String" required="true" rtexprvalue="true" description="Value"/>
<jsp:scriptlet>
//<![CDATA[
String name = (String) jspContext.getAttribute("name");
String value = (String) jspContext.getAttribute("value");
out.write(" " + name + "=" + "\"" + value + "\"");
<!--[if lt IE 8 ]>
<script src="//ajax.googleapis.com/ajax/libs/chrome-frame/1.0.3/CFInstall.min.js">/* */</script>
<script>window.attachEvent('onload',function(){CFInstall.check({mode:'overlay'})})</script>
<![endif]-->
@agentgt
agentgt / SpringAtmosphereServlet.java
Created September 12, 2011 18:09
Tomcat Spring Atomsphere Servlet
package com.snaphop.spring;
import java.lang.reflect.InvocationTargetException;
import javax.servlet.ServletConfig;
import org.atmosphere.cpr.AtmosphereServlet;
import org.atmosphere.cpr.Broadcaster;
import org.atmosphere.cpr.BroadcasterFactory;
import org.atmosphere.handler.ReflectorServletProcessor;