Skip to content

Instantly share code, notes, and snippets.

View twasink's full-sized avatar

Robert Watkins twasink

View GitHub Profile
@twasink
twasink / SpringMappingFilter.java
Created November 2, 2011 10:03
Example Filter that binds spring-managed beans into the request
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.springframework.context.ApplicationContext;
@twasink
twasink / gist:1349979
Created November 9, 2011 01:10
Creating a qualified bean using Grails Spring DSL
In order to match a @Qualifier reference like this (in a Spring-managed bean):
public class MyManagedBean {
@Autowired @Qualifier("bean_a") private MyBean myBean;
}
using the Grails Spring DSL, you do this:
myBean(MyBean) { bean ->
bean.beanDefinition.addQualifier(new org.springframework.beans.factory.support.AutowireCandidateQualifier( org.springframework.beans.factory.annotation.Qualifier, 'bean_a'))
@twasink
twasink / gist:1997799
Created March 8, 2012 01:20
Colourised git-aware PS1 that also knows what repo you're in.
__git_repo () {
local g="$(__gitdir)"
local repo_dir=""
if [ -n "$g" ]; then
if [ ! ".git" == "$g" ]; then
git_dir=`dirname $g`
repo_dir=`basename $git_dir`
printf " $repo_dir"
fi
@twasink
twasink / Description
Created June 6, 2012 11:55
Spring, Hibernate, HSQLDB and automatically creating tables
An example of using Spring and Hibernate together to automatically create a HSQLDB in-memory database for testing hibernate mappings.
@twasink
twasink / Description
Created June 6, 2012 12:24
Spring, JPA, HSQLDB and automatically creating tables
Same as the earlier gist, but with JPA wrapping hibernate. Note that the choice of wether to create the tables or not is in the spring-config file, NOT the persistence.xml file like a lot of other examples out there.
@twasink
twasink / delete_all_data.sql
Created June 13, 2012 10:32
Query to delete all data from default HSQL database schema
-- PUBLIC is the default name of a HSQL database
truncate schema PUBLIC and commit
@twasink
twasink / EmailTester.java
Created July 9, 2012 01:21
Sending email (Java, Spring)
package net.twasink.email;
import java.io.IOException;
import javax.activation.DataSource;
import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
import javax.mail.util.ByteArrayDataSource;
import org.junit.Test;
import org.springframework.mail.SimpleMailMessage;
tmp $ mkdir nomasters
tmp $ cd nomasters/
nomasters $ git init --bare
Initialized empty Git repository in /Users/robertdw/tmp/nomasters/
nomasters [BARE:master]$ git log master
fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions
nomasters [master]$ git remote add -t a_branch origin https://github.com/twasink/jbehave-spike
nomasters [master]$ git fetch
remote: Counting objects: 313, done.
@twasink
twasink / NumberFunkyTest.java
Created September 26, 2012 13:56
Funky number parsing surprises in Commons-Lang NumberUtils (used by json-lib)
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
import org.apache.commons.lang.math.NumberUtils;
import org.junit.Test;
public class NumberFunkyTest {
@Test public void testingSomeOddParsingBehaviourFoundEarlier() {
@twasink
twasink / ControllerTestSpikeSpec.js
Created November 14, 2012 03:01
An example of testing an ExtJS controller and View together. (Not shown - the creation of the ExtJs application itself, or the Jasmine setup)
Ext.define('App.controller.SpikeController', {
extend: 'Ext.app.Controller',
refs: [
{ ref: 'foobar', selector: '#foobar' },
{ ref: 'bazbux', selector: '#bazbux' },
{ ref: 'spikeView', selector: 'spike_view' }
],
init: function() {