Clearing floats the right way
This page here shows how to how to clear floats the RIGHT way when you’re using a containing div around your floating elements. Using overflow : auto lets the containing div grow to the appropriate height. And it doesn’t require a trailing div upon which to apply the clear : both style. Using structural HTML to perform styling? Ugh.
JUnit 4.4 includes Hamcrest core matchers?
Interesting read on what’s new in JUnit 4.4.
Wiring EHCache into your app with Spring
Here’s a great straight forward tutorial on how to use Spring to wire EHCache into your Java web application.
Java Interview Questions
Some darned good (and not so easy) Java interview questions.
The one where I try to learn OAuth…
As I try to learn OAuth and how to add it to my site, this article really helped get the basic understanding.
Enabling ssh on Mac OSX
The Apple Mac OS X operating system has SSH installed by default but the SSH daemon is not enabled. This means you can’t login remotely or do remote copies until you enable it.
To enable it, go to ‘System Preferences’. Under ‘Internet & Networking’ there is a ‘Sharing’ icon. Run that. In the list that appears, check the ‘Remote Login’ option.
This starts the SSH daemon immediately and you can remotely login using your username. The ‘Sharing’ window shows at the bottom the name and IP address to use. You can also find this out using ‘whoami’ and ‘ifconfig’ from the Terminal application.
Blocking Meebo, the most annoying news site ad nonsense
Here’s how to block Meebo using Adblock. Worked for my Chrome install.
http://www.chizang.net/alex/blog/2010/08/19/block-meebo-bar/
Excellent webinar on Continuous Integration by Thoughtworks
Here’s an excellent webinar on Continuous Integration by Thoughtworks.
Using Hibernate’s ability to create a user defined type to fix clunky Oracle CLOB code
Very helpful post over here explained how to use Hibernate’s UserType to create a custom type to override the behavior of Oracle’s CLOB types.
Because no programmer can leave well enough alone, I tweaked his code, and made the Unicode related fix suggested in the comments there. Here’s the code I’m using, and it works brilliantly on Java + Hibernate + Oracle 11:
package net.bigmarv.hibernate.types; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.Reader; import java.io.Serializable; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; import org.hibernate.HibernateException; import org.hibernate.usertype.UserType; /** * Way of mapping an Oracle CLOB field as user defined type * in Hibernate. Makes it easier to read these fields. * Borrowed from this * Blog Entry */ public class ClobType implements UserType { @Override public int [] sqlTypes() { return new int [] { Types.CLOB }; } /** * Returns the class that this Clob is converted to. */ @SuppressWarnings( "rawtypes" ) @Override public Class returnedClass() { return String.class; } @Override public boolean equals( Object left, Object right ) throws HibernateException { if ( left == null || right == null ) { return false; } if ( !(left instanceof String) || !(right instanceof String) ) { return false; } return ( ( String )left ).equals( right ); } @Override public int hashCode( Object o ) throws HibernateException { return o.hashCode(); } @Override public Object nullSafeGet( ResultSet resultSet, String [] names, Object owner ) throws HibernateException, SQLException { StringBuilder sb = new StringBuilder(); try { // First we get the stream //InputStream is = resultSet.getAsciiStream( names[0] ); // Should be getCharacterStream for unicode Reader reader = resultSet.getCharacterStream( names[ 0 ] ); char [] buf = new char[ 4096 ]; int read = -1; while ( reader != null && ( read = reader.read(buf)) >= 0) { sb.append( buf, 0, read ); } if ( reader != null ) { reader.close(); } return sb.toString(); } catch ( IOException ioException ) { throw new HibernateException( "Unable to read from resultset", ioException ); } } @Override public void nullSafeSet( PreparedStatement pst, Object data, int index ) throws HibernateException, SQLException { data = data == null ? new String() : data; String in = (String) data; byte[] buf = in.getBytes(); int len = buf.length; ByteArrayInputStream bais = new ByteArrayInputStream(buf); pst.setAsciiStream(index, bais, len); } @Override public Object deepCopy( Object object ) throws HibernateException { if ( object == null ) { object = new String(); } String in = ( String )object; int len = in.length(); char [] buf = new char[ len ]; for ( int i = 0; i < len; i++ ) { buf[ i ] = in.charAt( i ); } return new String( buf ); } @Override public boolean isMutable() { return false; } @Override public Serializable disassemble( Object arg0 ) throws HibernateException { return ( String )arg0; } @Override public Object assemble( Serializable arg0, Object arg1 ) throws HibernateException { return this.deepCopy( arg0 ); } @Override public Object replace( Object arg0, Object arg1, Object arg2 ) throws HibernateException { return this.deepCopy( arg0 ); } }
Once you've created this class and put it in an appropriate package, you'll need to update your .hbm.xml files to use the new type. In my case, I had columns defined as
<property name="foo" column="foo" type="clob" />
I changed this to
<property name="foo" column="foo" type="net.bigmarv.hibernate.types.ClobType" />
I then ran
mvn hibernate:hbm2java
and then recompiled, and I was done. Beautiful stuff!