11 ธันวาคม 2550

แก้ปัญหาไม่สามารถใช้ eth0 ได้เมื่อเปลี่ยน Network Card ใน Ubuntu 7.10

ใน Ubuntu 7.10 (อันที่จริงตั้งแต่ที่เริ่มใช้ udev) Network Card ที่ udev ตรวจสอบได้จะถูกบันทึกไว้ที่ /etc/udev/rules.d/70-persistent-net.rules (ไม่มี /etc/iftab ต่อไป) ถ้าเปลี่ยน Network Card ตัวใหม่จะถูกเพิ่มต่อท้าย ให้เปลี่ยนตัวที่เพิ่มขึ้นมาเป็น eth0 (หรือ Interface อื่น) และลบบรรทัดที่มี MAC address เดิมทิ้ง

20 มิถุนายน 2550

ปัญหาเรื่อง Time Zone ใน PHP และ MySQL

Time Zone Problems, ใน PHP และ MySQL ทำให้เวลาที่ใช้งานคลาดเคลื่อน สำหรับ PHP สามารถแก้ได้ใน Code ด้วย
date_default_timezone_set("Asia/Bangkok"); ซึ่งจะตั้งให้เป็นเวลามาตรฐานประเทศไทย
ถ้าต้องการแก้ค่า default ให้แก้ใน php.ini ที่
[Date]
; Defines the default timezone used by the date functions
date.timezone = Asia/Bangkok


ส่วน MySQL ให้ใช้ SQL Command "SET time_zone = '+7:00'" ตั้งให้เป็นเวลามาตรฐานประเทศไทย
ถ้าต้องการแก้ค่า default ให้แก้ใน /etc/mysql/my.cnf (my.ini สำหรับ Windows) ที่
[mysqld]
default-time-zone=+07:00
หรือตามด้านล่าง (ใช้บน Windows ไม่ได้)
[mysqld]
default-time-zone=Asia/Bangkok

16 มิถุนายน 2550

Zip และ Unzip ด้วย PHP

บันทึกวิธีการ Zip/Unzip ด้วย PHP:
1. Download dUnzip2 จาก phpclasses.org มี 2 classes, dZip & dUnzip

2. Zip โดยใช้ dZip classs
require_once("dzip.inc.php");
$zip = new dZip("archive.zip");
$zip->addFile("myfile.doc", "myfile.doc"); // parameter แรกเป็น source file, parameter สองเป็น ชื่อ file ใน zip
$zip->addDir("subdir"); // สร้าง Folder ใน Zip
$zip->addFile("anotherfile.jpg", "subdir/newname.jpg"); // เพิ่ม file ใต้ Folder
$zip->save();
3. Unzip โดยใช้ dUnzip class
require_once("dzip.inc.php");
$zip = new dUnzip("archive.zip");
$zip->unzipAll("targetfolder"); // Unzip ทุก file ไปยัง folder ชื่อ targetfolder
$zip->unzip("source.doc", "destination.doc"); // unzip source.doc ใน zip file เป็น destination.doc

28 พฤษภาคม 2550

php: baaGrid::setGPCol

baaGrid เป็น Data Grid class ตัวหนึ่งซึ่งสามารถแสดงผล SQL Query จาก Database ได้หลายตัว โดย Default เป็น MySQL

ความสามารถหนึ่งที่ทำให้ baaGrid แสดงรายงานในแบบตารางได้ดีคือ General Purpose Column ซึ่งจะสามารถนำข้อมูลจาก query มาแสดงในรูปแบบอื่นได้เช่น image หรือ hyperlink แต่อย่างหนึ่งซึ่งตัว baaGrid Guide ไม่ได้บอกไว้ก็คือการสนับสนุนการใช้ function ได้ (**อย่างมีข้อจำกัด**) ทั้ง php built-in และ user defined โดยในการ parse funtion นั้น baaGrid ใช้ function_exists ของ php ตรวจอักขระที่ ตำแหน่ง 0 จนถึง วงเล็บเปิดแรก ถ้ามี function ที่รู้จักก็จะผ่านไปให้ eval ของ php ทำงาน
ตัวอย่าง
...
$grid->setGPCol(4, 'myfunction(#1)'); // pass column 1 from query to myfunction, valid for numeric data
$grid->setGPCol(5, 'myfunction("#2")'); // pass column 2 from query to myfunction, valid for string data
$grid->setGPCol(6, 'myfunction(#1)+123'); // also valid
...
$grid->setGPCol(6, '123+myfunction(#1)'); // invalid, function_exists('123+myfunction') returns null

11 พฤษภาคม 2550

wxWidgets ใช้ Image File แบบอื่นนอกเหนือ BMP

ถ้าจะใช้ Image File แบบอื่นนอกเหนือ BMP ต้องทำการระบุชนิดที่ต้องการใช้เพิ่มด้วยดังนี้
1 ใน class ที่ derived จาก wxApp ที่ OnInit จะต้องทำการ add image handler

#include

bool MyApp::OnInit() {
...
wxImage::AddHandler( new wxPNGHandler );
wxImage::AddHandler( new wxJPEGHandler );
wxImage::AddHandler( new wxGIFHandler );
wxImage::AddHandler( new wxXPMHandler );
}



ถ้าเอาทุกแบบใช้ wxInitAllImageHandlers.
Available Image Handlers

  • wxBMPHandler For loading and saving Windows bitmap files.
  • wxPNGHandler For loading and saving PNG files. Images with transparency or an alpha channel are supported.
  • wxJPEGHandler For loading and saving JPEG files.
  • wxGIFHandler GIF files: only for loading, due to legal issues.
  • wxPCXHandler For loading and saving PCX files. wxPCXHandler will count the number of different colors in the image; if there are 256 or fewer colors, it will save as 8-bit; otherwise it will save as 24-bit.
  • wxPNMHandler For loading and saving PNM files. Loading PNMs only works for ASCII or raw RGB images. When saving in PNM format, wxPNMHandler will always save as raw RGB.
  • wxTIFFHandler For loading and saving TIFF files.
  • wxIFFHandler For loading IFF files.
  • wxXPMHandler For loading and saving XPM files.
  • wxICOHandler For loading and saving Windows icon files.
  • wxCURHandler For loading and saving Windows cursor files.
  • wxANIHandler For loading Windows animated cursor files.

2. อย่าลืม Link library ที่เกี่ยวข้อง

  • JPEG, wxjpeg.lib
  • PNG, wxpng.lib & wxzlib.lib