Archive for June, 2008

0023 | Collections Framework

Tuesday, June 24th, 2008 Posted in Java | No Comments »

ไม่มีอะไรครับ เอา code มาเก็บไว้เฉยๆ 555
กลับมาอ่านอีกทีคงลืมแล้วแหงๆ ว่ามันไว้ทำอะไร

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.*;
class Product implements Comparable<Product>
{
public int id;
public String name;
public int qty;
public double price;
 
public Product(int id, String name, int qty, double price) {
this.id = id;
this.name = name;
this.qty = qty;
this.price = price;
}
 
public String toString() {
return this.id +:+ this.name +:+ this.qty +:+ this.price;
}
 
public int compareTo(Product s) {
return s.qty - this.qty;
}
}

———————————–

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import java.util.*;
class ProductDB
{
public static void main(String[] args)
{
List<Product> db = new LinkedList<Product>();
db.add(new Product(1, “pen”, 20, 5.50d));
db.add(new Product(2, “ruler”, 18, 10.00d));
db.add(new Product(3, “notebook”, 15, 18.50d));
db.add(new Product(4, “rubber”, 40, 15.00d));
db.add(new Product(5, “pencil”, 25, 3.00d));
Collections.sort(db);
for (Product i : db) {
System.out.println(i);
}
}
}

Tags: , ,

0022 | สร้าง subdomain แบบสิ้นคิด

Sunday, June 15th, 2008 Posted in Web Server | 8 Comments »

เล่นง่ายมากเลยครับวันนี้
พี่เอก bluegy.com ให้มา config แปลงจาก subfolder เป็น subdomain
สมมติ URL เดิม http://www.icez.net/blog/
ก็ให้มันเข้าจาก http://blog.icez.net/ แทนได้เลย
เราก็นึกก่อนเลย htaccess rewrite เอาก็จบ เสร็จแล้วก็เลยสิ้นคิดมากมาย
นั่ง search หาข้อมูลกันแบบงงๆ เล็กน้อย มั่วเอาจาก wordpress mu
สุดท้ายก็ได้ตัว .htaccess ตัวนี้มาครับ

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} !\.php$
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . – [L]

RewriteCond %{HTTP_HOST} !www.icez.net
RewriteCond %{HTTP_HOST} !^icez.net

RewriteCond %{HTTP_HOST}<>%{REQUEST_URI} ^([^.]+)\.icez\.net(:80)?<>/([^/]*) [NC]
RewriteCond %1<>%3 !^(.*)<>\1$ [NC]
RewriteRule ^(.*)$ /%1/$1 [L,QSA]

เจอปัญหาอย่างนึงว่า ถ้าสมมติเข้าเว็บ อย่าง http://something.icez.net/
แล้วไม่มี folder ชื่อนี้อยู่ในระบบเนี่ย
มันจะเด้งหน้า Internal Server Error ขึ้นมาเลย

แก้ได้แล้วค้าบบบบ ไม่เจอแล้ว เย้ๆๆๆๆๆๆๆๆๆ
(ถ้าไม่เจอ subdomain จะขึ้นหน้า 404 ธรรมดาแทน)

อ้อ ถ้าใครจะเอาไปทำ อย่าลืมเพิ่ม config apache ลงใน virtual host ด้วยนะครับ

ServerAlias *.icez.net

ตามนี้เลยฮะ (แก้ตัวสีน้ำเงินด้วยน่อ)
แล้วก็อย่าลืมไป add DNS record ด้วยนะจ๊ะ

*.icez.net. IN A 203.146.129.182

.

.

แก้ไขเพิ่มเติมจ้าาาา ด้านบนเลย ^^”

Tags: , ,