Skip to content

Instantly share code, notes, and snippets.

@kjunine
kjunine / cors.js
Created July 25, 2013 06:46
CORS GET example for MSIE 8 & 9
var callback = function(data) { console.log(data); };
var url = "http://somewhere.in/the.web";
if (windows.XDomainRequest) {
var xdr = new XDomainRequest();
xdr.open("get", url);
xdr.onload = function() {
callback(this.responseText, 'success');
};
xdr.send();
@kjunine
kjunine / CrossOriginResourceSharingInterceptor.java
Created July 25, 2013 05:51
CrossOriginResourceSharingInterceptor When using @responsebody, response header SHOULD be set in the preHandler method.
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
public class CrossOriginResourceSharingInterceptor implements
HandlerInterceptor {
private static final String DEFAULT_ALLOW_ORIGIN = "*";
@kjunine
kjunine / pom.xml
Created July 4, 2013 12:11
maven-shade-plugin for spring application
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
@kjunine
kjunine / tests.sc
Created May 18, 2013 07:23
Tests foldLeft and foldRight of List in Scala.
package streams
object tests {
def xtoy(x: Int, y: List[Int]): List[Int] = {
println(x + " @ " + y)
x :: y
}
def ytox(x: List[Int], y: Int): List[Int] = {
@kjunine
kjunine / BytesBuilder.java
Created May 10, 2013 06:53
BytesBuilder to make row key for HBase.
package iadb.data.utils;
import static org.apache.hadoop.hbase.util.Bytes.*;
import java.math.BigDecimal;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
public class BytesBuilder {
@kjunine
kjunine / ParentLastClassLoader.java
Created May 1, 2013 02:37
ParentLastClassLoader
import java.net.URL;
import java.net.URLClassLoader;
public class ParentLastClassLoader extends ClassLoader {
private ChildURLClassLoader childClassLoader;
/**
* This class allows me to call findClass on a classloader
*/
@kjunine
kjunine / JacksonObjectMapperUtils.java
Created May 1, 2013 02:35
JacksonObjectMapperUtils for JSON conversion in Spring MVC
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonProcessingException;
import org.codehaus.jackson.Version;
import org.codehaus.jackson.map.DeserializationContext;
import org.codehaus.jackson.map.JsonDeserializer;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.map.module.SimpleModule;
import org.codehaus.jackson.node.ObjectNode;
public class JacksonObjectMapperUtils {
@kjunine
kjunine / jsonp.html
Last active December 16, 2015 20:29 — forked from anonymous/jsonp.html
JSONP sample of Daum Search API using jQuery
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>JSONP</title>
</head>
<body>
<script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
$(function() {
@kjunine
kjunine / ApiAuthenticationEntryPoint.java
Created April 30, 2013 07:15
API Authentication with spring security
@Component
public class ApiAuthenticationEntryPoint implements
AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request,
HttpServletResponse response, AuthenticationException authException)
throws IOException, ServletException {
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Unauthorized");
}
@kjunine
kjunine / RequestAttribute.java
Last active June 4, 2016 11:44
Spring MVC에서 WebArgumentResolver를 이용하여 @RequestAttribute 어노테이션 추가하기
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface RequestAttribute {