Archive

Archive for มกราคม, 2009

เรื่องของ 2D barcode สำหรับ Nokia

มกราคม 23rd, 2009

http://mobilecodes.nokia.com/index.htm

เป็นเว็บสำหรับการสร้าง 2d-Barcode ครับ สำหรับบางรุ่นของ nokia

MOBILE

php resize รูปภาพ

มกราคม 14th, 2009

ส่วนของการเรียกใช้งาน

<? 
// see online : http://kentung.f2o.org/scripts/thumbnail/sample.php 
include_once(“resize.php”); 
$thumb=new thumbnail(“/www/shiegege.jpg”); // prepare to generate “shiegege.jpg” in directory “/www” 
$thumb->size_width(100);           // set width for thumbnail with 100 pixels 
$thumb->show();                   // show my thumbnail 
$thumb->save(“/www/thumb/huhu.jpg”);       // save my  thumbnail to file “huhu.jpg” in directory “/www/thumb 
?>

 

ส่วนของคลาส(resize.php)

<? 
############################################## 
# Shiege Iseng Resize Class 
# 11 March 2003 
# shiegege_at_yahoo.com 
# View Demo : 
#   http://shiege.com/scripts/thumbnail/ 
/*############################################ 
Sample : 
$thumb=new thumbnail(”./shiegege.jpg”);            // generate image_file, set filename to resize 
$thumb->size_width(100);                // set width for thumbnail, or 
$thumb->size_height(300);                // set height for thumbnail, or 
$thumb->size_auto(200);                    // set the biggest width or height for thumbnail 
$thumb->jpeg_quality(75);                // [OPTIONAL] set quality for jpeg only (0 - 100) (worst - best), default = 75 
$thumb->show();                        // show your thumbnail 
$thumb->save(”./huhu.jpg”);                // save your thumbnail to file 
———————————————- 
Note : 
- GD must Enabled 
- Autodetect file extension (.jpg/jpeg, .png, .gif, .wbmp) 
  but some server can’t generate .gif / .wbmp file types 
- If your GD not support ‘ImageCreateTrueColor’ function, 
  change one line from ‘ImageCreateTrueColor’ to ‘ImageCreate’ 
  (the position in ’show’ and ’save’ function) 
*/############################################ 

class thumbnail 

    var 
$img

    function thumbnail($imgfile
    { 
        
//detect image format 
        
$this->img["format"]=ereg_replace(“.*\.(.*)$”,“\\1″,$imgfile); 
        
$this->img["format"]=strtoupper($this->img["format"]); 
        if (
$this->img["format"]==“JPG” || $this->img["format"]==“JPEG”) { 
            
//JPEG 
            
$this->img["format"]=“JPEG”
            
$this->img["src"] = ImageCreateFromJPEG ($imgfile); 
        } elseif (
$this->img["format"]==“PNG”) { 
            
//PNG 
            
$this->img["format"]=“PNG”
            
$this->img["src"] = ImageCreateFromPNG ($imgfile); 
        } elseif (
$this->img["format"]==“GIF”) { 
            
//GIF 
            
$this->img["format"]=“GIF”
            
$this->img["src"] = ImageCreateFromGIF ($imgfile); 
        } elseif (
$this->img["format"]==“WBMP”) { 
            
//WBMP 
            
$this->img["format"]=“WBMP”
            
$this->img["src"] = ImageCreateFromWBMP ($imgfile); 
        } else { 
            
//DEFAULT 
            
echo “Not Supported File”
            exit(); 
        } 
        @
$this->img["lebar"] = imagesx($this->img["src"]); 
        @
$this->img["tinggi"] = imagesy($this->img["src"]); 
        
//default quality jpeg 
        
$this->img["quality"]=75
    } 

    function size_height($size=100
    { 
        
//height 
        
$this->img["tinggi_thumb"]=$size
        @
$this->img["lebar_thumb"] = ($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"]; 
    } 

    function size_width($size=100
    { 
        
//width 
        
$this->img["lebar_thumb"]=$size
        @
$this->img["tinggi_thumb"] = ($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"]; 
    } 

    function size_auto($size=100
    { 
        
//size 
        
if ($this->img["lebar"]>=$this->img["tinggi"]) { 
            
$this->img["lebar_thumb"]=$size
            @
$this->img["tinggi_thumb"] = ($this->img["lebar_thumb"]/$this->img["lebar"])*$this->img["tinggi"]; 
        } else { 
            
$this->img["tinggi_thumb"]=$size
            @
$this->img["lebar_thumb"] = ($this->img["tinggi_thumb"]/$this->img["tinggi"])*$this->img["lebar"]; 
        } 
    } 

    function jpeg_quality($quality=75
    { 
        
//jpeg quality 
        
$this->img["quality"]=$quality
    } 

    function show() 
    { 
        
//show thumb 
        
@Header(“Content-Type: image/”.$this->img["format"]); 

        /* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/ 
        
$this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]); 
            @
imagecopyresized ($this->img["des"], $this->img["src"], 0000$this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]); 

        if ($this->img["format"]==“JPG” || $this->img["format"]==“JPEG”) { 
            
//JPEG 
            
imageJPEG($this->img["des"],“”,$this->img["quality"]); 
        } elseif (
$this->img["format"]==“PNG”) { 
            
//PNG 
            
imagePNG($this->img["des"]); 
        } elseif (
$this->img["format"]==“GIF”) { 
            
//GIF 
            
imageGIF($this->img["des"]); 
        } elseif (
$this->img["format"]==“WBMP”) { 
            
//WBMP 
            
imageWBMP($this->img["des"]); 
        } 
    } 

    function save($save=“”
    { 
        
//save thumb 
        
if (empty($save)) $save=strtolower(“./thumb.”.$this->img["format"]); 
        
/* change ImageCreateTrueColor to ImageCreate if your GD not supported ImageCreateTrueColor function*/ 
        
$this->img["des"] = ImageCreateTrueColor($this->img["lebar_thumb"],$this->img["tinggi_thumb"]); 
            @
imagecopyresized ($this->img["des"], $this->img["src"], 0000$this->img["lebar_thumb"], $this->img["tinggi_thumb"], $this->img["lebar"], $this->img["tinggi"]); 

        if ($this->img["format"]==“JPG” || $this->img["format"]==“JPEG”) { 
            
//JPEG 
            
imageJPEG($this->img["des"],“$save”,$this->img["quality"]); 
        } elseif (
$this->img["format"]==“PNG”) { 
            
//PNG 
            
imagePNG($this->img["des"],“$save”); 
        } elseif (
$this->img["format"]==“GIF”) { 
            
//GIF 
            
imageGIF($this->img["des"],“$save”); 
        } elseif (
$this->img["format"]==“WBMP”) { 
            
//WBMP 
            
imageWBMP($this->img["des"],“$save”); 
        } 
    } 

?>

PHP

ผลการทดสอบ Mysql Connector/NET ติดต่อกับ Mono-Project

มกราคม 13th, 2009

จากการทดสอบโหลด Mysql Connector/NET มาใช้กับ mono ซึ่งรุ่นที่ตั้ดตั้ง รองรับ .net framework 1,2
โ ดยโหลด Mysql Connector/NET จาก

http://dev.mysql.com/downloads/connector/

รุ่นที่ทดสอบ ได้แก่

  • mysql-connector-net-1.0.10
  • mysql-connector-net-5.0.9
  • mysql-connector-net-5.1.7
  • mysql-connector-net-5.2.5
โดยในการทดสอบผมใช้ mono รุ่น
# mono -V
Mono JIT compiler version 1.2.4 (tarball)
Copyright (C) 2002-2007 Novell, Inc and Contributors. www.mono-project.com
        TLS:           __thread
        GC:            Included Boehm (with typed GC)
        SIGSEGV:       normal
        Architecture:  amd64
        Disabled:      none
ผลที่ได้คือเ มื่อใช้ mysql-connector-net-1.0.10 แล้วจะไม่พบอาการโหลดข้อมูลแล้วค้าง แบบรุ่นใหม่ๆ จึงไม่น่าจะแปลกใจหากใครใช้รุ่นอื่น กับ mono แล้วจะเกิดปัญหาขึ้นได้

Linux, OpenSource

คำสั่งตรวจสอบพื้นที่ Quota

มกราคม 12th, 2009

ตัวอย่างการกำหนด โควต้า

เช่นต้องการจำกัดผู้ใช้ชื่อ myuser
มีพื้นที่ไม่เกิน 200000 blocks(200 Mbytes) และ/หรือ 1000 inodes(แฟ้ม)
โดยเริ่มเตือนที่ 160000 blocks(160 Mbytes) และ/หรือ 800 inodes ด้วยตัวอย่างคำสั่ง
#setquota -u myuser 160000 200000 800 1000 -a

 

คำสั่งตรวจสอบพื้นที่ Quota

# quota -u dd26_ktlogic.com

# quota -g web26

Disk quotas for group web26 (gid 10026):

     Filesystem  blocks   quota   limit   grace   files   quota   limit   grace

      /dev/sda5   25156  512000  513024            4382       0       0

ค่าของ blocks คือจำนวนพื้นที่ที่ถูกใช้ไป (นับเป็น block)

ค่าของ files คือจำนวนพื้นที่ที่ถูกใช้ไป (นับเป็น file)

quota คือค่าที่จะมีการแจ้งเดือน เมื่อเกินค่าที่ตั้งไว้

limit คือค่าที่ห้ามเกินไปกว่านี้

 

การใช้ quota จะไม่มีการ update พื้นที่ให้อัตโนมัติครับ ต้องมีการทำ script เอาเอง เช่น

/etc/cron.daily/quota-check มีข้อมูลดังนี้
#!/bin/sh
/sbin/quotaoff -a
/sbin/quotacheck -vagum -a
/sbin/quotaon -a

Linux

ทดสอบ คอมไ ฟล์ และใช้งาน Mono (บน CentOS linux)

มกราคม 11th, 2009

จะเป็นการทดสอบสร้างโปรแกรมง่ายๆครับ และทดสอบ run เพื่อแสดงข้อความง่ายๆ

 

[root@ns1 test_mono]# echo ‘class Hello{static void Main(){System.Console.Write(”Sourcecode.in.th\n”);}}’ >> program.cs

[root@ns1 test_mono]# mcs program.cs

[root@ns1 test_mono]# mono program.exe

Sourcecode.in.th

[root@ns1 test_mono]#

C#, Linux, OpenSource

ติดตั้ง Mono (.net บน Linux) บน CentOS 5

มกราคม 11th, 2009

ติดตั้งผ่านคำสั่ง yum ครับ

#yum groupinstall Mono

#yum install xsp

#yum install mod_mono

 

ตรวจสอบว่าที่ /etc/httpd/conf.d พบไฟล์ mod_mono.conf หรือไม่ครับ หากพบไฟล์ ก็แปลว่าได้ทำการติดตั้ง mod_mono เป็นที่เรียบร้อย

ต่อมาทำการ restart apache 

#/etc/rc.d/init.d/httpd restart

ตรวจสอบ process ของ mono ด้วยคำสั่ง

#ps -ef |grep mono

ควรจะมีรายการของ mono ทั้ง framework 1 และ 2 ดังตัวอย่าง

[root@ns1 web]# ps -ef |grep mono

apache   21098     1  0 16:44 ?        00:00:00 /usr/bin/mono /usr/lib64/mono/1.0/mod-mono-server.exe –filename /tmp/mod_mono_server_global –nonstop –master

apache   21113     1  1 16:44 ?        00:00:00 /usr/bin/mono /usr/lib64/mono/2.0/mod-mono-server2.exe –filename /tmp/mod_mono_server_dd25 –applications /:/var/www/web25/web/ –nonstop

root     21237  7561  0 16:45 pts/1    00:00:00 grep mono

 

ทดสอบสร้าง asp.net ไฟล์ นำไปไว้ที่เว็บได้เลยครับ

Linux, OpenSource