Events Calendar

« < February 2012 > »
S M T W T F S
29 30 31 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 1 2 3

CB Login

CB Online

None

Comments

Welcome to my site!
Bamboo! PDF Print E-mail
Written by T.A. Nguyen   
Saturday, 11 February 2012 14:27

Bamboo!

 

Stretched out along the Vietnam countryside

The bamboo, dark, green, immense

Swingings to the air, floating in the evening winds

Like the silky hair of a young girl.

 

Together we shared the happyness of growing

Day by day up till now.

Her song sang me to sleep.

And it is in my heart still

 

Then came the evil war

My beloved country was drowned in blood.

The war desolated her beauty,

Only ashes remain, nothing survived.

 

She lost man friends;

But you, bamboo, did not leave the country.

You held tight to the land,

You lived through the storm

You keep Vietnam green still.

 

I see you again in my memory

Bamboo!  My childhood friend

How should I ever forget?

I am so sorry that I left you!

 

T.A. Nguyen

March 16, 1983

To all the one I left behind!

 

Bookmark with:

Deli.cio.us    Digg    reddit    Facebook    StumbleUpon    Newsvine
 
Tiển Mẹ PDF Print E-mail
Written by T.A. Nguyen   
Friday, 23 December 2011 17:20

Ngàn hoa con tiển mẹ đi
Đường quê cát trắng râm ri biển gào
Mẹ đi mưa ướt hồn nào
Trời mưa thay tiếng rì rào cỏi tâm

Bồng lai ngây ngất hương trầm
Lời con khấn nguyện âm thầm mẹ hay
Đến miền cực lạc an thay
Vãng sanh cảnh thế duyên nay vẹn toàn

Tặng mẹ,
T.A. Nguyen
Sàigòn - 12/17/2011

Bookmark with:

Deli.cio.us    Digg    reddit    Facebook    StumbleUpon    Newsvine
 
NHỮNG BỆNH... VÔ DUYÊN! PDF Print E-mail
Written by T.A. Nguyen   
Monday, 03 January 2011 05:21

NHỮNG BỆNH... VÔ DUYÊN!

BS Đỗ Hồng Ngọc

Tuy già không phải là một bệnh nhưng già thì thường có bệnh.

Bệnh thì có bệnh nặng, bệnh nhẹ, bệnh có duyên và bệnh... vô duyên. Ai cũng biết thầy thuốc là người giúp ta chữa trị bệnh tật, vậy mà thầy thuốc cũng có thể gây bệnh cho ta, dù là ngoài ý muốn, cái đó gọi là bệnh do thầy thuốc gây ra (iatrogenic) mà theo GS. Phạm Khuê, một chuyên gia về Lão khoa, Chủ tịch Hội người cao tuổi Việt Nam thì

có đến một phần tư người già do thầy thuốc gây nên

Những bệnh... vô duyên còn có thể do chính mình, người thân trong gia đình, bạn bè,

hàng xóm, hoặc các nhân viên tâm lý xã hội gây ra nữa! Bà cô của một bác sĩ bạn tôi trên 80 tuổi kêu lúc nào trong người cũng nóng bức, miệng khô nên đã mua rễ tranh, mía lau, mã đề ngoài chợ về nấu "nước mát" uống. Mát đâu không thấy, thấy đi tiểu liên tục gây thêm tình trạng mất nước trong cơ thể, lại thấy nóng bức, thấy khô miệng, lại uống thêm "nước mát"!

Thì ra "rễ tranh, mía lau, mã đề" là những loại thuốc lợi tiểu (diuretics).

Một ông bác gầy còm nghe hàng xóm bày vẽ có loại tễ mập, bèn mua uống mấy cây. Mập thiệt! Nhưng người béo bệu, cơ thể bạc nhược! Thì ra, thuốc tễ đó chỉ là bột mì trộn với mật ong và Corticoil, một thứ thuốc uống vào lâu ngày gây hội chứng Cushing, ứ nước, làm mập bệu và gây ra vô số những tác dụng tai hại khác như giảm sức đề kháng, mọc lông, loãng xương, loét bao tử, cao huyết áp...

Ta cũng biết thuốc chữa đau khớp có thể gây loét dạ dày; thuốc điều trị cao huyết áp có

thể gây hạ huyết áp đột ngột; thuốc trị tiểu đường làm hạ đường huyết; thuốc uống cho đỡ bị đái són ở người già thì gây khô miệng, đỏ da, mờ mắt, chóng mặt...

Một đặc điểm sinh học của người cao tuổi là khả năng thích ứng dần kém đi. Hấp thu thuốc đã chậm mà đào thải cũng chậm. Tác dụng phụ của thuốc lại thiên hình vạn trạng, tùy từng người, từng lúc, có thuốc người này dùng thì tốt mà bày cho người khác không xong, uống vào bị phản ứng ngay.

Cho nên dùng thuốc ở người già phải dò dẫm trên từng trường hợp, giảm liều, giảm lượng,đắn đo tính toán trước sau, nào bệnh trước mắt, nào bệnh tiềm tàng; thuốc chữa được bệnh này nhưng có gây ra bệnh khác không, có làm bộc phát một bệnh cũ nào đó không, người bệnh ăn uống ra sao, tiêu tiểu ra sao và trạng thái tâm thần ra sao?

Người cao tuổi cũng thường hay tự ý gia giảm thuốc, tin lời bày vẽ, ai mách gì cũng nghe, gây tương tác thuốc lung tung rất dễ sinh ra nhiều bệnh... vô duyên đáng tiếc.

Ngày càng có nhiều máy móc xét nghiệm và một số người cao tuổi cũng thường muốn được xét nghiệm này nọ.

Tổ chức sức khỏe thế giới (WHO) cũng cảnh cáo hiện tượng over - investigation, "thăm dò quá mức cần thiết" này (Health of the Elderly, WHO, 1989).

Một số người cao tuổi được chăm sóc bảo bọc quá đáng, được làm xét nghiệm thăm dò, theo dõi liên tục làm cho người bệnh muốn.... hết bệnh cũng không được; không kể trong khi thăm dò, chọc hút, bơm tiêm, thụt tháo... không phải là không có nguy cơ.

Dĩ nhiên nếu có bệnh thì cần phải làm để có chẩn đoán chính xác và điều trị hiệu quả. Còn thăm dò chỉ để... thăm dò thì không nên. Các chuyên gia khuyên chỉ nên làm xét nghiệm cho người già khi nhằm để chẩn đoán một thứ bệnh có thể chữa được, có thể phục hồi được, có lợi cho người bệnh hoặc để chẩn đoán phân biệt tìm ra một bệnh có tiên lượng tốt hơn, điều trị có kết quả hơn, có lợi cho bệnh nhân và gia đình hơn mà thôi. Tóm lại,khi cần thiết lắm mới phải làm xét nghiệm và phải có chỉ định của bác sĩ.

Thế nhưng có thứ không phải là thuốc, không phải là thủ thuật gì cả mà vẫn có thể gây ra những bệnh vô duyên: đó là lời nói!

Có những lời nói gây hoang mang, lo lắng, làm mất ăn mất ngủ, gây kiêng cữ quá đáng làm cho tình trạng bệnh khó phục hồi hơn. Cái đó gọi là sự "dán nhãn" (labelling). Chẳng hạn như người không có chuyên môn, không đủ cơ sở khoa học chắc chắn mà "phán" cho một cái chẩn đoán kiểu như "nghi ung thư", "hơi bị lớn tim", hoặc một từ mơ hồ như "máu lộn mỡ, gan hơi nhiễm mỡ, viêm nhiễm phần phụ, rối loạn thần kinh thực vật"... hoặc "bị thư phù, bị người cõi trên nhập..." đều đem lại những kết quả tai hại không thể ngờ được!

Ngay cả bị dán nhãn là già cả, già nua, già yếu, mất sức rồi bị ép phải nằm yên một chỗ, lúc nào cũng có người nâng đỡ chăm sóc thì sẽ ngày càng lệ thuộc, ngày càng suy nhược, mau loãng xương, bắp cơ thoái hóa, cứng khớp nhanh.

Đáng sợ hơn cả là bị ép phải vào nằm viện, nằm nhà thương, nhà dưỡng lão, nhà nghỉ mất sức... khi vẫn còn có thể tự lo lấy được. Thật ra đây chỉ là giải pháp cuối cùng vì một khi đã vào các cơ sở này rồi thì không hy vọng gì trở lại đời sống bình thường được nữa vì càng ngày càng thụ động, ỷ lại, lệ thuộc, suy sụp.

Các cơ quan chăm sóc cho người già thực ra rất cần thiết, miễn là phải giữ một số nguyên

tắc như bảo đảm bảo sự riêng tư, tôn trọng cá nhân, giúp tự chủ, tự quản, và tạo nhiều cơ

hội cho họ tham gia sinh hoạt phù hợp với sở thích và sức khỏe.

Tóm lại, không nên để người cao tuổi mắc thêm những bệnh.... vô duyên!

BS Đỗ Hồng Ngọc

Bookmark with:

Deli.cio.us    Digg    reddit    Facebook    StumbleUpon    Newsvine
Last Updated on Monday, 03 January 2011 16:03
 
RemoteService a simple client to test your Restful and SOAP services PDF Print E-mail
Written by T.A. Nguyen   
Wednesday, 11 May 2011 13:24

Random thought...

As Java growth, so does the Web Service spaces along with the complexity of the services it can handle.  With Axis/Axis2 then come along CXF many of these implementation are wonderful in focusing on how to make it easier for developer to create webservices.  I am all for it, and thankful for those who contribute to make it better.  SoapUI a recent addition to the slewth of tool that help with the web-services space, great tool, a must check and use if you use web services day in day out.

As an educator, I often being asked about the basic building block behind these.  One of my favorist is the simple http/https implementation.  Yes, it all started when the world wild web protocol started....

So, I find myself refer back to my basic http/s get/post code that had been develop a decade ago... and amazingly, it still work, not only that it also serve as great example for my student to understanding the building block behind it all.

 

Here are my 2 simple classes that I been using for a while:

 

// RemoteService 
package org.cnci.service.util.client;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;

// There are several flavors of these 
import org.apache.axis.encoding.Base64;

/**
 * provide as is, no warranty.
 * @author T.A. Nguyen
 * ta{at}cnci{dot}org
 */
public class RemoteService {

   /**
    * Simple remote get/post client if data present, it will do a post, if user
    * present it will place it in the Authorization header
    * 
    * @throws RemoteServiceException
    **/
   public static String postService(String url, String data, String user) 
      throws RemoteServiceException 
   {
      return remoteService(url, data, user, null, null);
   }

   public static String getService(String getUrl, String user, 
                 String password, String encoding) throws RemoteServiceException 
   {
      return remoteService(getUrl, null, user, password, encoding);
   }

   public static String getService(String getUrl, String user) 
           throws RemoteServiceException 
   {
      return remoteService(getUrl, null, user, null, null);
   }

   public static String remoteService(String getUrl, String data, String user, 
      String password, String encoding) throws RemoteServiceException 
   {
      OutputStreamWriter wr = null;
      BufferedReader rd = null;
      String result = null;

      try {
         StringBuffer buff = new StringBuffer();
         URL url = new URL(getUrl);
         URLConnection uc = url.openConnection();
         uc.setRequestProperty("User-Agent", "TAzilla/4.0");
         
         /* ----- encoding, we use "identity" for authentication -------
          * Accept-Encoding: compress, gzip
          * Accept-Encoding:
          * Accept-Encoding: *
          * Accept-Encoding: compress;q=0.5, gzip;q=1.0
          * Accept-Encoding: gzip;q=1.0, identity; q=0.5, *;q=0
          */
         if (encoding == null) encoding = "identity";
         uc.setRequestProperty("Accept-Encoding", encoding);
         if (user != null) {
            String auth = user;
            if (password != null) {
               String encode = user + ":" + password;
               auth = "Basic " + Base64.encode(encode.getBytes());
            }
            uc.setRequestProperty("Authorization", auth);
         }
         if (data != null) {
            uc.setDoOutput(true);
            wr = new OutputStreamWriter(uc.getOutputStream());
            wr.write(data);
            wr.flush();
         }

         // Get the response
         rd = new BufferedReader(new InputStreamReader(uc.getInputStream()));
         String line=null;
         while ((line = rd.readLine()) != null) {
            buff.append(line + "\n");
         }
         result = buff.toString();

         if (result.indexOf("Exception: ") > 0) {
            throw new RemoteServiceException(result);
         }
      } catch (Exception e) {
         throw new RemoteServiceException(e.getMessage(), e);
      } finally {
         try {
            if (wr != null) wr.close();
            if (rd != null) rd.close();
         } catch (Exception e) {
            e.printStackTrace();
         }
      }

      return result;
   }

   /**
    * test codes.... 
    * @param args
    */
   public static void main(String[] args) {
      try {
         String url = "http://localhost:9000/service/MyRestfulService?getPerson=5";
         String data = remoteService(url, null, "myUserId", "secret", "identity");
         System.out.println("data:>>" + data);
      } catch (RemoteServiceException e) {
         e.printStackTrace();
      }
   }
}


// RemoteServiceException 
package org.cnci.service.util.client;

/**
 * provide as is, no warranty.
 * @author T.A. Nguyen
 * ta{at}cnci{dot}org
 */
public class RemoteServiceException extends Exception {
   private static final long serialVersionUID = 1L;

   public RemoteServiceException() {
   }

   public RemoteServiceException(String msg) {
      super(msg);
   }

   public RemoteServiceException(Throwable e) {
      super(e);
   }

   public RemoteServiceException(String msg, Throwable e) {
      super(msg, e);
   }
}

And as many of the https protocol, there are invalid/expired certs that show up more often that us developers like to see. The problem is a valid certificate cost yearly fee, not sure why? And so to enable the security cost, most of the smaller (mom and pop) web sites and services just use the default or expired certs, this cause the problem to the Java space of end up enforcing to a failed certificate. Sun, provided a neat tool called InstallCert.java by Sun Micro System. Just download and follow these steps

  • javac InstallCert.java
  • java InstallCert yoursslserver:sslport

For a full solution refer to Sthyo blogs.

Bookmark with:

Deli.cio.us    Digg    reddit    Facebook    StumbleUpon    Newsvine
Last Updated on Wednesday, 11 May 2011 15:15
 
Basic Java Socket Programming: Creating a Basic Chat Service PDF Print E-mail
Written by T.A. Nguyen   
Friday, 17 September 2010 01:24

Welcome to JavaLand.  Here I will attempt to explain about the basic Java socket programming by creating a simple client/server Chat project.

 

The basic idea for the server is as follow:

 

 

ChatServer.java

  • Listen on a port until a client connect using the SocketServer.accept()
  • Once, connected, create a ChatService and have it handle that connection in a separate thread
  • Now, go back to listening mode again for next connection.
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * Basic Chat Server (BChat)
 * @author TA Nguyen
 */
public class ChatServer
{
  // Defines the port that this server will listen on
   final int SBAP_PORT = 80;
   
   public static void main(String[] args) throws IOException
   {
       // Create a new mediator
       Mediator mediator = new Mediator();

       // Create a new server object
       ServerSocket server = new ServerSocket(SBAP_PORT);
       System.out.println("");
       System.out.println("Press CTRL+C to terminate.");
       System.out.println("Waiting for clients to connect...");

       /**
        * Main loop of the application.
        */
       while (true) {
	       // wait for client to connect
           Socket socket = server.accept();
           System.out.println("Client connected.");

           // ok, connected, 
           //now create ChatService to handle this connection
           ChatService service = new ChatService(socket, mediator);

           // tell the JVM to run it in a thread
           Thread thread = new Thread(service);
           thread.start();
		   
           // now, we go back to wait for next connection.
       }
   }
}

 

ChatService.java

  • Listen for incomming message and tell the Mediator to send it to all connecting clients
import java.io.IOException;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;

/**
 * ChatService: Executes BChat commands from a socket.
 * @author TA Nguyen
 */
public class ChatService implements Runnable
{
    private Socket socket;
    private Scanner in;
    private Mediator mediator;
    private PrintWriter writer;


    /**
     * Constructs a service object that processes commands
     * from a socket utilizing the mediator service.
     * @param socket the Socket
     * @param mediator the Mediator
     */
    public ChatService(Socket socket, Mediator mediator) {
        this.socket = socket;
        mediator = mediator;
    }


    /**
     * Add new i/o services and call doService()
     * which performs the primary chat functions.
     *
     * When doService() returns, cleans up and shuts down the thread.
     */
    public void run() {
        try {
            try {
                in = new Scanner(socket.getInputStream());
                writer = new PrintWriter(socket.getOutputStream());
                mediator.add(writer);
                doService();
            } finally {
                mediator.remove(writer);
                socket.close();
                System.out.println("Client disconnected.");
            }
        } catch (IOException exception) {
            System.out.println("Serverside error occured.");
            exception.printStackTrace();
        }
    }


    /**
     * Prints every command received.  If the user enters "QUIT",
     * then the thread terminates.
     */
    public void doService() throws IOException {
        while (true) {
            if (!in.hasNext()) {
                return;
            }

            String command = in.nextLine();
            if (command.equals("QUIT")) {
                return;
            } else {
                executeCommand(command);
            }
        }
    }


    /**
     * Executes a single command.
     * @param command the command to execute
     */
    public void executeCommand(String command) {
        mediator.writeMessage(command);
    }
}

 

Mediator.java

  • keep track of all the outgoing socket (clients)
  • loop and display received message to all clients
import java.io.PrintWriter;
import java.util.LinkedList;

/**
 * Mediator:
 * 1. Stores and maintains a list of the clients 
 *    that are connected to the server.
 * 2. Provide a relays of received messages 
 *    to all connected clients.
 *
 * This list must be synchronized across all threads 
 * to maintain access to each connection.
 *
 * @author TA Nguyen
 */
public class Mediator {
    private LinkedList connections;


    /**
     * Constructor creates the list that maintains the connections
     */
    public Mediator() {
        connections = new LinkedList();
    }


    /**
     * Accepts a message and sends it out to all of the clients
     * @param Message the message to broadcast to all connections
     */
    public void writeMessage(String message) {
        System.out.println("Recieved: " + message);
        for (PrintWriter out : connections) {
            out.println(message);
            out.flush();
        }
    }


    /**
     * Adds a new connection
     * @param Out the new connection to add to the list
     */
    public void add(PrintWriter out) {
        connections.add(out);
    }


    /**
     * Removes a connection
     * @param Out the connection to remove
     */
    public void remove(PrintWriter out) {
        connections.remove(out);
    }
}

 

ChatClient.java

  • Establish a connection to the ChatServer
  • Create a DisplayService and run it in a thread to handle server income message
  • Loop and wait for user to enter message, then send it to the server.
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;


/**
 * Basic Chat Client (BChat)
 *
 * @author TA Nguyen
 */
public class ChatClient 
{
  // The port to connect to
    private static final int BCHAT_PORT = 80;
    private static final String BCHAT_IP = "localhost";
    
    public static void main(String[] args) throws IOException {

        // Create the socket and connect to the predefined server:port
        Socket socket = new Socket(WTSCS_IP, WTSCS_PORT);

        // Create the input and output streams, from this socket connection
        InputStream instream = socket.getInputStream();
        OutputStream outstream = socket.getOutputStream();

        // Create a scanner and print writer for local i/o
        Scanner socketIn = new Scanner(instream);
        PrintWriter socketOut = new PrintWriter(outstream);
        Scanner keyIn = new Scanner(System.in);

        // Define the display service and instruct it to listen 
        // to the socket input stream, display all messages the come in.
        DisplayService service = new DisplayService(socketIn);

        // Well, do it (display) in a thread so that 
        // we can type with out being blocked by in comming messages.
        Thread thread = new Thread(service);
        thread.start();

        // first, get the client name and remember it.
        System.out.print("Enter your name: ");
        String name = keyIn.nextLine();

        while (true) {
            // read a line of message from (system/console) input stream 
            String line = keyIn.nextLine();
            
            // write the message with client name to the socket output stream
            socketOut.println(name + ": " + line);
            socketOut.flush();
            
            // if the last message is "QUIT" then stop.
            if ("QUIT".equals(line)) {
                break;
            }
        }
        socket.close();
    }
}

 

DisplayService.java

  • Wait for message from the server and display it to the console.
import java.util.Scanner;

/**
 * DisplayService: 
 * Displays all input received.
 *
 * @author TA Nguyen
 */
public class DisplayService implements Runnable {
    private Scanner scanner;
    
    
    /**
     * Constructor receives a scanner object for i/o operations.
     *
     * @param scanner The source to read input from
     */
    public DisplayService(Scanner scanner) {
        this.scanner = scanner;
    }
    
    
    /**
     * Get input from the scanner and print the line to the output.
     */
    public void run() {
        while (true) {
            if(scanner.hasNext()) {
                String line = scanner.nextLine();
                System.out.println(line);
            } else {
                return;
            }
        }
    }
}

 

Now, that you have the basic understanding of client/server using socket and a working chat client/server, I challence you to take this to a step further and add a gui to the client, along with the Avatar image for the client.  Hint you can use the java serialization to send complete java object over socket.

 

Note: this demo was originally written as part of the class excercise for CSC-251 class that I teach at WakeTech.edu

Enjoy,

T.A. Nguyen

 

Bookmark with:

Deli.cio.us    Digg    reddit    Facebook    StumbleUpon    Newsvine
Last Updated on Wednesday, 11 May 2011 15:26
 
<< Start < Prev 1 2 3 4 5 6 7 8 Next > End >>

Page 1 of 8
T.A. Nguyen, Powered by Joomla! and VNSAB.com