Skip to content

Instantly share code, notes, and snippets.

View dwelch2344's full-sized avatar

David Welch dwelch2344

View GitHub Profile
package in.javadigest.encryption;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.security.KeyPair;
public class Foobar{
public static void doSomething(){
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter String");
String s = br.readLine();
System.out.print("Enter Integer:");
try{
int i = Integer.parseInt(br.readLine());
}catch(NumberFormatException nfe){
@dwelch2344
dwelch2344 / IOUtils.java
Created September 25, 2013 19:37
a standalone class for doing byte copying...
public class IOUtils
public ByteArrayOutputStream readBytes(InputStream is) throws IOException{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[1024 * 16];
while ((nRead = is.read(data, 0, data.length)) != -1) {
baos.write(data, 0, nRead);
}
@dwelch2344
dwelch2344 / DispatcherServlet.java
Last active December 23, 2015 22:19
A simple standalone dispatcher servlet, for working in disappointing environments
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
@dwelch2344
dwelch2344 / Broken_Model.java
Last active December 21, 2015 18:38
Strange error bubbled up from upgrading SpringData MongoDB
public class Participant implements Serializable{
// ...
private Date date;
}
@dwelch2344
dwelch2344 / RestConfig.java
Created July 17, 2013 16:13
Originally I just added a @configuration file for SprintData-Rest and got my entities working in my existing SpringMVC app, but then I realized it was stomping on the web portion of my app (mapped to / ) So I've reworked the initializer to add a separate DispatcherServlet. I added the code around line 39 to try and add SpringData-Rest with a pre…
import org.springframework.context.annotation.Configuration;
import org.springframework.data.rest.webmvc.RepositoryRestMvcConfiguration;
// @Configuration
public class RestConfig extends RepositoryRestMvcConfiguration {
public RestConfig() {
System.out.println("Rest Config");
}
@dwelch2344
dwelch2344 / InheritableAbstractRefreshableWebApplicationContext.java
Created July 17, 2013 02:12
Some inheritable Spring containers for experimenting
import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractRefreshableConfigApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.ui.context.Theme;
@dwelch2344
dwelch2344 / hibernate.hbm2ddl.properties
Last active December 19, 2015 17:59
An example of how to have Maven and Hibernate 4 generate your DDL for you... See http://mydevnotes.nicus.it/2013/03/generate-ddl-with-maven-jpa-hibernate-4.html
# stashed in src/main/resources
hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
hibernate.ejb.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
hibernate.connection.charSet=UTF-8
hibernate.export.schema.delimiter=;
@dwelch2344
dwelch2344 / spring-xd-demo.sh
Created July 11, 2013 19:23
Spring XD demo script
./redis/bin/redis-server
# new tab
./xd/bin/xd-singlenode
# another window
# To view redis info: ./redis/bin/redis-cli
@dwelch2344
dwelch2344 / ApiDocExample.java
Created May 14, 2013 14:30
Quick little POC for self-documenting the controller layer in a SpringMVC app
public class ApiDocExample{
@Inject
private RequestMappingHandlerMapping mapping;
public void foobar(){
Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
for( RequestMappingInfo info : map.keySet() ){
HandlerMethod method = map.get(info);
ApiOperation annotation = method.getMethodAnnotation(ApiOperation.class);