Author Archive

Feb 23

Time Ago

1 comment - Post a comment

เกรียนเล่น facebook

เห็นใน facebook เวลา comment หรือว่าทำอะไรแทนที่มันจะแสดงออกมาเป็น datetime เลย มันทำเป็น time ago เลยแหะ
ต้องหัดทำบ้าง…คนที่ office ชอบบอกว่า

จะเอาแบบ facebook อะทำได้มั้ย

แกะ facebook ได้ html

<abbr title=”Tue, 23 Feb 2010 01:52:11 -0800″>17 minutes ago</abbr>

อธิบายวิธีคิดสั้นละกันครับ

  1. เวลาที่ต้องการคำนวน Tue, 23 Feb 2010 01:52:11 -0800 … แปลงให้เป็น timestamp ด้วย strtotime()
  2. เวลาปัจจุบันใช้ time()
  3. ส่วนต่างเวลา diff = time() – strtotime(‘Tue, 23 Feb 2010 01:52:11 -0800′);
  4. คำนวนอายุ … ได้ diff กับ periods โอย..ไปแกะเองเหอะพี่น้อง
  5. diff ปัดเศษ
  6. return diff periods ago

code PHP

function ago($time) {
$periods = array(“second”, “minute”, “hour”, “day”, “week”, “month”, “year”, “decade”);
$lengths = array(“60″,”60″,”24″,”7″,”4.35″,”12″,”10″);

$now = time();

$difference = $now – $time;
$tense      = “ago”;

for($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
$difference /= $lengths[$j];
}
$difference = round($difference);
$period = ($difference != 1) ? $periods[$j].’s’ : $periods[$j];
return “$difference $period $tense”;
}

เรียกใช้

echo ago(strtotime(‘Mon, 22 Feb 2010 17:28:12 -0800′)). “\n”;
echo ago(strtotime(‘2010-02-23 17:30:00′)). “\n”;
echo ago(strtotime(‘2010-02-23 17:48:00′)). “\n”;

มันยังไม่จบครับพี่น้องมี jquery version ด้วย…รอก่อน

start

/usr/local/etc/rc.d/mysql-server start

stop

/usr/local/etc/rc.d/mysql-server stop

restart

/usr/local/etc/rc.d/mysql-server restart

Jan 15

PHProxy

No comment - Post a comment

ที่มา http://sourceforge.net/projects/poxy/

PHProxy is a web HTTP proxy programmed in PHP meant to bypass firewalls and access otherwise inaccessible resources (i.e. blocked websites). If the server this script is run on can access a resource, so can you!

เอามาใช้งาน
unzip จับยัดลง {DOCUMENT_ROOT}/poxy-0.5b2/

» Read more after the jump →

Jan 14

Clear DNS Cache

No comment - Post a comment

Flush DNS ความหมายแบบหยาบ ก็คือการ clear DSN cache นั่นเองครับ
สมัยก่อนโน้นที่ยังใช้ WindowsXP มันทำง่ายๆ แค่คลิกขวาตรง icon network แล้ว repair ก็จบแล้ว

เดี๋ยวนี้ใช้ Windows7 เฟ้ย…ของแท้เฟ้ย
1. windows + r (run)
2. ipconfig /flushdns

ถ้าจะดูว่า DNS cache มีอะไรบ้าง
ipconfig /displaydns

Plugin ของ jQuery ที่ผมใช้ประจำก็คือ  jQuery Validation Plugin ใช้งานยังไงไปอ่าน jQuery + Validate Plugin เช็คฟอร์มเรื่องง่าย ใครว่ายาก ได้เลยครับ..

แต่วันนี้จะมาขาย method ที่เขียนใช้เองคิดว่าคงจะได้ใช้กันบ้าง..เป็นการตรวจสอบ รหัสประจำตัวประชาชน ใครยังไม่รู้ความหมายขิงเลขแตละหลักไปอ่าน http://dop.rta.mi.th/pid13.htm เอาเองนะ..

สำหรับการตรวจสอบ รหัสประจำตัวประชาชน ด้วย javascript ผมก็ไปก๊อปจาก
ความหมายของเลข 13 หลัก ในบัตรประจำตัวประชาชน พร้อม Code JavaScript

ปรับแต่งนิดหน่อยแล้วเพิ่ม medthod ไปใน jQuery Validation Plugin จะได้เรียกใช้ง่ายๆ

$.validator.addMethod(“pid13″, function(value, element) {
if (!/^[1-8]\d{12}/.test(value.toString())) return false;
var t=value.toString().split(”);
var m=13,s=0;
for (i in t) s+=t[i]*m–;s-=t[12];
return (11-s%11)%10==t[12];

}, “Please enter a valid personal ID.”);

การใช้งาน
ไส่ class=” pid13″ ได้เลย

หรือกำหนดเองขั้นเทพ

$(function() {
$(“form”).validate({
rules: {
pid: {
required: true,
pid13: true
}
}
});
})

ปล. “..” แปลว่า ขี้เกียจหว่ะ

เอาไว้กันเหนียวเวลา hosting แม่ง @!@#$%^&*
» Read more after the jump →

ปีนี้อดไปลอยกระทงกับคุณครูเลยขอลอยกระทงบนเว็บแทน
» Read more after the jump →

Oct 16

isIE6

No comment - Post a comment

function isIE6() {
  return $.browser.msie && $.browser.version<7;
}

ลาก่อน Prototype

ความในใจที่ใช้ prototype น่าจะมากว่า 2 ปี

  • Syntax ของ prototype ง่ายครับ….ก็ใช้ prototype อย่างเดียวอันอื่นยากหมด
  • มองไปทางไหนใครๆก็ jQuery กันทั้งนั้น …. เออดีจะได้ไม่มีใครแกะ code เราออก
  • jQuery เร็วสาาดเทียบกันเป็นวิเลยนะ … ใช้ prototype แหละถึงช้าแต่งานเสร็จเร็ว
  • plugin jQuery เยอะนะ…แง่มๆ prototype ก็พอมี เขียนเองก็ได้
  • animate() เจ๋งสุด …ใช้ script.aculo ก็ได้

…สุดท้าย
เราเลือกทางเดินที่ดีที่สุดเสมอ

ปล. ลาก่อน Michael Jackson

Jul 18

jquery sifr

1 comment - Post a comment

แอบมาอัพเดท wordpress เงียบๆ
..

ทดสอบความหล่อ…อีกแล้วเหรอ