Skip to content

Instantly share code, notes, and snippets.

@yclian
yclian / HibernateTest.java
Created September 12, 2011 08:00
Mocking a Hibernate session / testing Criteria
package yourpackage;
import static org.mockito.Mockito.*;
import java.util.HashMap;
import org.hibernate.SessionFactory;
import org.hibernate.classic.Session;
import org.hibernate.dialect.MySQL5Dialect;
import org.hibernate.dialect.function.SQLFunctionRegistry;
@yclian
yclian / Version.java
Created May 7, 2012 12:54
Version Comparator in Java
package foo;
import static java.util.regex.Pattern.compile;
import static org.apache.commons.lang3.StringUtils.substringAfter;
import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;
@yclian
yclian / dm_helper.rb
Created July 31, 2012 05:02
RSpec helper that starts and rolls (back) a transaction
module DataMapperHelper
end
RSpec.configure do |c|
# See: http://rhnh.net/2010/10/06/transactional-before-all-with-rspec-and-datamapper
[:all, :each].each do |s|
c.before s, :type => :api do
repository :default do |r|
t = DataMapper::Transaction.new(repository)
t.begin
FactoryGirl.define do
factory :person do
sequence(:name) { |n| "Nicole Neal (#{n})" }
factory :person_with_party do
after_create do |person|
# TODO
# party = FactoryGirl.create(:party)
# FactoryGirl.create(:party_membership, { party: party, member: member, joined_at: 1.year.ago.year })
end
@yclian
yclian / SearchQueryToSQL .java
Created September 21, 2012 12:28
Search query to SQL
import java.lang.System;
import java.util.*;
import java.util.regex.*;
import java.util.regex.Pattern;
public class SearchQueryToSQL {
public static void main(String[] args) {
String search = "LOL \\* abc* def_huaua def\\_\\% [lolipop]";
@yclian
yclian / developer_spec.rb
Last active December 17, 2015 06:38
This is a spec to hire for a Ruby/Rails developer to work on developing tools and extensions for Zendesk - one of the best helpdesk solutions available!
require 'spec_helper'
# == About
#
# This is a spec to hire for a Ruby/Rails developer to work on developing tools
# and extensions for Zendesk - one of the best helpdesk solutions available!
#
# == More About CustomWare
#
# CustomWare is a US based company with offices in Australia, Malaysia and
@yclian
yclian / google_geocode
Last active December 18, 2015 05:39
Map/Real/Geo queries and samples
# http://maps.googleapis.com/maps/api/geocode/json?address=Jalan%203/23A%20Danau%20Kota,%20Kuala%20Lumpur&sensor=false
{
"results" : [
{
"address_components" : [
{
"long_name" : "Jalan 3/23a",
"short_name" : "Jalan 3/23a",
"types" : [ "route" ]
@yclian
yclian / build.gradle
Last active December 18, 2015 10:48
`build.gradle` for `spark-demo`.
apply plugin: 'java'
apply plugin: 'idea'
apply from: 'libraries.gradle'
defaultTasks 'build'
group = 'com.yclian.demo.spark'
repositories {
mavenCentral()
@yclian
yclian / maven-wadl-plugin.xml
Created February 18, 2014 06:21
Sample configuration of Maven WADL Plugin
<plugin>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>maven-wadl-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
@yclian
yclian / git.diff
Last active August 29, 2015 14:02
Additional configuration for Gradle to publish JaCoCo report to Sonar
build.gradle | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/build.gradle b/build.gradle
index cc52b8f..c053194 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,6 +5,7 @@ apply from: "${ext.scriptDir}/common/java.gradle"
apply from: 'libraries.gradle'