Skip to content

Instantly share code, notes, and snippets.

View dwelch2344's full-sized avatar

David Welch dwelch2344

View GitHub Profile
@dwelch2344
dwelch2344 / ComponentLoadProcessor.java
Created May 3, 2013 02:06
An example from Nathan Toone on avoiding @configuration scanning times (for AppEngine)
public class ComponentLoadProcessor{
@Override
public
void postProcessBeanDefinitionRegistry(final BeanDefinitionRegistry reg)
throws BeansException {
for (final String s : reg.getBeanDefinitionNames()) {
final BeanDefinition bd = reg.getBeanDefinition(s);
if (bd.getBeanClassName() != null &&
bd instanceof AnnotatedBeanDefinition) {
final AnnotatedBeanDefinition ab =
@dwelch2344
dwelch2344 / SimpleConfig.java
Last active December 16, 2015 03:49
Trying to get Spring Batch 2.2.0.RC1's JavaConfig working, but it appears @EnableBatchProcessing isn't providing the autowired beans
import javax.sql.DataSource;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobRepository;
@dwelch2344
dwelch2344 / pom.xml
Created April 7, 2013 06:25
Executable WAR example via Tomcat Maven Plugin
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<!-- Your stuff here... -->
<build>
<plugins>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
@dwelch2344
dwelch2344 / BadController.java
Created April 6, 2013 16:05
A simple demo of how to create a base Controller class that will turn all errors into JSON responses. Note that this expects you have Spring & Jackson configured to translate the object into an actual JSON response. See https://plus.google.com/108147394231281101268/posts/KEs945cvnEH
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class BadController extends BaseController{
@RequestMapping("/foobar")
public void foobar() throws Exception{
throw new Exception("I meant to fail!");
}
import java.io.File;
import java.io.FileNotFoundException;
import java.util.List;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.scope.context.ChunkContext;
@dwelch2344
dwelch2344 / mvn-local-repo.sh
Last active December 15, 2015 05:19
Maven local repository / hosting on GitHub stuff. Really need to document the rest...
# Deploy to release
mvn -DaltDeploymentRepository=snapshot-repo::default::file:/Users/$USER/dev/maven-repo/releases clean deploy
# Deploy to snapshot
mvn -DaltDeploymentRepository=snapshot-repo::default::file:/Users/$USER/dev/maven-repo/snapshots clean deploy
@dwelch2344
dwelch2344 / throttle.js
Created February 28, 2013 21:44
Throttling function, abstracted from Underscore
var throttle = function (func, wait) {
var context, args, timeout, result;
var previous = 0;
var later = function() {
previous = new Date();
timeout = null;
result = func.apply(context, args);
};
return function() {
var now = new Date();
@dwelch2344
dwelch2344 / install-composer-osx.sh
Created February 27, 2013 19:34
Install PHP Composer on OS X w/o errors
curl -s https://getcomposer.org/installer | php -d detect_unicode=Off
public enum ActionAuditType {
USER_LOGGED_IN("User Logged In"),
USER_LOGGED_OUT("User Logged Out");
private String mDescription;
private ActionAuditType(String aDescription) {
mDescription = aDescription;
}
@dwelch2344
dwelch2344 / fix-screen.scpt
Created February 19, 2013 20:43
Rotate Screen applescripts
tell application "System Preferences"
quit
delay 1
launch
activate
tell application "System Events"
key down {option, command}
end tell
reveal pane id "com.apple.preference.displays"