Skip to content

Instantly share code, notes, and snippets.

View max747's full-sized avatar

max747 max747

  • Xross Soft, LLC.
  • Osaka, Japan
View GitHub Profile
@max747
max747 / PdfJoiner.java
Created May 20, 2011 04:08
concatenate pdfs (using iText)
import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfCopy;
import com.itextpdf.text.pdf.PdfImportedPage;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.RandomAccessFileOrArray;
@max747
max747 / Utils.java
Created May 24, 2011 02:38
map関数を実現したい
import java.util.Collection;
public class Utils {
public static <S, T, R extends Collection<T>> R map(Collection<S> target, Function<S, T> function, Class<R> clazz) {
R newCollection = null;
try {
newCollection = clazz.newInstance();
} catch (InstantiationException e) {
throw new RuntimeException();
@max747
max747 / VelocityEngineUtils.java
Created May 25, 2011 08:52
Using Velocity Tools 2.0 in SpringFramework 3.0.x
/*
* Copyright 2002-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@max747
max747 / BlockJunit4ClassRunner.java
Created May 26, 2011 03:25
Execute platform-dependent test using JUnit4
@Override
protected void runChild(FrameworkMethod method, RunNotifier notifier) {
EachTestNotifier eachNotifier= makeNotifier(method, notifier);
if (method.getAnnotation(Ignore.class) != null) {
runIgnored(eachNotifier);
} else {
runNotIgnored(method, eachNotifier);
}
}
@max747
max747 / App.java
Created June 2, 2011 00:22
Using list, map, ... with annotated Spring bean
package sandbox.spring;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class App {
public static void main(String[] args) {
ApplicationContext context =
new ClassPathXmlApplicationContext("applicationContext.xml");
SampleBean sample = context.getBean(SampleBean.class);
@max747
max747 / Message.java
Created July 2, 2011 13:52
use property placeholder in SpringFramework MessageSource
package sandbox.message;
import java.util.Locale;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Service;
@Service
public class Message {
<%
java.util.Enumeration e = request.getAttributeNames();
while (e.hasMoreElements()) {
Object o = e.nextElement();
Object attr = request.getAttribute(o.toString());
if (request.getAttribute(o.toString()) instanceof org.springframework.validation.BindingResult) {
org.springframework.validation.BindingResult r = (org.springframework.validation.BindingResult) attr;
out.println(r.getObjectName());
java.util.List<FieldError> errors = r.getFieldErrors();
out.println("<br> ---------------- <br>");
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Node;
import org.dom4j.io.SAXReader;
import org.junit.Test;
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:02.492s
[INFO] Finished at: Wed Sep 07 12:32:18 JST 2011
[INFO] Final Memory: 12M/32M
[INFO] ------------------------------------------------------------------------
[ERROR] Character reference "&#55527" is an invalid XML character. -> [Help 1]
org.xml.sax.SAXParseException: Character reference "&#55527" is an invalid XML character.
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
@max747
max747 / gist:1202512
Created September 8, 2011 03:06
テキストファイルを1000個つくる
import java.io._
{ 1 to 1000 } map { n => "hoge%04d.txt".format(n) } foreach { name =>
val writer = new PrintWriter(new FileWriter(name))
writer.println("hogehoge")
writer.close
}