顯示具有 array 標籤的文章。 顯示所有文章
顯示具有 array 標籤的文章。 顯示所有文章

2015年10月5日 星期一

google sheet array串接

googlesheet如果需要將兩個array串成一個array時,使用{array1;array2}的格式。

參考資料
忘了留

2015年8月10日 星期一

apache php 接收 json

關鍵在apache的目錄必須開啟apache user讀寫權限。另外我遇到的狀況是傳送整個json檔案,因此必須使用json_decode函式將json file轉換成array才能進一步使用。
<?php
//header("Content-Type: application/json", true);

$filename = fopen('test.json', 'w');  //打開json暫存檔,'w'參數為每次打開皆清空檔案

if ( $_SERVER['REQUEST_METHOD'] === 'POST' ){ 
    $postText = file_get_contents('php://input'); 


fwrite($filename, $postText);  //寫入暫存檔
fclose($filename);  //關閉暫存檔

$url = "http://target.php";  //改成需要轉發的url

$data_decode = json_decode($postText);  //json格式解碼
$data_string = json_encode($data_decode);  //json格式編碼,這邊的目的是再將收到的json轉發出去                                                                                 
                                                                                                                     
$ch = curl_init($url);                                                                      
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                                                                      
curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
    'Content-Type: application/json',                                                                                
    'Content-Length: ' . strlen($data_string))                                                                       
);                                                                                                                   
                                                                                                                     
$result = curl_exec($ch);


}

?>

上面的範例是當對方發送json過來時,將收到的json file再轉發到另一個url的webserver。
另外jquery必須將.js嵌入網頁,可由網路或本地端,之後才可以使用。

清除舊的ubuntu repository資料
sudo sed -i -e 's/archive.ubuntu.com\|security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
sudo apt-get update

參考資料

php curl post

http://stackoverflow.com/questions/15200632/how-to-upload-file-using-curl-with-php
http://askubuntu.com/questions/9293/how-do-i-install-curl-in-php5
https://www.digitalocean.com/community/questions/installing-curl-on-ubuntu-12-04
http://blog.derakkilgo.com/2009/06/07/send-a-file-via-post-with-curl-and-php/
http://reader.roodo.com/esabear/archives/16358749.html
http://blog.roodo.com/esabear/archives/16358749.html
http://stackoverflow.com/questions/19758954/get-data-from-json-file-with-php
http://markonphp.com/php-curl-basic-post-example/
http://www.lornajane.net/posts/2011/posting-json-data-with-php-curl

php receive post

http://stackoverflow.com/questions/938811/receive-xml-file-via-post-in-php
http://stackoverflow.com/questions/19004783/reading-json-post-using-php
http://stackoverflow.com/questions/15220704/how-to-detect-if-post-is-set
http://www.blog.magepsycho.com/sending-json-data-remote-server/
http://www.php.net/manual/en/function.json-decode.php
http://codex.wiki/post/166087-764/
http://josh.gourneau.com/blog/2010/11/16/serve-json-as-content-type-applicationjson-with-apache-on-ubuntu/
https://blog-ldkrsi.rhcloud.com/php%E6%8E%A5%E6%94%B6post%E4%BE%86%E7%9A%84json%E8%B3%87%E6%96%99/
http://www.j2h.tw/bbs/bbs16/519.html
http://phpwolf.blogspot.tw/2013/08/php-post-json.html
http://stackoverflow.com/questions/18866571/receive-json-post-with-php

POST測試

https://www.hurl.it/

jquery傳送資料給php,php再回傳

https://docs.google.com/document/d/1U0n01CVFllcpd5Irzk8999x8ALHck5M4vOJizA_mYvs/pub
http://italwaysrainonme.blogspot.tw/2013/02/jqueryjsonphp-phpjsonjquery.html
http://kinomelma.pixnet.net/blog/post/30403239-%5B%E8%B6%85%E7%B0%A1%E6%98%93%5D-jquery-json-%E6%A0%BC%E5%BC%8F%E6%8E%A5%E6%94%B6%E8%88%87%E5%88%86%E6%9E%90

android溝通

http://j796160836.pixnet.net/blog/post/28994669-%5Bandroid%5D-%E4%BD%BF%E7%94%A8http%E7%9A%84post%E6%96%B9%E5%BC%8F%E5%92%8C%E7%B6%B2%E9%A0%81%E8%A1%A8%E5%96%AE%E6%BA%9D%E9%80%9A

install jquery

http://stackoverflow.com/questions/1458349/installing-jquery
http://www.mkyong.com/jquery/jquery-html-example/
https://developers.google.com/speed/libraries/#jquery
http://www.mkyong.com/jquery/jquery-hello-world/
http://expect7.pixnet.net/blog/post/37919326-%5B%E7%A8%8B%E5%BC%8F%5D%5Bjquery%5D-jquery%E4%B8%AD%E7%9A%84ajax%E7%9A%84%E5%9F%BA%E7%A4%8E%E9%81%8B%E7%94%A8%E3%80%82%E6%8F%90%E4%BE%9B%E7%AF%84
http://blog.jex.tw/blog/2013/02/19/php-json/
http://www.mkyong.com/jquery/jquery-html-example/

php server上傳

http://givemepass.blogspot.tw/2013/06/php-server.html

php fwrite example

http://php.net/manual/en/function.fwrite.php

2015年2月3日 星期二

google apps script

Google apps sript 使用for loop處理簡單的寫入時會很慢,不像excel運算的速度。因此需要簡化程式,以參考資料為例即為將每格寫入轉換成一次寫入,速度會提升很多。

另外矩陣變數則是要用"[["開頭,"]]"結尾,另外如果需要用迴圈加入單元,可以用.push(),記得變數要用var 變數 = [];。google apps script的for是小寫,我試過用大寫會無法辨識,需要注意。

在尋找字串裡的"("時,由於"("是特殊字元,必須escape,而search本身也是regular express所以要再escape一次,故應寫成search("\\(")。此時的錯誤訊息會是SyntaxError: unterminated parenthetical。

同理在取代字串的時候也會遇到regular express的問題,因為是regexp所以只會取代找到的第一個,解決方法是直接使用regexp寫法,如replace(/,/g)可取代字串中所有","。

function的部分就是直接呼叫,如HelloWorld();

replace在spreadsheet內使用的話要寫.toString().replace()才能用。還有length在計算array內字元我遇過會出錯,記得最後再加上[]。

Invalid assignment left-hand side. 我遇到的狀況是comparison的問題,就是code裡該使用"=="的地方(判斷式)用成"="(變數assign)就會出現這個error。而且這個error的debug會抓錯地方一直顯示第一行錯,所以第一次遇到會不知道發生甚麼事,連存檔都無法。

另外還有遇到一個狀況是在使用importrange公式,跑完script後會無法正常update數值,查了一下好像也有人遇到同樣情形,在google修好之前只好先用script頂著先。現象是都不會更新,將該格公式更動,或刪除復原就可以正常更新。

參考資料
基礎
https://developers.google.com/apps-script/guides/bound#creating_a_bound_script
簡化程式
http://stackoverflow.com/questions/19120211/google-script-performance-slow-down
加入公式
http://stackoverflow.com/questions/12036726/how-do-i-add-formulas-to-google-spreadsheet-using-google-apps-script
Matrix
http://stackoverflow.com/questions/15783169/convert-string-to-matrix-array
search "("
http://stackoverflow.com/questions/3977351/javascript-search-fails-to-find
replace all
http://stackoverflow.com/questions/1144783/replacing-all-occurrences-of-a-string-in-javascript
javaScript運算子
http://taiwantc.com/js/js_tut_a4.htm
javaScript字串運算
http://miisoo.blogspot.tw/2008/01/javascript-string-operations.html
Invalid assignment left-hand side.
http://stackoverflow.com/questions/11888923/what-could-cause-invalid-assignment-left-hand-side-error-message-that-doesnt
importrange issue
http://stackoverflow.com/questions/25970185/importrange-function-not-refreshing-new-entries-in-linked-google-sheet
http://stackoverflow.com/questions/22587418/new-google-spreadsheet-formula-results-different-than-what-i-see-importrange-fu?rq=1