I'm not a Mac guy but was instructed to do so. Ran through a few web site, try to install pkg-config, fuse, glib, ... ... and end up with the simplest solution.
Step 1:
Install MacPorts from http://www.macports.org/
Step 2:
Install s3fs with MacPorts.
port install s3fs
Done.
Thanks to MacPorts
Wednesday, June 20, 2012
Thursday, May 17, 2012
Manually Sort an ArrayList in Java
Just like to paste this code:
Listsorted = new ArrayList (); RackPosition temp = null; int remove_index = -1; while(original.size() > 0) { temp = original.get(0); for (int i = 0; i < original.size(); i++ ) { RackPosition rp2 = original.get(i); if(temp.getPositionNumber().compareTo(rp2.getPositionNumber()) > 0) { temp = rp2; remove_index = i; } } System.out.println("Adding " + temp.getPositionNumber()); sorted.add(temp); // original.remove(temp); if(remove_index >= 0) { original.remove(remove_index); } remove_index = 0; }
Labels:
Java
Wednesday, March 21, 2012
Generate S3 Pre-signed URL in Java
I googled, not happy, so post it myself.
FYI:
and required access to Internet/AWS.
Do feedback if you really like this post.
import java.util.Calendar;
import java.util.Date;
import com.amazonaws.HttpMethod;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
public class PreSignURLGenerator {
private final static String BUCKET_NAME = "this-is-not-porn";
private final static String FILE_NAME = "not-porn-media-files/0146ce52-bbd5-4998-9378-35c20ece0000.jpg";
private final static String ACCESS_KEY = "not-telling-you";
private final static String SECRET_KEY = "it-s-a-secret";
/**
* @param args
*/
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
cal.add(Calendar.SECOND, 1000);
Date expDate = cal.getTime();
try {
BasicAWSCredentials cre = new BasicAWSCredentials(ACCESS_KEY, SECRET_KEY);
AmazonS3 s3 = new AmazonS3Client(cre);
String url = s3.generatePresignedUrl(BUCKET_NAME, FILE_NAME, expDate, HttpMethod.GET).toString();
System.out.println(url);
} catch (Exception e) {
e.printStackTrace();
}
}
}
FYI:
and required access to Internet/AWS.
Do feedback if you really like this post.
Wednesday, February 29, 2012
jBPM - How to trace a lifecycle of a process
Just need to add a ProcesEventListener() to the ksession.
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
CustomProcessEventListener customProcessEventListener = new CustomProcessEventListener();
ksession.addEventListener(customProcessEventListener);
...
...
ksession.startProcess("com.sample.MyTaskFlow", params);
And here is the sample CustomProcessEventListener();
private static class CustomProcessEventListener implements ProcessEventListener {
@Override
public void afterNodeLeft(ProcessNodeLeftEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void afterNodeTriggered(ProcessNodeTriggeredEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void afterProcessCompleted(ProcessCompletedEvent arg0) {
// TODO Auto-generated method stub
logger.debug("Process has completed.");
System.exit(0);
}
@Override
public void afterProcessStarted(ProcessStartedEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void afterVariableChanged(ProcessVariableChangedEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void beforeNodeLeft(ProcessNodeLeftEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void beforeNodeTriggered(ProcessNodeTriggeredEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void beforeProcessCompleted(ProcessCompletedEvent arg0) {
// TODO Auto-generated method stub
logger.debug("Process is going to be completed.");
}
@Override
public void beforeProcessStarted(ProcessStartedEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void beforeVariableChanged(ProcessVariableChangedEvent arg0) {
// TODO Auto-generated method stub
}
}
As you can see, you can do many things on every stage of a process.
Tuesday, February 28, 2012
Drools again, example for beginner
Who would foresee that I will get my hand dirty again with drools? Well, after 13 months, here I am, looking at drools, again... now with jbpm too.
Anyway, it was good. Got better understanding about it and yeah, as usual, share.
I successfully made this:
I am not posting the codes here, you can request for it if you want.
The first process flow (can be in .rf or .bpmn) shows how to use Script Tasks. In the "Question" script, I ran these:
The gateway after the "Question" script I check for this:
The "Error message" script just print error message. I ran the process.
It will keep on asking you who the question until you say "frank". Pretty basic but it gives you better understand about how things run.
Here is the sample output.
The learning issues here will be:
For beginners, you should try it out your self.
Many thanks to Drools/jBPM development team and the community for their hard work. Many helpful resources are now available online compare to last year.
Anyway, it was good. Got better understanding about it and yeah, as usual, share.
I successfully made this:
The first process flow (can be in .rf or .bpmn) shows how to use Script Tasks. In the "Question" script, I ran these:
System.out.println("Who is the smartest man in the world?");
java.io.BufferedReader br = new java.io.BufferedReader(new
java.io.InputStreamReader(System.in));
String name = null;
try {
name = br.readLine();
} catch (java.io.IOException e) {
System.out.println("Error!");
}
kcontext.setVariable("smart_guy", name);
The gateway after the "Question" script I check for this:
return smart_guy.equals("frank");
The "Error message" script just print error message. I ran the process.
ksession.startProcess("interactiveJava");
It will keep on asking you who the question until you say "frank". Pretty basic but it gives you better understand about how things run.
Here is the sample output.
The learning issues here will be:
- Define variable "smart_guy" in the flow/process.
- In the "Question" script, we set the user input to the process variable.
kcontext.setVariable("smart_guy", name);
- In the gateway constraint:
return smart_guy.equals("frank");
For beginners, you should try it out your self.
Many thanks to Drools/jBPM development team and the community for their hard work. Many helpful resources are now available online compare to last year.
Wednesday, January 25, 2012
Can you cook an egg in your car? Yes you can!
Today I ran a very crazy experiment with my car. Because it was very very hot today, 40°. So I want to see if I can cook an egg inside the car dashboard. And here is the result.
Too bad I didn't record the temperature inside the car, but it IS hot enough to cook an egg.
Too bad I didn't record the temperature inside the car, but it IS hot enough to cook an egg.
Wednesday, December 14, 2011
Who sucks?
When googling and found
... always annoys me. I learned it from the hard way, so I just want to present a fairer view and give you another perspective.

Plain: google search the keyword
Sucks: adds a ' sucks' at the end of the keyword
Great: adds a ' great' at the end of the keyword
I'll let you guys do your own conclusion.
Plain: google search the keyword
Sucks: adds a ' sucks' at the end of the keyword
Great: adds a ' great' at the end of the keyword
I'll let you guys do your own conclusion.
Subscribe to:
Posts (Atom)



