Tag: array’
Javascript สั้นๆ ตอน Array ปลอมๆ [แล้วจะรู้ได้ยังไงว่าเป็น Array หรือ Object]
- by NAzT
ใน JavaScript ไม่มีข้อมูลที่เป็น Array จริงๆ
Array ที่มีอยู่มัน array แบบหลอกๆ จริงแล้วมันเป็น object ที่มี key เป็นตัวเลข, มี method เกี่ยวกับ array, และมี property length
ถ้าเราพึ่งคำสั่ง typeof อย่างเดียวเราก็จะเจ็บอีกตามเคย
กล่าวคือถ้าเราสั่ง typeof [] และ typeof {} มันจะบอกว่า เป็น object ทั้งคู่! แบบนี้
Read this article »
Unit Vectors – Normalizing ใช้ python และ numpy
- by Nat
ก่อนที่เราจะ 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 = 3.0 / 3.742 = 0.802
y = 1.0 / 3.742 = 0.267
z = 2.0 / 3.742 = 0.534
ซึ่งใน python เขียนแค่
ก็จะได้คำตอบ
array([ 0.26726124, 0.53452248, 0.80178373])
[Google Maps Geocoding] ลอง Parse Json ด้วย Groovy + Java (Netbeans)
- by Nat
โปรเจ็คตลกๆมาอีกแล้ว เพราะโปรเจ็คนี้ผมใช้ Json Lib + Groovy + Java
แต่ผมใช้ Groovy ดึง json (URL.text) แล้วใช้ Java เป็นตัวแกะ jsonObject เป็น jsonArray
หลังจากนั้นเอาข้อมูลโยนกลับไปให้ Groovy ถอดเอาเฉพาะส่วนที่ต้องการออกมา (ในที่นี้คือ coordinates — latitude ,longitude นั่นแหละ)
ดูวุ่นวายมาก ทั้งๆที่ เขียน Groovy อย่างเดียวก็ได้ เพราะ Json Lib ก็ลองรับ groovy หรือจะเขียน Java เพียวๆ เลยก็ได้
เรื่องของเรื่องคืออยากเขียน Java ร่วมกับ Groovy อีกครั้ง เพราะไม่ค่อยถูกกับ Java จริงๆ
มันดูเวื่นเว้อ มันเขียนเวิ่นเว้อด้วย ยาวๆ งงๆ (อาจเป็นเพราะไม่ได้ศึกษาอย่างลึกซึ้ง)
groovy มันสั้น เข้าใจง่าย ไม่เวิ้นเว้อ (อาจจะใช้ได้ไม่เต็มประสิทธิภาพ แต่ผมชอบ พวก Closures )
เหตุผลที่ไม่เขียน Groovy เพียวๆไปเลยก็เพราะว่า
code ตัวอย่างที่เค้ามีให้ดู มันพิมพ์ผิด
def fromList = [1,true,'json'] as JSONarray
มันควรจะต้องเป็น JSONArray เมื่อแก้และเอาอันอื่นมาลองดู มัน cast เป็น Type พวก net.sf.json.* ไม่ได้ อาการประมาณนี้
ก็เลยลองซัด Java + Groovy ไปเลย
มันก็เจอปัญหานิดหน่อยเพราะ ไม่ได้อ่าน Dependency List เลยค่อยๆตามหา พอได้ครบแล้วเพิ่งจะเห็นว่ามันมีบอกไว้ว่า
Json-lib requires (at least) the following dependencies in your classpath:
- jakarta commons-lang 2.4
- jakarta commons-beanutils 1.7.0
- jakarta commons-collections 3.2
- jakarta commons-logging 1.1.1
- ezmorph 1.0.6
น่าเขกกะโหลกจริงๆ Read this article »
[code] อัพโหลดภาพเข้า twitpic โดยใช้ api
- by NAzT
[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);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
$result = curl_exec($curl);
curl_close($curl);
$login_xml = new SimpleXMLElement($result);
if (isset($login_xml->error)) {
print_r($login_xml);
return false;
} else
{
return $login_xml;
}
}function return message ที่โพส ยังไง print_r ดูได้ครับ [Draft] : NPDigger Version Semi Auto
- by NAzT
กำลังทำ 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’) “; $this->db->where($where); $data_array['query']=$this->db->get_where(‘captcha’, array(‘userkey’ => $userkey)); $this->load->view(‘digger_getCode’, $data_array); echo “last”; // print_r($data_array['query']); }
Related Blogs
getPage และ postPage ด้วย php+cURL
- by NAzT
มีฟังก์ชั่น 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 ($curl); return $html; } //----------------------------------------------------------------------------------- //----------------------------------------------------------------------------------- function postPage($url,$pvars,$referer,$timeout){ if(!isset($timeout)) $timeout=30; $curl = curl_init(); $post = http_build_query($pvars); if(isset($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, 0); curl_setopt ($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt ($curl, CURLOPT_POST, 1); curl_setopt ($curl, CURLOPT_POSTFIELDS, $post); curl_setopt ($curl, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded")); $html = curl_exec ($curl); curl_close ($curl); return $html; } //-----------------------------------------------------------------------------------จาก http://www.tellinya.com คร้าบ
Related Blogs
- DIY Flight Simulators – Jet Fighter Multi-Function Panel | The …
- THE IDIOCY OF URL-SHORTENED HYPERLINKING Population Statistic
- HTML SQL (snoopy, extract, referer) – PHP Classes
- Twitter Tiny URL Plugin
- Change the Search Header in Zen Cart | kerrinhardy.com
- The great URL change « The Economic Voice
- Liver function and vitamins | Losogor.msk.ru music
- The Significance of A Good Website Graphic Header | Dave Dockhorn
- Happy Mother's Day and Header & Blogroll updates
- How can I take user input and save it to an XML file in PHP …
- Apache virtuAL host / HTTP REFERER?
- what size mortgage can i get
- swissmiss | HTML 5 for Web Designers
- Setting a Zend Framework _redirect Referer | stoimen.com/blog
- free std testing greenville nc
- Professional Pre Amp
- MetsBlog.com – Pre-Game: Giants vs. Mets
- Clean up extra url parameters when searching Google
- Magento- Bulk url rewrite edit | Magento Help
- Executive Committee
MPI Programming : ตอนที่ 2
- by NAzT
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
- by NAzT
กำลังสงสัยว่า
ใน 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"] ส่วน >> a[0,0] => []
เฮ่อแบบนี้ก็ต้องใช้ a[x,y] เพราะมันจะ return [] มาได้ทำให้หลุดจาก recursion
Related Blogs
- Aries 202007 Black Side Step Bar | Center Bestsellers cheaper from …
- [polls] What sort of Christian Nation should Sarah Palin's America …
- The Olive Garden's cooking school is real … sort of | Latest Buzz
- Nintendo Declares War On Apple [Blockquote] | Hirdyz Emporium
- Freedom Central – Freedom Central
- The Conrad Black Style of Doing Hard Time / Chicago News Cooperative
- Successful People Start Fast and Finish Strong | Bud Bilanich
- Opera Finds Flash Unappetizing For Web Video [Blockquote] | Gadget …
- How to Do a Mail Merge « Imogene Braggs
- Cricket Blog – Pietersen to return home
- Opera Finds Flash Unappetizing For Web Video [Blockquote]
- Ruby 1.9 Encodings: A Primer and the Solution for Rails « Katz Got …
- Infinite Scroller 2
- Infinite Scroller 2 | XDGames.net
- Adam Lambert talks makeup and style on Jonathan Ross @ Unreality TV
- Opera Finds Flash Unappetizing For Web Video [Blockquote]
- Araxis Merge Professional 2010 (Build 3829) | s?ahuj rapidshare warez
- Denard Span / Span bounced back from a rough 0-for-8 performance …
- How do I get started developing Ruby Web applications …
- Sort Files Like A Master With The Linux Sort Command (Bash)
