วันพุธที่ ๘ ตุลาคม พ.ศ. ๒๕๕๑

Time Management

งาน เร่งด่วน ไม่เร่งด่วน
สำคัญ ก. งานก้อนกรวด ข. งานก้อนหิน
  * วิกฤต
* ปัญหาประชิดตัว
* กำหนดการแน่นอน
โครงการใหม่
กฏระเบียบ
การปฏิรูป
ไม่สำคัญ ค. งานเม็ดทราย ง. งานน้ำ
  รับรองแขกที่ไม่ได้เชิญ
จัดการจดหมายเอกสาร
เข้าประชุมทั่วไป
กิจกรรมทั่วไป
งานเลี้ยง
สังสรรค์
กิจกรรมอื่นๆ

วันจันทร์ที่ ๒๙ กันยายน พ.ศ. ๒๕๕๑

ThaiUtilities

public class ThaiUtilities {
public static String Unicode2ASCII(String unicode) { // แปลง Unicode เป็น ASCII
StringBuffer ascii = new StringBuffer(unicode); // กำหนดพื้นที่ใช้งานชั่วคราว
int code;
for(int i = 0; i < unicode.length(); i++) { // ลูปเท่าจำนวนตัวอักษร
code = (int)unicode.charAt(i); // อ่านค่ารหัสที่ละตัวอักษร
if ((0xE01<=code) && (code <= 0xE5B )) // ตรวจสอบว่าอยู่ในช่วงภาษาไทยของ Unicode หรือไม่
ascii.setCharAt( i, (char)(code - 0xD60)); // หากใช้แปลงเป็นภาษาไทยในช่วงของ ASCII
}
return ascii.toString(); // แปลงข้อมูลกลับไปเป็นแบบ String เพื่อใช้งานต่อไป
}
public static String ASCII2Unicode(String ascii) {
StringBuffer unicode = new StringBuffer(ascii);
int code;
for(int i = 0; i < ascii.length(); i++) {
code = (int)ascii.charAt(i);
if ((0xA1 <= code) && (code <= 0xFB)) // ตรวจสอบว่าอยู่ในช่วงภาษาไทยของ ASCII หรือไม่
unicode.setCharAt( i, (char)(code + 0xD60)); // หากใช้แปลงเป็นภาษาไทยในช่วงของ Unicode
}
return unicode.toString(); // แปลงข้อมูลกลับไปเป็นแบบ String เพื่อใช้งานต่อไป
}
}

 

ปล เอามาจาก หลายๆ ต่อ แต่เค้าว่าดังเดิมมาจาก javacentrix

วันอังคารที่ ๒๓ กันยายน พ.ศ. ๒๕๕๑

FW: ทอนเท่าไหร่

เงินสิบบาท
ถ้าเรามีเงินอยู่ 10 บาท ซื้อของ 3 บาท จะได้รับเงินทอนเท่าไร?
ครูคนหนึ่งตั้งคำถามกับเด็กว่า 'ถ้ามีเงินอยู่ 10 บาท ซื้อของ 3 บาท จะได้รับเงินทอนเท่าไร' เด็ก
ส่วนใหญ่ตอบว่า '7 บาท'
แต่มีเด็ก 2คนที่ตอบไม่เหมือนกับคนอื่น คนหนึ่งตอบว่า '2 บาท' อีกคนหนึ่งตอบว่า 'ไม่ต้องทอน'
ครูถามเด็กคนแรกว่าทำไมถึงได้เงินทอน 2 บาท คำตอบที่ได้ก็คือภาพในใจของเขาสำหรับเงิน 10
บาท คือ เหรียญห้า 2 เหรียญ เมื่อซื้อของราคา 3 บาท เขา
ก็ให้เหรียญห้า 1 เหรียญ ดังนั้น จึงได้เงินทอน 2 บาท
ถามเด็กคนที่สองว่าทำไมไม่เหลือเงินทอนเลย
คำตอบก็คือเด็กคนนี้คิดว่าในกระเป๋ามีเหรียญบาท 10 เหรียญ เมื่อซื้อของราคา 3 บาท เขาก็ส่ง
เหรียญบาทให้ 3 เหรียญ เพราะฉะนั้น คนขายจึงไม่ต้องทอนเงิน
ให้เขา
โชคดีที่เป็นการถาม-ตอบในห้องเรียน ลองนึกดูสิครับว่าถ้าโจทย์นี้เป็นข้อสอบที่มีคำตอบเป็น ก-ข-ค-ง
เด็ก 2 คนนี้ก็คงไม่ได้คะแนนจากคำตอบที่ผิดเพี้ยนจากคน
ส่วนใหญ่
การสร้างโจทย์ที่ 'เสมือนจริง' จินตนาการของ 'ครู' อาจถูกจำกัดเพียงแค่ 'ตัวเลข' แต่สำหรับ
เด็ก จินตนาการของเขาไร้กรอบ 10 บาท จึงสามารถเปลี่ยน
เป็นเหรียญสิบ เหรียญห้า หรือเหรียญบาท
เมืองไทยมีเหรียญ 2 บาท เราจึงไ ด้คำตอบเพิ่มอีก 1 คำตอบ คือ ได้เงินทอน 1 บาท
โลกในห้องเรียนกับโลกของความเป็นจริงนั้นแตกต่างกัน โลกในห้องเรียน ทุกคำถามส่วนใหญ่มีเพียง
1 คำตอบ แต่โลกของความเป็นจริง ทุกคำถามอาจมีคำตอบที่
ถูกต้องได้เกิน 1 คำตอบ
'อย่ารีบตัดสินความผิดถูกของคนๆ นั้น เพียงแค่ คำตอบ ของเรา'
'อย่าหยุดความคิดสร้างสรรของคนๆ นั้น ด้วยกรอบความคิดของเรา'

วันศุกร์ที่ ๑๑ เมษายน พ.ศ. ๒๕๕๑

GHC cont..

เราสามารถ สร้าง fn ด้วย clauses หลายๆ อันโดยคั่น ด้วยเครื่องหมาย เซมิโคลอน


Prelude> let { f op n [] = n ; f op n (h:t) = h `op` f op n t }
Prelude> f (+) 0 [1..3]
6
Prelude>


ดูแล้วงงๆ มะ


ลองถามใน www.codenone.com แล้ว มีคนตอบไว้ดังนี้


Submitted by pphetra on 7 April, 2008 - 07:39.



function นี้ define ไว้ 2 กรณีคือ

กรณีที่ parameter ตัวที่ 3 เป็น empty-array



f op n [] = n


กับกรณี parameter ตัวที่ 3 เป้น array ปกติ



f op n (h:t) = h `op` f op n t


ถ้ายังงงว่าทำไมมันต้อง define เป็น 2 function แบบนี้

แนะนำว่าควรอ่าน concept เรื่อง pattern matching ก่อน


http://en.wikipedia.org/wiki/Pattern_matching



เมื่อเราเรียก f (+) 0 [1..3]


เนื่องจาก array ของเรามีค่า


มันก็จะใช้ function ที่สองในการทำงาน



f (+) 0 (1:[2,3]) = 1 + (f (+) 0 [2,3])
= 1 + (2 + (f (+) 0 [3]))
= ...
= 1 + ... + (f (+) 0 [])


หลังจาก recursive ไปเรื่อยๆ จนถึง f (+) 0 [] (ตัวที่อยู่ที่ท้ายบรรทัด),

กรณีนี้ค่าใน array ของ parameter ตัวที่ 3 มันเป็นค่าว่าง


ดังนั้นเวลามันทำงาน มันก็จะไปตกในเงื่อนไข function แรก



f op n [] = n
==>
f (+) 0 [] = 0

วันพฤหัสบดีที่ ๓ เมษายน พ.ศ. ๒๕๕๑

TERM

IT Management, Business strategies and functions, Asset/resource/knowledge management, B2B, Cost control, Customer support, E-commerce, IT budgeting, IT outsourcing, IT project management, R&D, Nanotechnology, Robots, ROI/TCO, Recycling, Standards, Infrastructure, IT training, Infrastructure/architecture management, Service level management, Internet, Domain names, Web sites, Industries, Automotive, Bio-tech, Entertainment, Government, Healthcare, Space, Networking, Data management, Data mining and analysis, Data security, Data warehousing/business intelligence, Database management, Directory services, LANs and WANs, Bandwidth, Diagnostics and monitoring, Ethernet, Network administration/implementation, Network standards/protocols, Optical networking, Routing/switching, Systems migration, TCP/IP, Mobile/wireless, 3G, 802.11/Wi-Fi, Bluetooth, Mobile platforms/communications, RFID, WAP, WiMax, Wireless LANs, Networking technology, Business broadband, Home automation, Personal broadband, Cable, DSL, Telephony, VoIP and IP telephony, VPNs, Security, Authentication and encryption, Biometrics, Digital signatures, PKI (public key infrastructure), SSL/TLS, Network security, Disaster recovery, Firewalls, IDS (Intrusion Detection Systems), Security applications/tools, Security implementation/standards, Security management, Security threats, Hacking, Spam and phishing, Spyware/adware, Viruses and worms, Software, Business applications, Antivirus software, App servers, Content management, Customer resource management (CRM), Databases, E-mail servers, Enterprise resource planning (ERP), File servers, Groupware, work flow software, Instant messaging, Knowledge management, Remote management, Sales force automation, Search, Spam filtering, Storage software, Supply chain management (SCM), Utility computing, Web servers, Web services, Mobile platforms, PalmOS, Pocket PC, Symbian, Open source, Operating systems, Linux, Linux desktop OS, Linux server OS, Mac OS, Microsoft Windows, Longhorn, Microsoft Server 2003, Windows 2000, Windows 98, Windows NT, Windows XP, Unix, Personal applications, Dell (DELL), Microsoft Outlook, Games, Media players, Office suites, Microsoft Office, Web browsers, Protocols and platforms, .Net, Authoring, Component-based development, Java, Multimedia, Object-oriented programming, Peer to peer, Programming languages, Software engineering/development, Software integration, XML, Software licensing

วันอาทิตย์ที่ ๓๐ มีนาคม พ.ศ. ๒๕๕๑

GHC ต่อ

อ่านจาก Tutorial Chapter 3

เมื่อเราพิมพ์ expression ของ haskell ที่ prompt GHCi จะทำการ evaluate แล้วให้ผลลัพธ์ทันที เช่น

Prelude> reverse "hello"
"olleh"
Prelude> 5+5
10


ตัว GHCi นอกจาก evaluate expression แล้วยังจัดการเกี่ยวกับ IO ด้วย เช่น



Prelude> putStrLn "hello"
hello


Prelude> do { putStrLn "hello"; return "yes" }
hello
"yes"


Prelude> x <- return 42
42
Prelude> print x
42
Prelude>


statement  x <- return 42 หมายถึง "execute return 42" ใน IO และจากนั้นให้ bind ผลลัพธ์ไปเก็บที่ x หลังจากนั้นเราสามารถใช้ x ใน statment อื่น ต่อได้ทันที เช่น ใช้คำสั่ง print เพื่อแสดงข้อมูลที่ x เก็บไว้ออกมา



 



เราสามารถ bind โดยใช้ let ก็ได้ดังนี้



Prelude> let x = 42
Prelude> x
42
Prelude>


นอกจากนี้เรายังสามารถใช้ let ในการสร้าง function ขึ้นมาใช้งานได้เช่น



Prelude> let add a b = a + b
Prelude> add 1 2
3
Prelude>


Prelude> let extraadd a b = a + a + b

Prelude> extraadd 1 2


4


Prelude>



 



 

วันเสาร์ที่ ๒๒ มีนาคม พ.ศ. ๒๕๕๑

ลอง GHC (The Glorious Glasgow Haskell Compilation System User's Guide, Version 6.6)

ดาวน์โหลด http://www.haskell.org/ghc/dist/6.6/ghc-6-6.msi

ว้ววว ลงได้แหะ

   ___         ___ _
  / _ \ /\  /\/ __(_)
/ /_\// /_/ / /  | |      GHC Interactive, version 6.6, for Haskell 98.
/ /_\\/ __  / /___| |      http://www.haskell.org/ghc/
\____/\/ /_/\____/|_|      Type :? for help.

Loading package base ... linking ... done.
Prelude>