Skip to content

Instantly share code, notes, and snippets.

View agentgt's full-sized avatar

Adam Gent agentgt

View GitHub Profile
@agentgt
agentgt / XmlStreamObjectUtils.java
Created September 19, 2012 20:54
Turn XML Stream into an Object Iterator
package com.snaphop.util;
import static com.google.common.base.Preconditions.checkState;
import java.io.Reader;
import java.util.Iterator;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
@agentgt
agentgt / JSR305Test.java
Created September 9, 2012 18:07
Aspect for validating JSR 305 annoations during runtime.
package com.snaphop.aop;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class JSR305Test {
@agentgt
agentgt / URIExtractor.java
Created September 8, 2012 12:25
URIExtractor extracts URI and URL from a stream.
package com.snaphop.util;
import static com.google.common.collect.Iterators.transform;
import java.io.IOException;
import java.io.Reader;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Iterator;
import java.util.List;
@agentgt
agentgt / SpringExceptionTranslationExecuteListener.java
Created September 7, 2012 20:23
JOOQ Spring Transaction support.
package com.snaphop.jooq;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import javax.sql.DataSource;
import org.jooq.ExecuteContext;
import org.jooq.impl.DefaultExecuteListener;
@agentgt
agentgt / AbstractSqlBuilder.java
Created September 6, 2012 02:38
MyBatis SqlBuilder done right!
/*
* Copyright 2009-2012 The MyBatis Team
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@agentgt
agentgt / gist:3406599
Created August 20, 2012 18:45
/etc/bash_completion.d/mercurial
# bash completion for the Mercurial distributed SCM
# Docs:
#
# If you source this file from your .bashrc, bash should be able to
# complete a command line that uses hg with all the available commands
# and options and sometimes even arguments.
#
# Mercurial allows you to define additional commands through extensions.
# Bash should be able to automatically figure out the name of these new
@agentgt
agentgt / AppendableDecorator.java
Created July 12, 2012 22:22
An appendable decorator that will soften the IOException, handle nulls, and do collection joins.
package com.snaphop.util;
import javax.annotation.Nullable;
public class AppendableDecorator {
protected final CharSequence nullText;
protected final CharSequence newLine;
protected final boolean skipNull;
@agentgt
agentgt / HttpClientURIUtil.java
Created June 28, 2012 12:25
Commons Httpclient Encoding tools that are missing from Commons Http Components
package com.snaphop.util;
/*
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//httpclient/src/java/org/apache/commons/httpclient/util/URIUtil.java,v 1.27 2004/05/05 20:34:01 olegk Exp $
* $Revision: 507321 $
* $Date: 2007-02-14 01:10:51 +0100 (Wed, 14 Feb 2007) $
*
* ====================================================================
*
@agentgt
agentgt / gist:2872813
Created June 5, 2012 05:20
Nginx configuration for Maven Repository
server {
listen 30080;
root /home/maven/public;
index index.html index.htm;
server_name my.host.name;
access_log /var/log/nginx/localhost.access.log;
location / {
@agentgt
agentgt / select2insert.py
Created May 1, 2012 13:50
Turns Postgresql SELECT statements into INSERT statements
#!/usr/bin/env python
## Turns a SELECT sql statement into INSERT statements
## for copying into another database server with the same table.
## The SELECT statement should select all the columns.
## pgAdmin III will create a SELECT statement with all the columns by
## right clicking on a table and selecting 'Scripts->SELECT'
## The statement should come from STDIN. So you can dom something like $ cat some.sql | select2insert.py
## http://stackoverflow.com/questions/1820650/sql-script-to-create-insert-script/10392124#10392124
import fileinput
import re