Skip to content

Instantly share code, notes, and snippets.

View kdonald's full-sized avatar

Keith Donald kdonald

View GitHub Profile
@kdonald
kdonald / connect-m3.txt
Created April 22, 2011 15:21
Spring Social Connect - Upcoming 1.0.0.M3 API
2. Service Provider 'Connect' Framework
The spring-social-core module includes a Service Provider 'Connect' Framework for managing connections to Software-as-a-Service (SaaS) providers such as Facebook and Twitter. This framework allows your application to establish connections between local user accounts and accounts those users have with external service providers. Once a connection is established, it can be be used to obtain a strongly-typed Java binding to the ServiceProvider's API, giving your application the ability to invoke the API on behalf of a user.
To illustrate, consider Facebook as an example ServiceProvider. Suppose your application, AcmeApp, allows users to share content with their Facebook friends. To support this, a connection needs to be established between a user's AcmeApp account and her Facebook account. Once established, a FacebookApi instance can be obtained and used to post content to the user's wall. Spring Social's 'Connect' framework provides a clean API for managing service prov
@kdonald
kdonald / ecmascript5-objects.js
Created July 6, 2011 16:46
ECMAScript 5 Objects and Properties
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) {
@kdonald
kdonald / gist:1150698
Created August 17, 2011 02:40
$.Deferred refactoring
// 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 / jmustache-spring-mvc.java
Created January 12, 2012 21:38
JMustache Spring MVC Integration
build.gradle
------------
jmustacheVersion = '1.5'
dependencies {
compile 'com.samskivert:jmustache:$jmustacheVersion'
}
JMustacheViewResolver.java
--------------------------
package org.springframework.servlet.mvc.view.jmustache;
@kdonald
kdonald / WelcomeMailerTests.java
Created January 24, 2012 17:01
Mail Sending Example
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 / ExampleController.java
Created March 10, 2012 17:54
RestTemplate + Jackson Solr Client Example
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;
@kdonald
kdonald / ExternalizedSql.java
Created March 11, 2012 20:43
Spring JDBC Extension - Externalized SQL strings
// 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 / JsonNodeRowMapper.java
Created March 20, 2012 16:35
Auto Mapping a JDBC ResultSet to JSON
// 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 / facebook.js
Created March 25, 2012 03:56
Facebook AMD Module
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 / CorisFilter.java
Created March 29, 2012 01:12
Basic Cross Origin Resource Sharing (CORS) support
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;