Thursday, January 17, 2008

Nature's Marbles


Nature's Marbles, originally uploaded by Matt Hughes.

Sunday, January 13, 2008

Favorite photos


, originally uploaded by zebaislam.

Saturday, January 12, 2008

with your feet in the air
and your head on the ground
try this trick & spin it ... ... ...
your head will collapse
if theres nothing in it
you will ask yourself where is my mind?

Thursday, January 10, 2008

Regular expression in java

http://java.sun.com/developer/technicalArticles/releases/1.4regex/

String input = "something";

1. write a regular expression
String regex="your_reg_ex"; 


2. create a pattern object compiling your regex


Pattern p = Pattern.compile(regex);


3. create a matcher object that will match input string with the compiled regex

Matcher m = p.matcher(input);


4. check whether any matching found

if (m.find())
{
//5. if found, the matched portion will be available at m.group()
String found = m.group();
// do whatever u like
 }

let, input = "fjkl;pokjhA123ss456Apghkit"
u want to read block between 2 A's
regex = (?<=X).*?(?=X) where X = "A" here output = "123ss456" u can only use fixed length string in (?<=X), never use .*? or + in X otherwise u'll get exception
Look-behind group does not have an obvious maximum length near index ..



Java code for this:
 1 
 2   String regularExp = "(?<=A).*?(?=A)";

 3 
 4   String input = "fjkl;pokjhA123ss456Apghkit";
 5 

 6   Pattern pattern = Pattern.compile(regularExp);

 7   
 8   Matcher matcher =  pattern.matcher(input);

 9      
10      if(matcher.find())
11         {

12         String parsedData = matcher.group();
13                 System.out.println(" Output ->"+parsedData);

14          }
15        

SSHClient in java

http://www.docjar.com/docs/api/com/sshtools/j2ssh/SshClient.html

Saturday, December 22, 2007

struts2+Spring workflow

1. An initial request goes to the Servlet container (such as Jetty or Resin) which is passed through a standard filter chain.

2. the required FilterDispatcher is called, which in turn consults the ActionMapper to determine if the request should invoke an action.


3. The ActionMapper interface provides a mapping between HTTP requests and action invocation requests and vice-versa.

When given an HttpServletRequest, the ActionMapper may return null if no action invocation request matches, or it may return an ActionMapping that describes an action invocation for the framework to try.

If the ActionMapper determines that an Action should be invoked, the FilterDispatcher delegates control to the ActionProxy.

4. The ActionProxy consults the framework Configuration Files manager (initialized from the struts.xml file).

5. the ActionProxy creates an ActionInvocation, which is responsible for the command pattern implementation. This includes invoking any Interceptors (the before clause) in advance of invoking the Action itself.

6. Once the Action returns, the ActionInvocation is responsible for looking up the proper result associated with the Action result code mapped in struts.xml.

7. The result is then executed, which often (but not always, as is the case for Action Chaining) involves a template written in JSP or FreeMarker to be rendered.


8. While rendering, the templates can use the Struts Tags provided by the framework.

9. All objects in this architecture (Actions, Results, Interceptors, and so forth) are created by an ObjectFactory.

This ObjectFactory is pluggable. We can provide our own ObjectFactory
A popular ObjectFactory implementation uses Spring as provided by the Spring Plugin.

Normally, in struts.xml you specify the class for each Action. When using the default SpringObjectFactory, the framework will ask Spring to create the Action and wire up dependencies as specified by the default auto-wire behavior.


10. Interceptors are executed again (in reverse order, calling the after clause).


11. Finally, the response returns through the filters configured in the web.xml.


N.B:
don't know how to setup simple struts2 project? see simple setup

Monday, December 10, 2007

The 5 stages of grief


1. Denial: The initial stage: "It can't be happening."
2. Anger: "Why ME? It's not fair!" (either referring to God, oneself, or anybody perceived, rightly or wrongly, as "responsible")
3. Bargaining: Now the grieving person may make bargains with God, asking, "If I do this, will you take away the loss?"
4. Depression: "I'm so sad, why bother with anything?"
5. Acceptance: "It's going to be OK."


Kübler-Ross model

Wednesday, December 05, 2007

SCP using java api

same as SFTP example except use ScpClient in place of SFTPClient


ScpClient client = ssh.openScpClient();

// Open the SCP channel
String localFile = "localPath";
String remoteFile = "remotePath";

//
//get method signature
//public void get(java.lang.String localFile,
// java.lang.String remoteFile,
// boolean recursive,
// FileTransferProgress progress)
// throws SshException,
// ChannelOpenException
//

client.get(localFile,remoteFile,true);




syntax highlighted by Code2HTML, v. 0.9.1

SFTP using java api

Librery used SSHTools-J2SSH
Tutorial help from David Hayes

1
2 String userName = "someuser";

3 String password = "somepwd";
4
5 String host = "host_ip";

6 int port = 22;
7
8 String destinationPath = "<your_dest>";

9 String sourcePath = "<your_src>";
10
11 SshClient ssh = new SshClient();

12
13 try{
14 ssh.connect(host, port);

15
16 // Authenticate
17 PasswordAuthenticationClient passwordAuthenticationClient =
18 new PasswordAuthenticationClient();

19
20 passwordAuthenticationClient.setUsername(userName);
21 passwordAuthenticationClient.setPassword(password);

22
23 int result = ssh.authenticate(passwordAuthenticationClient);

24 if(result != AuthenticationProtocolState.COMPLETE){
25

26 throw new FTPException("Login to " + host + ":"

27 + port + " " + userName + "/" + password + " failed");

28
29 }
30
31 // Open the SFTP channel
32 SftpClient client = ssh.openSftpClient();

33 //change local directory where file would be copied
34 client.lcd(destination);
35 // download file

36 client.get(sourceFilePath);
37
38 client.quit();

39 ssh.disconnect();
40
41 }
42 catch(IOException e)

43 {
44
45 // file transfer failed
46 e.printStackTrace();

47 }




syntax highlighted by Code2HTML, v. 0.9.1

Tuesday, December 04, 2007

Writing pdf file using java

Librery used iText

// Step 1: Create an instance of com.lowagie.text.Document:

Document document = new Document();

//Step 2: Create a Writer (for instance com.lowagie.text.pdf.PdfWriter)
//that listens to this document and
//writes the document to the OutputStream of your choice:

PdfWriter.getInstance(document, new FileOutputStream("HelloWorld.pdf"));

//Step 3: Open the document:

document.open();

//Step 4: Add content to the document:

document.add(new Paragraph("Hello World"));

//Step 5: Closes the document:

document.close();



syntax highlighted by Code2HTML, v. 0.9.1

check other tutorials

Thursday, November 22, 2007

Help Sidr affected people

1. Type 'save' in your cell and send it to 5455
. your 1 single sms will give 15 tk to the cyclone
affected people. it's a joint project of "save the
children" and somewhereinblog.

2. You can also write “help” and send to “1010” from any mobile in Bangladesh.
It’s a joint initiative taken by all the mobile operator in Bangladesh and fully reliable.For each sms taka 10 will be deducted from your account and the total money will be donated for the SIDR affected people.

3. Directly to the Chief Adviser's Relief and Welfare Fund:
Current Account No.33004093 with Sonali Bank, Prime Minister's Office
Branch, Tejgaon, Dhaka, Bangladesh

4. Bangladesh Red Crescent Society
A/C No. 01-1336274-01
Standard Chartered Bank
Dhaka Bangladesh
SWIFT Code: SCBLBDDX

Here is a list of organizations we can send our contributions to:

UNICEF
Save the Children – US

International Federation of Red Cross and Red Crescent Societies

World Vision Web

World Vision Web
BY PHONE 1-888-562-4453 (888-56-CHILD) and donating with the “giving
code” of Bangladesh Cyclone Relief.

CARE Responds to Bangladesh Cyclone - Donate Now

Islamic Relief

Catholic Relief Services

Food for the Hungry

How to donate to "Chief Advisor's Relief and Welfare"
# Method 1
Check/money order/bank draft
Payable to : "Bangladesh Consulate General in New
York"
Memo: For Chief Advisor's Relief and Welfare Fund
Address to send:
211 East 43rd Street, Suite 502
NY 10017

*You will get an acknowledgment receipt from
Bangladesh Consulate General

# Method 2

Money Transfer via Sonali Exchange Co. Inc
Check payable to "Sonali Exchange Co. Inc. USA"
Memo: For chief advisor's relief and welfare fund
Address to send:
211 East 43rd St,
Suite # 1503
NY 10017
Tel: 212-808-0790/212-808-4085

Friday, November 16, 2007

1,100 reported killed in Bangladesh cyclone






Death toll may cross 1,000; all communications, utility services snapped; thousands missing; houses, crops, trees destroyed; lakhs homeless


Bangladesh dated with a nightmare as cyclone Sidr ripped through the southwestern coast late Thursday, killing over 700 people and demolishing houses, crops, vegetables and trees alike along its trail of devastation over an area of thousands of square kilometers.

Packing winds over 220km an hour, the fierce tropical storm roared across the shoreline after it hit landfall at the Khulna-Barisal coast at 7:30pm Thursday, cutting off all communications and utility services across the country.


One of the fiercest cyclones in the history of the land, the Sidr rode on wailing winds, driving rains and tidal surges to wreak havoc for over 14 hours before moving to Asam and Tripura through the Sylhet border, turning into a well-marked low yesterday.

Despite having carried out a commendable evacuation effort, the government last night found itself reeling from shock as the number of deaths and extent of damage continued to increase with every passing hour.

In a rather awkward manner, the food and disaster management ministry told the press in the afternoon that about 233 people were killed but left out death tolls in two most-affected districts--- Borguna and Jhalakathi. However, the same briefing stated that Red Crescent found 118 dead so far in Barguna alone.

But within hours at 12 midnight, an official at the food and disaster management ministry's control room raised the death figure to 700, with maximum 177 killed in Patuakhali. However, quoting unofficial sources, Our Correspondent in Patuakhali, reported death of 490 people.

But finds of newsmen and different private sources till filing of this report early morning today revealed that the death toll is destined to climb up to 1,000 as rescuers and volunteers could not yet reach most of the worst-hit areas.

Meanwhile, no information on causalities could be gathered from numerous remote islands (chars), residents of which mostly turned a deaf ear to government's evacuation alert.

“Tidal waves swept away many people from Dublar Char in Bagerhat”, Red Crescent worker Abul Kashem Dulal told our correspondent in Barisal. Of them, bodies of 17 people could be recovered.

The government could provide shelter for around 15 lakh people in 2168 shelter houses, leaving around 33 lakh people in the coastal areas in vulnerable situation.

Casualties apart, the Patuakhali district also suffered most in the farm sector. “The crop loss should be no less than Tk 497 crore in the seven upazilas,” he said, quoting a rough estimate of a deputy director of agriculture extension department in Patuakhali.

The Patuakhali town went under knee-deep waters as tidal surges 6-7 feet higher than normal ones sped through the locality. At least seven other southern districtsBarguna, Jhalakathi, Pirojpur, Bhola, Madaripur, Barisal and Bagerhat suffered nearly the same fate of Patuakhali.

However, the actual extent of destruction in Bagerhat could not be known till filing of this report as a very few could reach areas like Sharankhola near the worst-hit Sundarbans, the world's largest mangrove forest.

“Hundreds of trees lying on the roads and fields give a picture of massive damage,” said Raphael Palma, communications manager of World Vision Bangladesh, a non-government organisation.

Palma, who yesterday visited Mongla, said the locals are saying they lived through the cyclone of 1988 but it was no match to this cyclone. “The roaring wind was not as devastating as this one.”

The casualties could be much higher if not the local administration warned people about the imminent disaster, he observed.

As per the government count, 44 people died in Bagerhat. But unofficial sources put the number at 133, of which 90 were killed in Sharankhola upazila alone.

The volunteers and rescuers painted an even grimmer picture of the shocking event, which also left thousands injured. Chief Adviser Fakhruddin Ahmed too rushed to some southern districts in an effort to buck up the spirit of cyclone-victims.

But it will take weeks to assess the actual death toll, financial loss and days to reach relief to people who are forced to live overnight under the open sky, rescuers and volunteers said, almost in identical words.

People in lakhs are staying under the open sky with hardly any foods in their possession, thousand remained missing, embankments broke down in many areas, scores of livestock killed, and unknown number of persons was swept away by tidal surges.

However, the devastation could have been much higher if the cyclone, originally predicted to be heading for the shores of Orissa near Paradip, made landfall during the high tide hours at around 3:00am on Friday.

“Had the high tide and cyclone taken place at the same time the damage would have tripled,” said an expert.

According to the midnight update of the government, 177 were killed in Patuakhali, 134 in Pirojpur, 133 in Bagerhat, 78 in Barisal, 35 in Barguna, 32 in Jhlakathi, 25 in Gopalganj, 20 in Bhola, 15 in Shariatpur,12 in Khulna, 10 in Faridpur, four each in Chandpur and Dhaka, three in Sathkhira, one each in Laxmipur, Chittagong, and Jessore.

However, the government briefing in the afternoon stated 19 people were killed in Madaripur, two in Narayanganj, and one each in Noakhali and Chandpur.

full news