星期日, 7月 31, 2011

實作多國語言蒐集

jQuery plugin
jQuery Localisation
[jQ]jQuery Localisation 1.0.5
jQuery i18n Plugin

星期四, 7月 28, 2011

[C#] HttpWebRequest request limitation

最近實作多執行緒上傳檔案的測試工具時,
發現不管執行幾個執行緒同時只會有二個連線數存在。
這是.net預設的連線數,透過以下設定即可。
ServicePointManager.DefaultConnectionLimit = 10;
網路上有人建議最大連線數不要超過1024,最好的效果是512。
另外也可以從app.config來設定最大連線數

硬碟單位換算


單位換算問題:適用於各語言的實作XD
10 MB = 10485760 Bytes

Explanation: 10 MB = 10*1024 KB = 10*1024*1024 Bytes = 10485760 Bytes

As we have,

1 KB = 1024 Bytes

1 MB = 1024 KB


Read more: 

星期二, 7月 19, 2011

[jQuery Plugin] 第一次用jQuery Validator就上手

常用到的客戶端的表單欄位驗證,在此簡單記錄一下:
本測試使用v1.8.1

[Java] Resize Image as JPG

簡單的影像Resize程式

public class ResizeImage {

 static public byte[] resizeImageAsJPG(byte[] pImageData, int pMaxWidth)
   throws IOException {

  // Create an ImageIcon from the input image byte[]
  ImageIcon imageIcon = new ImageIcon(pImageData);
  int width = imageIcon.getIconWidth();
  int height = imageIcon.getIconHeight();

  // If the image is larger than the max width, we need to resize it
  if (pMaxWidth > 0 && width > pMaxWidth) {
   // Determine the shrink ratio
   double ratio = (double) pMaxWidth / imageIcon.getIconWidth();
   height = (int) (imageIcon.getIconHeight() * ratio);
   width = pMaxWidth;
  }

  // Create a new empty image buffer to "draw" the resized image into
  BufferedImage bufferedResizedImage = new BufferedImage(width, height,BufferedImage.SCALE_SMOOTH);
  // Create a Graphics object to do the "drawing"
  Graphics2D g2d = bufferedResizedImage.createGraphics();
  g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BICUBIC);
  // Draw the resized image
  g2d.drawImage(imageIcon.getImage(), 0, 0, width, height, null);
  g2d.dispose();
  // Now our buffered image is ready
  // Encode it as a JPEG
  ByteArrayOutputStream encoderOutputStream = new ByteArrayOutputStream();
  JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(encoderOutputStream);
  encoder.encode(bufferedResizedImage);
  byte[] resizedImageByteArray = encoderOutputStream.toByteArray();
  return resizedImageByteArray;
 }
}

[jQuery] File upload using AJAX form

最近使用jQuery Form Plug & jQuery File Upload上傳檔案,如果將Server Response的content-type設定application/json的話,因為元件上傳使用iframe來達到ajax form的效果,因此在Firefox和IE瀏覽器會跳出下載的Dialog。如果要回傳json格式來交換資料的話,只能將content-type設定text/plain或text/html,等接到ajax callback事件後,再將json的字串利用JSON.parser()轉換到json object即可。


後紀:使用text/plain會被多加pre element進去

Reference:Frequently Asked Questions
Internet Explorer prompting to download a file after the upload completes

The file upload plugin makes use of an Iframe Transport module for browsers like Microsoft Internet Explorer and Opera, which do not yet supportXHR file uploads.
Iframe based uploads require a Content-type of text/plain or text/html for the JSON response - they will show an undesired download dialog if the iframe response is set to application/json.
Please have a look at the Content-Type Negotiation section of the Setup instructions.

星期五, 7月 15, 2011

[C#] Settings

To Write and Persist User Settings at Run Time
  1. Access the user setting and assign it a new value, as shown in the following example:
    Properties.Settings.Default.myColor = Color.AliceBlue;
    
  2. If you want to persist changes to user settings between application sessions, call the Savemethod, as shown in the following code:
    Properties.Settings.Default.Save();

星期一, 7月 11, 2011

[Java] Keytool 相關蒐集

[Java] 實作HTTPS Request

最近的專案為了確保網路資料傳輸的安全性,使用了SSL來加密,
原本實作的RESTful Client(Java HttpsURLConnection)模擬request時,伺服器回應了以下錯誤:

javax.servlet.ServletException: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
 com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:418)
 com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
 com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

Google了一下找到了這篇文章:

其他你感興趣的文章

Related Posts with Thumbnails