Skip to content

Instantly share code, notes, and snippets.

@criminy
criminy / HelloWorldResource.java
Created December 26, 2011 04:51
powderj example view.
/**
* Resource which shows the hello world message.
*
* @author sheenobu
*
*/
@Path("/")
public class HelloWorldResource {
// we don't need to load this from a singleton context (yet) because
@criminy
criminy / GetTimeResource.java
Created December 16, 2011 04:04
underscore JS demo
@Path("/time.json")
public class GetTimeResource
{
@GET
@Produces("application/json")
public String currentTimeAsJson() {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
//get current date time with Date()
Date date = new Date();
return String.format("{\"timeKey\":\"%s\"}",dateFormat.format(date));
@criminy
criminy / add_ssl.groovy
Created November 30, 2011 14:36
Mockup of ActiveRecord-style using groovy/gradle style.
accounts = table("accounts")
migration("add_ssl") {
up {
add_column accounts "ssl_enabled" Fields.boolean {
defaults 1
}
}
down {
remove_column accounts "ssl_enabled"
@criminy
criminy / PageI.java
Created October 5, 2011 01:01
Initial MyBatis support for Spring-Data (specifically a sample repository and Pagination).
import java.util.Collection;
import java.util.List;
import java.util.ListIterator;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
/**
* Extension class between spring data commons and java.util.List that is
* required to get MyBatis to use it as a return value.
@criminy
criminy / LazyListTest.java
Created September 14, 2011 18:56
Figuring out the building of lists from functions and lazy lists with memoization.
import static org.junit.Assert.*;
import java.util.List;
import org.junit.Test;
import com.google.common.base.Function;
import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
import com.google.common.collect.ImmutableList;
@criminy
criminy / Example.java
Created September 12, 2011 20:34
Lazy List Utilities useful for lazy-loading of DAO collections.
RepositoryInstance repositoryInstance; //some Repository which has findById.
List<T> lazyList = LazyListUtil.idListToLazyList(jdbcTemplate.queryForList("select foreign_key from join_table where primary_key = ?",new Object[]{id},String.class),repositoryInstance));
// The only query run so far "select foreign key from join_table where primary_key = ?" . the others aren't run until we use lazyList, which would be inside RepositoryInstance.
@criminy
criminy / AbstractJdbcRepository.java
Created September 9, 2011 16:43
Implementation of PagingAndSortingRepository using JdbcTemplate
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
@criminy
criminy / TerrastoreClientMock-fragment.java
Created August 5, 2011 14:34
Proof of concept Mockito Mock of the terrastoreclient.
@Bean
public Map<String, DocumentPackage> mockDpBucket() {
return new HashMap<String, DocumentPackage>();
}
class WildcardExtractingHamcrestMatcher extends ArgumentMatcher<String> {
String regex;
public WildcardExtractingHamcrestMatcher(String reg) {
this.regex = reg;
@criminy
criminy / ExampleWebAppInitializer.java
Created August 2, 2011 12:05
Example Application
package us.gaje.example.web;
public class ExampleWebAppInitializer extends GajeStandardWebAppInitializer{
@Override
protected WebApplicationContext createWebApplicationContext() {
AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
root.getEnvironment().setDefaultProfiles("embedded");
root.scan("us.gaje.example.web.config");
return root;
@criminy
criminy / install.sh
Created July 31, 2011 20:39
A pax-run profile for karaf 2.2.1
mvn install:install-file -DgroupId=org.ops4j.pax.runner.profiles -DartifactId=karaf.shell.new -Dversion=2.2.1 -Dfile=karaf.shell-2.2.1.composite -Dpackaging=composite