Skip to content

Instantly share code, notes, and snippets.

View jamesmorgan's full-sized avatar

James Morgan jamesmorgan

View GitHub Profile
@jamesmorgan
jamesmorgan / sample_logging_annotation_example.java
Created August 4, 2011 12:23
Deomstration using the Loggin annotation
package com.morgan.design.demo;
import org.springframework.stereotype.Component;
import com.morgan.design.demo.annotation.LogMe;
import com.morgan.design.demo.annotation.LoggingLevel;
@Component
public class LoggingExample {
@jamesmorgan
jamesmorgan / logging_aspect_example.java
Created August 4, 2011 12:38
Sample Logging Aspect
@Aspect
public class LoggingAspect {
private ILoggerFactory iLoggerFactory = LoggerFactory.getILoggerFactory();
@Before("execution(@com.morgan.design.demo.annotation.LogMe(com.morgan.design.demo.annotation.LoggingLevel.WARN) * *(..))")
public void loggerWarn(final JoinPoint jp) throws Throwable {
final Logger logger = getLoggerForClass(jp);
logger.warn(buildLogging(jp));
}
@jamesmorgan
jamesmorgan / itext_qrcode_snippet.java
Created September 14, 2011 07:35
Sample iText QRCode creation snippet
PushbuttonField barcodeButton = acroFields.getNewPushbuttonFromField("barcode_button");
if(barcodeButton){
// These settings are optional, null can be passed in as the four argument to BarcodeQRCode
Map<EncodeHintType, Object> hints = Maps.newHashMap();
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
hints.put(EncodeHintType.CHARACTER_SET, "ISO-8859-1");
BarcodeQRCode qrcode = new BarcodeQRCode("SomeBarcodeData_123456789", 0, 0, hints);
barcodeButton.setLayout(PushbuttonField.LAYOUT_ICON_ONLY);
@jamesmorgan
jamesmorgan / ObjectArrayMatcher.java
Created September 20, 2011 19:51
Simple List Object Array Matcher with usage
/**
* An expected call to my matcher
*/
this.context.checking(new Expectations() {
{
one(someMockedService).save(with(args), with(def), with(thisObjectArray(batch)));
}
});
this.seviceUnderTest.source(args);
@jamesmorgan
jamesmorgan / CopyFromOneServerToAnother.groovy
Created October 15, 2011 07:23
Copy Messages from one ActiveMQ instance to another with Apache Camel and Groovy
import org.apache.activemq.camel.component.ActiveMQComponent
import org.apache.camel.CamelContext
import org.apache.camel.builder.RouteBuilder
import org.apache.camel.impl.DefaultCamelContext
class CopyFromOneServerToAnother extends RouteBuilder{
public static void main(String[] args) {
@jamesmorgan
jamesmorgan / InitialSqlBuilkder.java
Created November 2, 2011 08:33
Initial implementation of a SQL creation builder used for generating SQL migration queries.
String rawSql = new AlterTableBuild()
.alterTable(Person.class)
.addColumn(Person.FOO_ID)
.after(Person.NAME)
.migrate()
.from("old_column")
.to(Person.FOO_ID)
.build();
this.db.executeRaw(rawSql);
@jamesmorgan
jamesmorgan / ExampleAndroidOnUpgradeStrategy.java
Created November 7, 2011 19:44
ExampleOfORMLIteCustomDatabaseUpgradeStrategy
/**
* This is called when your application is upgraded and it has a higher version number. This allows you to adjust the various data to
* match the new version number.
*/
@Override
public void onUpgrade(final SQLiteDatabase db, final ConnectionSource connectionSource, int oldVersion, final int newVersion) {
Logger.i(LOG_TAG, "onUpgrade, oldVersion=[%s], newVersion=[%s]", oldVersion, newVersion);
try {
// Simply loop round until newest version has been reached and add the appropriate migration
while (++oldVersion <= newVersion) {
@jamesmorgan
jamesmorgan / UpgradeHelper.java
Created November 10, 2011 08:25
Utility class for loading migration files in Android assets directory
/**
* Used as a aid in the migration process for, loading required SQL files as specified by a given version
*
* @author James Edward Morgan
*/
public class UpgradeHelper {
private static final String LOG_TAG = "UpgradeHelper";
protected static final Set<Integer> VERSION;
@jamesmorgan
jamesmorgan / TODO.java
Created January 8, 2012 15:05
TODO.java - My version of a roadmap...
package com.morgan.design;
public class TODO {
private TODO() {
}
//@formatter:off
// ////////////////////////
// Build / Configuration //
@jamesmorgan
jamesmorgan / DynamicAssetsLoader.as
Created February 9, 2012 19:34
Loads a given image asset in ActionScript, setting the source on the given image
public class DynamicAssetsLoader {
public static function loadImage(image:Image, assetUri:String):void
{
// if not
if(!assetUri){
image.includeInLayout = false;
image.visible = false;
image.source = null;
return;