Unit Vectors – Normalizing ใช้ python และ numpy
ก่อนที่เราจะ normalize vector ได้ เราต้องหา norm ( magnitude หรือ ขนาด) ของมันก่อน ซึ่งมันหาได้โดยการ ถอด Square root ของ ผลบวกกำลังสองครับ (sumsquare) length = sqrt((ax * ax) + (ay * ay) + (az * az)) length = sqrt(9 + 1 + 4) = 3.742 ซึ่ง 3.742 จะเป็น ขนาดของ Vector [1,2,3] ครับ ถ้าจะ normalize vector นี้ก็เอา magnitude ไปหารทุกตัวครับ x [...]
[Google Maps Geocoding] ลอง Parse Json ด้วย Groovy + Java (Netbeans)
โปรเจ็คตลกๆมาอีกแล้ว เพราะโปรเจ็คนี้ผมใช้ Json Lib + Groovy + Java แต่ผมใช้ Groovy ดึง json (URL.text) แล้วใช้ Java เป็นตัวแกะ jsonObject เป็น jsonArray หลังจากนั้นเอาข้อมูลโยนกลับไปให้ Groovy ถอดเอาเฉพาะส่วนที่ต้องการออกมา (ในที่นี้คือ coordinates — latitude ,longitude นั่นแหละ) ดูวุ่นวายมาก ทั้งๆที่ เขียน Groovy อย่างเดียวก็ได้ เพราะ Json Lib ก็ลองรับ groovy หรือจะเขียน Java เพียวๆ เลยก็ได้ เรื่องของเรื่องคืออยากเขียน Java ร่วมกับ Groovy อีกครั้ง เพราะไม่ค่อยถูกกับ Java จริงๆ มันดูเวื่นเว้อ มันเขียนเวิ่นเว้อด้วย ยาวๆ งงๆ (อาจเป็นเพราะไม่ได้ศึกษาอย่างลึกซึ้ง) groovy [...]
[code] อัพโหลดภาพเข้า twitpic โดยใช้ api
[code] อัพโหลดภาพเข้า twitpic โดยใช้ api จะใช้ CURL ซึ่ง จาก function จะ input username ,password , filepath function postTwitpic($username='',$password='',$filepath='') { $postfields = array(); $postfields['username'] = $username; $postfields['password'] = $password; $postfields['media'] = "@$filepath"; $twitter_url = 'http://twitpic.com/api/upload'; $curl = curl_init(); curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1); curl_setopt($curl, CURLOPT_URL, $twitter_url); curl_setopt($curl, CURLOPT_POST, 3); [...]
[Draft] : NPDigger Version Semi Auto
กำลังทำ npdigger version ใหม่แบบ Semi Automatic เปิดโปรแกรมทิ้งไว้ แล้วมันจะโพสเองเรื่อยๆ จด code ไว้หน่อยละกัน function getCode($userkey) { if(isset($userkey)) { // $this->db->select_min(‘added_time’); // $this->db->where(‘status’, ); // $query= $this->db->get(‘captcha’); /// $this->db->select(‘UNIX_TIMESTAMP(MIN(added_time)) AS MIN_STAMP’); // $query= $this->db->get_where(‘captcha’, array(‘userkey’ => $userkey) ); $this->db->select(‘captcha, decaptcha’); // $this->db->select_min(‘addfed_time’); // $array = array(‘UNIX_TIMESTAMP(added_timed)’ => ‘UNIX_TIMESTAMP(MIN(added_time))’); $where = “UNIX_TIMESTAMP(added_time) = (select UNIX_TIMESTAMP(MIN(added_time)) FROM captcha WHERE userkey=’$userkey’) [...]
getPage และ postPage ด้วย php+cURL
มีฟังก์ชั่น 2 อัน ชื่อตรงตัวเลยครับว่าให้ทำอะไร วิธีใช้ก็อ่านเอาที่ Prototype ของ function ได้เลยครับ //———————————————————————————– function getPage($url, $referer, $timeout, $header){ if(!isset($timeout)) $timeout=30; $curl = curl_init(); if(strstr($referer,”://”)){ curl_setopt ($curl, CURLOPT_REFERER, $referer); } curl_setopt ($curl, CURLOPT_URL, $url); curl_setopt ($curl, CURLOPT_TIMEOUT, $timeout); curl_setopt ($curl, CURLOPT_USERAGENT, sprintf(“Mozilla/%d.0″,rand(4,5))); curl_setopt ($curl, CURLOPT_HEADER, (int)$header); curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0); $html = curl_exec ($curl); curl_close [...]
MPI Programming : ตอนที่ 2
Blocking Communication อันนี้เป็น Prototype ของ MPI_Send และ MPI_Recv ซึ่งเป็นการสื่อสารแบบ Blocking ครับ (มันมี Non-blocking ด้วยไว้ค่อยมาคุยกันอีกทีว่ามันต่างกันยังไงในวันหลังนะครับ) ที่ยกเรื่องนี้มาให้ดูก่อน เพราะตอนหน้าเราจะส่งข้อมูลข้าม Process โดยใช้ MPI (Send & Recv) กันแล้วคร้าบผม int MPI_Send( void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm );
Ruby Array with Range : Note
กำลังสงสัยว่า ใน ruby a[0..n] ทำไมมันถึงไม่เหมือนกับ a[0,n] ครับ มันควรจะเหมือนกันไม่ใช่หรอครับ เพราะไปเขียน Merge Sort แล้ว มันให้ผลไม่เหมือนกันเกิด Infinite Loop เลยทีเดียว พอเปิดหนังสือดู อ้าว… เฮ้ย เจ้าตัว operator [ ] ของ array มันก็ให้ผลเหมือนกันนี่หว่า return เหมือนกันเลย หลังจากนั้นก็ลองไปเทสแยกดู ตอนแรก a[0,3] กับ a[0..3] มันเท่ากัน ก็เลย งงว่า มันก็เท่ากันนี่หว่า แต่ลองเช็คอีกทีว่าถ้าเป็น 0,0 มันจะ return อะไร แล้วก็โป๊ะเชะ ที่มันไม่เท่าเพราะ a=["a","b","c","d"] แล้ว >> a[0..0] => ["a"] ส่วน [...]


![[Google Maps Geocoding] ลอง Parse Json ด้วย Groovy + Java (Netbeans)](http://www.together.in.th/wp-content/uploads/2010/01/Picture-5-150x150.png)