Skip to content

Instantly share code, notes, and snippets.

@mrg
mrg / AESPasswordEncoder.java
Created February 23, 2015 17:59
AES Password Encoder for Cayenne Models
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import org.apache.cayenne.conf.PasswordEncoding;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
/**
* @author mrg
@mrg
mrg / CayenneUtils.java
Last active May 10, 2017 14:15
A collection of Cayenne utilities
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.cayenne.CayenneDataObject;
import org.apache.cayenne.DataObjectUtils;
import org.apache.cayenne.DataRow;
import org.apache.cayenne.ObjectContext;
@mrg
mrg / TestBase.java
Last active August 29, 2015 14:03
Superclass for Cayenne/Tapestry unit testing using JNDI connections and allowing Cayenne to create the test database from the Cayenne Model. Designed for Cayenne 3.0 and Tapestry 5. See POM for additional dependencies.
import java.io.File;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import your.test.TestModule;
import org.apache.cayenne.ObjectContext;
import org.apache.cayenne.access.DataContext;
@mrg
mrg / BootstrapUpload
Last active May 4, 2016 10:39
Tapestry 5(.4) component to re-style a standard HTML upload to be more 21st century.
This Tapestry 5.4 component allows you to use a standard HTML upload
input (<input type="file" ... /> -- as produced Tapestry's upload
component), but with a more modern-looking Bootstrap styling.
Screenshot:
https://raw.githubusercontent.com/mrg/mrg-sandbox/master/screenshots/BootstrapUpload.png
This component only includes the upload facility and the parent must
provide the HTML FORM to handle the upload. Currently does not support
@mrg
mrg / IEWarning
Last active August 29, 2015 14:01
Tapestry 5(.4) component to warn users if they are using an old version of IE which probably will not work well.
A simple Tapestry 5.4 + Bootstrap Alert component to warn users they
shouldn't be using older versions of IE.
Note: This requires the UserAgent service:
https://gist.github.com/mrg/b814a42d86597440c9d9
To use, simply include it in your page TML somewhere, perhaps in your
Layout component for best results:
<t:ieWarning/>
@mrg
mrg / UserAgent
Last active August 29, 2015 14:01
Tapestry 5 service to determine User Agent of common browsers. Can easily be expanded upon to include mobile browsers, etc.
This is a Tapestry 5 service to query a browser's User Agent.
Inject it into your page when you need to do browser-specific
customizations. Make it a property and you can query via TML.
Add to AppModule.java to make the service available:
public static void bind(ServiceBinder binder)
{
...
@mrg
mrg / FormPreProcessorFilter
Last active August 29, 2015 13:56
Tapestry 5 service/filter to automatically trim all form inputs of leading/trailing whitespace and replace smart quotes with normal quotes.
In your AppModule:
public static void bind(ServiceBinder binder)
{
...
binder.bind(FormPreProcessorFilter.class, FormPreProcessorFilterImplementation.class);
...
}
/**