Skip to content

Instantly share code, notes, and snippets.

Avatar

Keith Donald kdonald

View GitHub Profile
View MappingJackson2HttpMessageConverter.java
/*
* Copyright 2002-2012 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
@kdonald
kdonald / CorisFilter.java
Created Mar 29, 2012
Basic Cross Origin Resource Sharing (CORS) support
View CorisFilter.java
package org.springframework.web.servlet.support;
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.filter.OncePerRequestFilter;
@kdonald
kdonald / facebook.js
Created Mar 25, 2012
Facebook AMD Module
View facebook.js
define("facebook", ["jquery", "https://connect.facebook.net/en_US/all.js"], function($) {
$("<div id='fb-root'></div>").prependTo($("body"));
FB.init({
appId : 'YOUR_APP_ID', // App ID
channelUrl : '//YOUR_DOMAIN/channel.html', // Channel File
status : false, // check login status
cookie : false, // enable cookies to allow the server to access the session
xfbml : false // parse XFBML
@kdonald
kdonald / JsonNodeRowMapper.java
Created Mar 20, 2012
Auto Mapping a JDBC ResultSet to JSON
View JsonNodeRowMapper.java
// convenient Spring JDBC RowMapper for when you want the flexibility of Jackson's TreeModel API
// Note: Jackson can also serialize standard Java Collections (Maps and Lists) to JSON: if you don't need JsonNode,
// it's simpler and more portable to have Spring JDBC simply return a Map or List<Map>.
package org.springframework.jdbc.core;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
@kdonald
kdonald / ExternalizedSql.java
Created Mar 11, 2012
Spring JDBC Extension - Externalized SQL strings
View ExternalizedSql.java
// example api usage:
String sql = SqlUtils.sql(new ClassPathResource("complex.sql", getClass()));
// example complex.sql
SELECT {a bunch of fields}
FROM {table}
INNER JOIN {other} ON ...
INNER JOIN {other} ON ...
@kdonald
kdonald / ExampleController.java
Created Mar 10, 2012
RestTemplate + Jackson Solr Client Example
View ExampleController.java
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import org.codehaus.jackson.JsonNode;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.node.ObjectNode;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
View WelcomeMailerTests.java
package com.example.mail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.io.InputStreamReader;
import java.io.Reader;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@kdonald
kdonald / jmustache-spring-mvc.java
Created Jan 12, 2012
JMustache Spring MVC Integration
View jmustache-spring-mvc.java
build.gradle
------------
jmustacheVersion = '1.5'
dependencies {
compile 'com.samskivert:jmustache:$jmustacheVersion'
}
JMustacheViewResolver.java
--------------------------
package org.springframework.servlet.mvc.view.jmustache;
@kdonald
kdonald / gist:1150698
Created Aug 17, 2011
$.Deferred refactoring
View gist:1150698
// BEFORE $.Deferred()
mainView.render(function(root) {
var mainContent = root.find("#content");
subView.render(function(el) {
mainContent.append(el);
nestedView.render(function(el) {
mainContent.append(el);
allDoneCallback(root);
});
@kdonald
kdonald / ecmascript5-objects.js
Created Jul 6, 2011
ECMAScript 5 Objects and Properties
View ecmascript5-objects.js
var ns = ns || {};
ns.PropertyUtils = {
// Make the named (or all) properties of o nonenumerable, if configurable.
hide : function(o) {
var props = (arguments.length == 1)
? Object.getOwnPropertyNames(o)
: Array.prototype.splice.call(arguments, 1);
props.forEach(function(p) {