2011/02/28

Manifest - update

mainfest 幾時先用update 呢~?
係得原本個manifest file 的content 有變

試過用touch 改個timestamp ... 唔得
改左cache 的嗰d file ...唔得
改manifest 的名... 唔得 (因為那版 cache 了)

manifest syntax

MANIFEST

CACHE MANIFEST
 
CACHE: 
#要cahce的file 放在下面, relative path 同實path 都ok
#但一定要有file 名, 唔可以用* 
img/cat.jpg
img/dog.jpg
img/bird.jpg
img/rabbit.jpg
img/mouse.jpg
img/ant.jpg
 
NETWORK: 
#要從network 拎的file 放呢度 (e.g api)
#用 * 就即係除左cache下面的file 都從network 拎
* 
 
FALLBACK:
#拎唔到file 時的替代方案
api/ api/index.html 

Manifest - cache page

manifest 會自動cache 了有 <html mani....> tag 的那版, 有人會用iframe 的方法避了它...
firefox 同chrome 同 pc safari 都ok gei (cache 到d file, 唔會每次次再d/l)
但去到手機就...... x_x

iphone 的safari ok, 好正常, 但用add to home screen 開就唔得了 (用唔到cache 的file, 每次要上網拎)
android 2.0 以下唔支援html5, 所以唔會cache 到
android 2.1 同android 2.2 都用唔到cache 的file

所以手機 + iframe 是廢的, 加上iframe 是不鼓勵用的

Make HTTP / XML request in API and Parse result (PHP)

for美國郵政局,using simple XML request, include the XML within the url with the registered userID,
it will then return XML result in similar format
http://www.usps.com/webtools/htm/Track-Confirm.htm

Test Request #1

http://SERVERNAME/ShippingAPITest.dll?API=TrackV2&XML=

<TrackRequest USERID="xxxxxxxx">
<TrackID ID="EJ958083578US">
</TrackID>
</TrackRequest>

Example
$xml ='http://testing.shippingapis.com/ShippingAPITest.dll?API=TrackV2&XML=';
$xml.= '<TrackRequest USERID="'.$usps_id.'">';
$xml.= '<TrackID ID="'.$usps_track_id.'">';
$xml.= '</TrackID></TrackRequest>';

$xml_file = urlencode($xml);

    if( ! $xml = simplexml_load_file($xml_file) )
    { 
        echo 'unable to load XML file';
    }
    else
    { 
        foreach( $xml as $user )
        {
            echo 'TrackSummary: '.$user->TrackSummary.'<br />';
for ($i=0;$i<count($user->TrackDetail);$i++){
echo 'TrackDetail: '.$user->TrackDetail[$i].'<br />';
}
        }
    }


EBay
SOAP API  request can be posted by CURL which is an extension in PHP.
E.g. ebay api, using CURL,data in xml and header can be make into HTTP request to the specific URL

 $endpoint = 'https://api.ebay.com/ws/api.dll';
    // create the xml request that will be POSTed
    $xmlRequest  = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
    $xmlRequest .= ".........";


    $session  = curl_init($endpoint);                       // create a curl session
    curl_setopt($session, CURLOPT_POST, true);              // POST request type
    curl_setopt($session, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($session, CURLOPT_POSTFIELDS, $xmlRequest); // set the body of the POST
    curl_setopt($session, CURLOPT_RETURNTRANSFER, true);    // return values as a string - not to std out
    $headers = array(
      'X-EBAY-API-COMPATIBILITY-LEVEL: 643',
      'X-EBAY-API-DEV-NAME: ...........
//input your required a/c info
      'X-EBAY-API-SITEID: 0',                                 // Site 0 is for US
      'Content-Type: text/xml;charset=utf-8'
    );
    curl_setopt($session, CURLOPT_HTTPHEADER, $headers);    //set headers using the above array of headers

    $responseXML = curl_exec($session);                     // send the request
    curl_close($session);

//    print_r($responseXML);

ebay (Alternative)

但以上的CODE太麻煩, 次次都要人手對番那串極長的xml request, 再insert對應不同api的parameter太費時了,  所以ebay 有sdk for php 給人下載, 名為PHP Toolkit with 527 Support
file名係EbatNs_1_0_527_0, 內置了所有api, 只要在config 輸入appid 等info便可即時調用

 $session = new EbatNs_Session('../EbatNsSamples/config/ebay.config.php');
 $cs = new EbatNs_ServiceProxy($session);
 // Set the Request type
 //#type $req GetSellerListRequestType
 $req = new GetSellerListRequestType();



PHP Toolkit Samples 有齊各api的sample code, copy & paste 改variable數值就可以了

Combine use of "group_concat" and "having" inside "group by"

select count(*),sum(sale_price),REPLACE(group_concat(sales_id),',','<br/>') from ebay_sold
group by sale_date
having sum(sale_price) >100

Cannot connect to MYSQL externally via software

An example of how to add SELECT privileges to a user using GRANT

GRANT SELECT ON db_base.* TO db_user@'localhost' IDENTIFIED BY 'db_passwd';
If SELECT is not enough for our user we can add more privileges using a query similar to the one below:


An example of how to add a selection of privileges to a user using GRANT

GRANT SELECT, INSERT, DELETE ON db_base.* TO db_user@'localhost' IDENTIFIED BY 'db_passwd';
If you want to GRANT ALL the privileges to a user then use this query:
An example of how to Grant Privileges in MySQL

GRANT ALL PRIVILEGES ON db_base.* TO db_user @'%' IDENTIFIED BY 'db_passwd';
As you see in the latest example we use '%' instead of localhost, which means that our user can use all the privileges from every host.


Sometimes you need to grant privileges to a user for a specific table. To specify the table, replace '*' in 'db_base.*' with your table's name.

An example of how to Grant Privileges in MySQL

GRANT ALL PRIVILEGES ON db_base.phonebook TO db_user @'%' IDENTIFIED BY 'db_passwd';
Once you have given the desired privileges for your user, you will need to FLUSH privileges in order to complete the setup and to make the new settings work. To do so, run this command within the SQL command prompt:

FLUSH PRIVILEGES;

2011/02/27

Manifest - by url

為了減了load 網頁的時間 同 少d 流量
試用了html5 的新feature, MANIFEST

 
manifest 是用url 來認的, 所以如果url唔同左manifest 就用唔到 or 要再d/l 過d file
e.g manifest在 www.example.com/main.do?action=view d/l 好了
下次load 的時候是 www.example.com/main.do?action=search, 咁之前的manifest 就用唔到, 而個website 又要再d/l 過d file 了...

 
仲有 同一個domain/ origin 只會儲存一個manifest, 所以如果我去左www.example.com/action.do 就會cover 左上一張~_~