Skip to content

Instantly share code, notes, and snippets.

@peysal
peysal / UpdateSignature.java
Created April 10, 2012 16:41
Using adobe fdf to populate value inside pdf
package my.mbb.incr2;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.net.URISyntaxException;
import java.net.URL;
import com.adobe.fdf.FDFDoc;
import com.adobe.fdf.exceptions.FDFException;
@peysal
peysal / introduction.scala
Created November 17, 2012 05:59
Basic scala
//val cannot be change
val two = 1 + 1
//functions are object
object Timer {
def oncePerSecond(callback: () => Unit) {
while (true) { callback(); Thread sleep 1000 }
}
def timeFlies() {
println("time flies like an arrow...")
@peysal
peysal / FirstTest.java
Last active December 13, 2015 21:08
Simple unit test using CamelTestSupport. I having problem running unit test with camel. So I going to do step by step as what mentioned in camel in action.
import java.io.File;
import org.apache.camel.Exchange;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Test;
public class FirstTest extends CamelTestSupport {
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@peysal
peysal / SpringFirstTest.java
Created February 18, 2013 09:04
Camel test using xml file
import java.io.File;
import org.apache.camel.Exchange;
import org.apache.camel.test.junit4.CamelSpringTestSupport;
import org.junit.Test;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SpringFirstTest extends CamelSpringTestSupport {
protected AbstractXmlApplicationContext createApplicationContext() {
return new ClassPathXmlApplicationContext("CONTEXT-INF/firststep.xml");
@peysal
peysal / firststep.xml
Created February 18, 2013 09:05
Xml file for camel
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">
<camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="file://target/inbox" />
@peysal
peysal / Introduction1.groovy
Last active December 21, 2015 13:49
Groovy introduction: 1) no accessors method 2) gString 3) accessing object 4) equality operator not referring to memory address extra: can change the value to make wrong assertion just to show groovy trace
class Person {
String name
int age
}
//no accessors method
Person person = new Person()
person.name = "goku"
println "helloo ${person.name}"
@peysal
peysal / introduction2.groovy
Last active December 21, 2015 13:49
Groovy introduction: 1) list 2) operator overloading 3) method pointer
def list = []
assert list.isEmpty()
list.add("ayam")
list.add "babun" //optional parentheses, except if it doesnt have any argument
list << "cicak" //operator overloading
assert list.size == 3
println list
def tambah = list.&add //method pointer in action
tambah "dugong"
@peysal
peysal / introduction3.groovy
Created August 23, 2013 04:13
Introduction to groovy 1) duck typing 2) return is optional, last statement will be taken
class Person {
def name //duck typing
def age
def getName() { //override default getter
"will not be printed"
"my name is ${name}" //return is optional, last statement is taken
}
}
person = new Person(name:"goku")
@peysal
peysal / introduction4.groovy
Last active December 21, 2015 13:49
Introduction to groovy. Safe deferencing and auto boxing
class Person {
def name
def spouse
def age
}
candidate1 = new Person(name:"bill", spouse: new Person(name:"lengloy"))
candidate1.spouse.spouse = candidate1
assert candidate1.spouse.spouse != null
@peysal
peysal / introduction5.groovy
Created August 23, 2013 09:45
List in groovy
def teamMembers1 = ["p1", "p2", "p3"] //by default arrayList
teamMembers1 << "p4"
assert teamMembers1.size() == 4
teamMembers2 = ["b1", "b2"] as Set //setting the type
teamMembers2 << "b1"
assert teamMembers2.size() == 2
emptyList = [] //empty list
assert emptyList.size() == 0