MY Note

study it – know it – use it

Using firebug in IE

add this script in html page

<script type='text/javascript'
        src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>

then run
——————–

July 29, 2009 Posted by | JAVASCRIPT | Leave a Comment

JavaScript : Ignore Case Array Sort

When you sort an array in Javascript the array gets sorted into dictionary order. This means that ‘A’ is less than ‘a’ and gets sorted that way. If your array consists of both uppercase and lowercase entries then you probably want to sort alphabetically ignoring the case of the individual entries instead. We can change the way that the array sort method works by passing it a parameter identifying a function that contains the instructions on how to compare the entries.

To sort an array into order ignoring case add the following code (into the head section of your page is probably the most appropriate place):

function charOrdA(a, b){
a = a.toLowerCase(); b = b.toLowerCase();
if (a>b) return 1;
if (a <b) return -1;
return 0; }
function charOrdD(a, b)
a = a.toLowerCase(); b = b.toLowerCase();
if (a<b) return 1;
if (a >b) return -1;
return 0; }

We can now sort the array without the upper and lower case entries being sorted into different orders. The following example shows how:

charArray = new Array(‘c’,'A’,'z’,'f’,'D’);
charArray.sort( charOrdA );
document.write(‘Ascending : ‘ + charArray + ‘<br />’);
charArray.sort( charOrdD );
document.write(‘Descending : ‘ + charArray + ‘<br />’);

June 15, 2009 Posted by | JAVASCRIPT | Leave a Comment

Short circuit logic operator

ในภาษาโปรแกรมมิ่งที่มีคนใช้กันมากๆเกือบทุกตัว จะต้องมีโอเปอเรเตอร์ในการดำเนินการทางตรรกะแบบลัด ซึ่งมีชื่อว่า Short-Circuit Operator ซึ่งเราสามารถที่จะใช้เจ้าตัว Short-Circuit Operator ให้เป็นประโยชน์ได้
 
ทำได้อย่างไร?
กฏของ Short-Circuit Operator อยู่บนกฏพื้นฐานของ && และ || นั้นคือ
สำหรับ && แล้วถ้ามีตัวใดตัวหนึ่งในนิพจน์เป็นเท็จค่าของนิพจน์ && จะเป็นเท็จทันที
ตัวอย่างที่แสดงได้ดังต่อไปนี้
Code Sample
bool p = false;
bool q = true;
if (p && q) // ที่บรรทัดนี้โปรแกรมสามารถสรุปได้ทันที่ว่าเงื่อนไขนี้เป็นเท็จ
   ;        // โดยไม่ต้อง evaluate(คำนวณ)ค่าของ q แต่กลับกันหาก
            // p เป็น true q ต้องถูก evaluate ค่า
ตัวอย่างในสถานการณ์จริงเช่นเราต้องการ เรียกใช้งาน Method ที่อยู่ใน class
แต่ตัวแปรที่ใช้เก็บ instance ของคลาสนั้น อาจมีค่าเป็น null ได้
เพื่อหลีกเลี่ยง NullException เราจึงต้อง Check ค่าของตัวแปรว่ามีค่าเป็น Null หรือไม่ก่อนที่จะใช้งานมัน
เช่น ต้องการตรวจสอบความยาวของ string s
if (s != null && s.Length == 100) // กรณี s มีค่าเป็น null เราก็ไม่จำเป็นต้องตรวจสอบความยาวอีก
    ; //so something

bitwise หรือ logic operator นั้นจะทำงานได้เร็วกว่าโครงสร้างควบคุมแบบ if(    ) และแน่นอนช่วยเพิ่มประสิทธิภาพให้โปรแกรมของคุณ

October 3, 2008 Posted by | .NET, ASP.NET, JAVASCRIPT | Leave a Comment

ทำไมจึงควรใช้ Asychronous script callback และ Page Method แทน Update Panel

การใช้งาน Asynchronize Feature ใน Ajax นั้นสามารถทำได้หลายวิธีด้วยกัน วิธีที่งานและเป็นที่นิยมมากคือการใช้ Update Panel ซึ่งเป็น Control พื้นฐานที่ติดมากับตัว Ajax Extension Module สำหรับ ASP.NET

UpdatePanel นั้นสามารถใข้งานได้งาน เพียงแค่นำส่วนของ Page ที่ต้องการให้เป็น Asynchronous Postback ใส่ไว้ใน Update Panel ก็สามารถทำงานได้แล้วแต่ ตัว UpdatePanel นั้นมีความสามารถในงาน call กลับไปยัง server ได้โดยที่ วงจรชีวิตในการทำงานของ server-side จะเกิดขึ้นปกติเหมือนกับการทำ postback ปกติ ตรงจุดนี้เองทำให้การใช้งาน Updatepanel นั้นจะได้ Performance ที่ต่ำกว่าการเรียกใช้ Webmethod หรือการใช้ Asynchronous layer เรียกไปยัง web service โดยตรง เนื่องจาก WebMethod นั้นจะทำงานโดย JSON ซึ่งเป็นลักษณะหน่ึงของ Web Service ข้อมูลที่ใช้ส่งระหว่างกันจะมีเพียงข้อมูลเป้าหมายที่ต้องการแสดงเท่านั้น แต่ในขณะที่ UpdatePanel นั้นจะทำการ render ทุกๆส่วนภายใน Panel ใหม่ทั้งหมด(ความจริง Render ใหม่ทั้ง Page แต่ว่า write กลับเฉพาะส่วนที่อยู่ภายใน UpdatePanel)

สรุป

การใช้ UpdatePanel นั้นดูเหมือนว่าจะเป็นการเพิ่มความสามารถให้กับหน้า Web Page ของเราแต่กลไกการทำงานของตัวมันเองจะมีลักษณะเดียวกับหน้าที่ไม่เป็น UpdatePanel และอาจจะอันตรายกว่าเนื่องจากการใช้ UpdatePenel เข้าไปช่วยนั้นมักจะทำให้เกิดการส่งข้อมูลบ่อยครั้งกว่าเนื่องจากผู้พัฒนามักเข้าใจผิดว่า server จะทำงานน้อยลง หากผู้พัฒนาต้องการทำเว็บเพจ ที่ต้องการการพิจารณาถึงเรือ่ง performance อยางระมัดระวังแล้ว Web service และ webmethod ดูจะเป็นทางเลือกที่ดีกว่า

 

ref: http://devstock.exteen.com/20090820/ajax-updatepanel-control

ref: http://devstock.exteen.com/20090820/ajax-updatepanel-control

October 3, 2008 Posted by | ASP.NET, JAVASCRIPT | Leave a Comment

javascript

Observer Design Pattern Using JavaScript
http://www.codeproject.com/KB/scripting/Observer_Pattern_JS.aspx

Handy XP Style Menu
http://www.codeproject.com/KB/scripting/leftmenu.aspx

AJAX For Beginners
http://www.itechcollege.com/courses/AJAX/

http://www.codeproject.com/KB/scripting/jsbeginner.aspx

http://secure.codeproject.com/KB/scripting/cookies_intro.aspx

http://www.codeproject.com/KB/scripting/Javascript_PageCookie.aspx

September 27, 2008 Posted by | JAVASCRIPT | Leave a Comment

JavaScript Convert String number

Question: How do I convert numbers to strings in JavaScript?

Answer: The simplest way to convert any variable to a string is to add an empty string to that variable, for example:

 

number -> string
a = a+'' // This converts a to string
b += ''  // This converts b to string
string -> number
eval(a);

September 19, 2008 Posted by | JAVASCRIPT | Leave a Comment

javascript replace string

/**
*
*  Javascript string replace
*  http://www.webtoolkit.info/
*
**/

// standart string replace functionality
function str_replace(haystack, needle, replacement) {
    var temp = haystack.split(needle);
    return temp.join(replacement);
}

// needle may be a regular expression
function str_replace_reg(haystack, needle, replacement) {
    var r = new RegExp(needle, 'g');
    return haystack.replace(r, replacement);
}

September 18, 2008 Posted by | JAVASCRIPT | Leave a Comment

Object serialization คืออะไร?

คือ การแปลงออปเจคให้อยู่ในรูปของไบต์สตรีม (byte stream) 

1. มีไว้เพื่อใช้ในการเก็บออปเจคไว้ในไฟล์ เพื่อเรียกอ่านและแปลงกลับ (deserialization) เป็นออปเจคในภายหลัง เช่น เราเซฟออปเจคที่เก็บข้อมูล application parameter บางตัวไว้ลงในไฟล์หลังจากโปรแกรมจบ เพื่อว่าในการรันโปรแกรมครั้งต่อไปจะได้อ่านพารามิเตอร์เหล่านั้นกลับเข้ามา วิธีนี้ไม่ค่อยเป็นที่นิยมนัก เนื่องจากมีทางเลือกอื่นๆ เช่น เก็บข้อมูลลงในฐานข้อมูล หรือ ใช้ System.Properties หรือใช้ XMLEncoder (ในจาวา 1.4 ขึ้นไป) 

2. มีไว้สำหรับเป็นวิธีส่งออปเจคนั้นไปยังเครื่องอื่น เนื่องจากออปเจคถูกแปลงเป็นไบต์สตรีม จึงสามารถส่งออปเจคนั้นไปที่เครื่องอื่น (object distribution) ในกรณีผ่านเป็นพารามิเตอร์ในการ invoke ออปเจคข้ามเครื่อง (เช่นที่ใช้ใน RMI) หรือเป็นการ migrate object ไปรันที่เครื่องอื่น เป็นต้น

———

Stream มีโครงสร้างพื้นฐานเป็นสายของ Byte ที่วิ่งมาเรื่อย ๆ เหมือนกระแสน้ำ นั่นหมายความว่าคุณสามารถเก็บข้อมูลจาก Stream หรือเขียนอะไรลงไปใน Stream คุณต้องทำงานเป็น Byte เสมอ คือก้อนข้อมูลขนาด 0-255 หลาย ๆ ก้อนต่อกัน ผมขอเรียกว่า Byte Stream

ต่อมาเราพบว่า Byte Stream มันใช้งานได้ยากลำบากมาก เพราะเราต้องทำอะไรบางอย่างเพื่อแปลง byte ที่ได้จากการอ่านข้อมูลจาก Stream ให้กลายเป็นสิ่งที่ต้องการ เช่น String และในทางกลับกันเวลาเขียนข้อมูลลงไปใน Stream ก็ต้องแปลงมันให้กลายเป็น byte ทีละ byte ก่อน จึงจะสามารถเขียนข้อมูลลงไปใน Stream ได้ จึงมีการสร้างตัวกรองขึ้นมา (Filter) โดยตัวกรองมีหน้าที่แปลงข้อมูลขาเข้าหรือขาออกตามแต่หน้าที่ เพื่อทำอะไรบางอย่างก่อนจะปล่อยข้อมูลออกมา หรือใส่ข้อมูลเข้าไปใน Stream

Filter จะไม่เปลี่ยนแปลงตัว Raw Data แต่จะทำการแปลงให้อยู่ในรูปแบบที่ใช้งานได้ง่ายขึ้น เช่น
- BufferedInputStream ทำหน้าที่อ่าน Stream มาเยอะ ๆ แล้วเก็บเอาไว้ในหน่วยความจำ แต่เวลาใช้งานเราใช้งานเสมือนว่าข้อมูลยังส่งอยู่ในสายข้อมูล มีประโยชน์ในการ mark/reset เพื่อย้อนกลับไปยังจุดที่เคยอ่านมาก่อน ซึ่ง Stream จริงๆ ไม่ใช่แบบนั้น (สายน้ำย่อมไม่ไหลย้อนกลับ แต่กักตุนได้)

September 9, 2008 Posted by | JAVASCRIPT, JSON | Leave a Comment

While Loop

var foundOne;
while (foundOne != 0){
foundOne = Math.round(14 * Math.random());
document.write (foundOne + ‘<br>’);
}

January 25, 2008 Posted by | JAVASCRIPT | Leave a Comment

Web develop tutorial

http://www.mandarindesign.com/

http://www.mandarindesign.com/boxes.html

*******************

http://www.sitepoint.com/recentarticles/

 http://www.sitepoint.com/article/aspnet-performance-tips

http://www.seoconsultants.com/css/menus/tutorial/

http://www.telerik.com/demos/aspnet/Grid/Examples/Overview/DefaultCS.aspx

http://www.amazon.com/gp/product/webstandardsw-20/1590595335/104-6729182-1300737

November 10, 2007 Posted by | dom, JAVASCRIPT, OTHER | Leave a Comment

Follow

Get every new post delivered to your Inbox.