顯示具有 programming 標籤的文章。 顯示所有文章
顯示具有 programming 標籤的文章。 顯示所有文章

2014-04-17

Dia 的 database 圖表轉換成 MySQL

Dia 是一種跨平台、放開資源的流程圖製作軟件,能繪製多種不同類型的圖表如資料庫圖表、類別圖表等
以 XML 或 GZip 壓縮後的 XML 作為文件保存格式,方便於其他程式語言分析

2013-06-11

使用 PHP 分析 User Agent

現在不少網頁都為了流動裝置編寫了專為流動裝置的瀏覽器而製作的網頁
當使用流動裝置傳取桌面版的網頁時,會自動移至流動裝置版的分頁
判斷瀏覽器是否流動裝置便需要先觀察 User Agent……

2012-11-16

Shell Script 誤報問題

部分 Linux 發行版,為了提升啟動速度將,以 /bin/dash 執行
導致部分 /bin/bash 的功能無法使用

2012-11-10

Shell Script 功能傳回值

Shell Script 是一種簡單,但功能強大的程序
經常出現於 Unix, Linux, BSD 系統,部分 Mac OS 亦會使用 Shell Script 進行設定
相比 Windows 的 Batch,Shell Script 更顯得重要

2012-07-13

Linux 簡單檔案批次設定權限

Linux 是一種對於檔案管理非常嚴格的系統,雖然嚴格,但設定上卻很簡單
透過 +/- r, w, x 或 八進制數值 控制權限
普遍地,利用
chmod -R 0777 /var/www
便可以將整個 /var/www 改變成 0777 權限

2012-07-03

Linux 簡單檔案批次重新命名

為了電腦檔案易於保管,不少情況都會使用數值來指定檔案名來限制檔案排列的次序
Windows 有一種簡單的方法,只需要選取需要的檔案,於第一個檔案重新命名,輸入指定的文字
就會將選取需要的檔案順次序改名,但這種改名方法的結果就不太理想
當然 Windows 上還有其他批次重新命名軟件
Linux 上亦有一種稱為 rename 的指令,一次過將大量檔案重新命名
但要讓檔案順著某個編號開始排列,rename 又好像不太適合

2012-04-19

XML I18N

不少電腦語言都各自有自己專用的 I18N (Internationalization) 寫法,例如
PHP 通常會用 gettext 或 intl
Java, JSP, Servlet 通常會用 Locale + ResourceBundle 配合 Properties file
另外還有各種 Framework 都各自有一套 I18N 寫法

但是若果由一種 I18N 寫法至另一種 I18N 寫法顯然是需要一點點時間學習……

2011-12-29

在 MySQL 計算年齡 (Calculating Age in MySQL)

儲存個人資料時,由於年齡是一種跟隨時間而變動的資料,因此合理情況上不會儲存年齡
取而代之會以出生日期為儲存資料,便可以透過日期相減計算出年齡
When recording an user data, age is an dynamic data. Generally, you should not store it.
So you store the date of birth, then calculating the age from date of birth.

2011-11-21

Windows Live SkyDrive 的批次下載問題 2 (Batch download files in Windows Live SkyDrive 2)

自從 Microsoft 更新了 Windows Live SkyDrive 後
每次上載的檔案由每個 50MB 增加至每個 100MB,而下載速度相當快,平均有 2~3Mbps
但上載速度便不敢恭維了,3 個 100MB 檔案便會發生 Timeout,看來 SkyDrive 仍有進步空間
但在此文章,主要不是討論這些問題

2011-10-16

批次處理程序的字串功能 (Function of String in Batch)

Windows 擁有優良的界面控制,但如果涉及大量重覆性的運作
使用界面並不合適,因此便需要使用批次處理程序
Windows provides a good quality of GUI, but, if you would like to do a large number of repetitive operations,
GUI is not appropriate, so we need to use the batch process

2011-06-29

利用 Java 發送 HTTP POST 請求 (Using Java to send HTTP Request with POST method)

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.net.URLConnection;

2011-02-24

使用 Java 上載檔案至 FTP 伺服器 (Use Java to upload file to FTP Server)

import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import sun.net.TelnetOutputStream;
import sun.net.ftp.FtpClient;

2010-11-27

PHP UTF-8 編碼與 session 及 header 問題 (Solving BOM of UTF-8 File Encoding problem with PHP session and header)

網絡上不少跨語言網頁大部分都是以 UTF-8 作為編碼
但利用 UTF-8 編碼編寫 PHP 文件使用到 session 及 header 時便會發生問題
UTF-8 編碼的文件會在文件檔頭加上 3個bytes 的資料,這 3個bytes 稱為 BOM - Byte Order Mark
在標準制式下 UTF-8 的這 3個bytes 分別是:
第一個byte - 0xef
第二個byte - 0xbb
第三個byte - 0xbf
UTF-8 is a popular File Encoding on the internet.
However, when we use UTF-8 with PHP using session and header there are some error occurs.
UTF-8 file has 3 bytes of data at the beginning of file, this 3 bytes called BOM - Byte Order Mark
The standard of UTF-8 file of this 3 bytes is:
1st byte - 0xef
2nd byte - 0xbb
3rd byte - 0xbf

2010-11-17

Windows VISTA / Windows 7 不能使用 VBScript 的 CommanDialog (VBScript CommonDialog in Windows VISTA and Windows 7)

不少人在 Windows 處理簡單的程序時,往往會用到 VBScript
而使用 VBScript 涉及檔案存取時不少人都會想到使用 File Dialog 讓使用者有一個具 GUI 的檔案選擇工具
VBScript is a light, useful programming language (script) in Windows OS
We can write a VBS with notepad or any text editor
We always select a file with File Dialog
File Dialog is a user-friendly GUI for user to select a specific file

2010-10-18

利用 PEAR 製作 Excel 檔案 (Use PEAR to create an Excel file)

PEAR 為 PHP Extension and Application Repository 的簡稱
是一種以 PHP 物件導向的設計的程式庫
PEAR is the abbreviation of PHP Extension and Application Repository

2010-06-03

利用 Java 將 Zip 格式解壓縮 (Use Java to decompress a ZIP file)

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public static void decompress(File source, File destination) throws IOException{
    if (!destination.exists() || destination.isDirectory()){
        destination.mkdirs();
        ZipInputStream zis = new ZipInputStream(new FileInputStream(source));
        byte[] buffer = new byte[1024];
        for (ZipEntry zip; (zip = zis.getNextEntry()) != null;){
            File file = new File(destination, zip.getName());
            if (zip.isDirectory()){
                file.mkdirs();
            } else {
                FileOutputStream fos = new FileOutputStream(file);
                for (int length; (length = zis.read(buffer)) > 0;){
                    fos.write(buffer, 0, length);
                }
                fos.close();
            }
            zis.closeEntry();
        }
        zis.close();
    }
}

利用 Java 將檔案與資料夾壓縮成 Zip 格式 (Use Java to compress file(s) or directory(ies) as ZIP format)

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.Deflater;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;

public static void compress(File source, File destination) throws IOException{
    compress(source, destination, null, Deflater.DEFAULT_COMPRESSION);
}

public static void compress(File source, File destination, String comment, int level) throws IOException{
    ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(destination));
    zos.setComment(comment);
    zos.setLevel(level);
    compress(zos, source.getParent(), source);
    zos.flush();
    zos.close();
}

private static void compress(ZipOutputStream zos, String rootpath, File source) throws IOException{
    String filename = source.toString().substring(rootpath.length() + 1);
    if (source.isFile()){
        zos.putNextEntry(new ZipEntry(filename));
        FileInputStream fis = new FileInputStream(source);
        byte[] buffer = new byte[1024];
        for (int length; (length = fis.read(buffer)) > 0;){
            zos.write(buffer, 0, length);
        }
        fis.close();
        zos.closeEntry();
    } else if (source.isDirectory()){
        zos.putNextEntry(new ZipEntry(filename + "/"));
        zos.closeEntry();
        File[] files = source.listFiles();
        for (File file : files){
            compress(zos, rootpath, file);
        }
    }
}