code

2019年5月9日 星期四

Android Privacy Policy

Privacy Policy

DeanHuang built the Chinese Conversation Practice app as an Ad Supported app. This SERVICE is provided by DeanHuang at no cost and is intended for use as is.

This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service.

If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy.

The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which is accessible at Chinese Conversation Practice unless otherwise defined in this Privacy Policy.

Information Collection and Use

For a better experience, while using our Service, I may require you to provide us with certain personally identifiable information, including but not limited to audio. The information that I request will be retained on your device and is not collected by me in any way.

The app does use third party services that may collect information used to identify you.

Link to privacy policy of third party service providers used by the app

Log Data

I want to inform you that whenever you use my Service, in a case of an error in the app I collect data and information (through third party products) on your phone called Log Data. This Log Data may include information such as your device Internet Protocol (“IP”) address, device name, operating system version, the configuration of the app when utilizing my Service, the time and date of your use of the Service, and other statistics.

Cookies

Cookies are files with a small amount of data that are commonly used as anonymous unique identifiers. These are sent to your browser from the websites that you visit and are stored on your device's internal memory.

This Service does not use these “cookies” explicitly. However, the app may use third party code and libraries that use “cookies” to collect information and improve their services. You have the option to either accept or refuse these cookies and know when a cookie is being sent to your device. If you choose to refuse our cookies, you may not be able to use some portions of this Service.

Service Providers

I may employ third-party companies and individuals due to the following reasons:

  • To facilitate our Service;
  • To provide the Service on our behalf;
  • To perform Service-related services; or
  • To assist us in analyzing how our Service is used.

I want to inform users of this Service that these third parties have access to your Personal Information. The reason is to perform the tasks assigned to them on our behalf. However, they are obligated not to disclose or use the information for any other purpose.

Security

I value your trust in providing us your Personal Information, thus we are striving to use commercially acceptable means of protecting it. But remember that no method of transmission over the internet, or method of electronic storage is 100% secure and reliable, and I cannot guarantee its absolute security.

Links to Other Sites

This Service may contain links to other sites. If you click on a third-party link, you will be directed to that site. Note that these external sites are not operated by me. Therefore, I strongly advise you to review the Privacy Policy of these websites. I have no control over and assume no responsibility for the content, privacy policies, or practices of any third-party sites or services.

Children’s Privacy

These Services do not address anyone under the age of 13. I do not knowingly collect personally identifiable information from children under 13. In the case I discover that a child under 13 has provided me with personal information, I immediately delete this from our servers. If you are a parent or guardian and you are aware that your child has provided us with personal information, please contact me so that I will be able to do necessary actions.

Changes to This Privacy Policy

I may update our Privacy Policy from time to time. Thus, you are advised to review this page periodically for any changes. I will notify you of any changes by posting the new Privacy Policy on this page. These changes are effective immediately after they are posted on this page.

Contact Us

If you have any questions or suggestions about my Privacy Policy, do not hesitate to contact me at lylis660@gmail.com.

This privacy policy page was created at privacypolicytemplate.net and modified/generated by App Privacy Policy Generator

2017年1月18日 星期三

Nodejs取得銀行匯率


要取得銀行匯率,需要對網頁原始碼做一些轉換,這裡使用cheerio,因此一開始要先安裝這個套件:
npm install cheerio

匯率方面,採用玉山銀行的匯率網頁。為什麼選擇玉山?因為它的網頁原始碼比較容易抓匯率。

首先取得匯率網頁的全部原始碼:
var request = require("request");
// 玉山銀行匯率
var url = "https://www.esunbank.com.tw/bank/personal/deposit/rate/forex/foreign-exchange-rates";
// 取得網頁資料
request(url, function (error, response, body) {
    if (!error) {        
        console.log(body);  // body是網頁原始碼 
    } else {
        console.log("擷取錯誤:" + error);
    }
});

玉山銀行的匯率表格叫做inteTable


其中貨幣資料在inteTable下的<tr class="tableContent-light">

現在用cheerio抓出各貨幣的資料:
// 用 cheerio 解析 html 資料
var $ = cheerio.load(body);
// 搜尋各種貨幣的匯率
var queryResult = []
$('.inteTable tr.tableContent-light').each(function(i, elem){
    queryResult.push($(this).text().split('\n')); // 把搜尋結果存到array
});
其中".inteTable tr.tableContent-light"的意思是「抓取class名字為inteTable下的tr標籤,這個tr標籤class名字是tableContent-light」
如果這時候把queryResult輸出結果如下:

[ [ '\r',
    '                \r',
    '                    美元(USD)\r',
    '                31.54\r',
    '                31.64\r',
    '\r',
    '                31.34\r',
    '                31.79\r',
    '            ' ],
...(下略)
可以看到輸出很雜亂,有很多不必要的空格,所以要再整理一下。這邊就不單獨列出程式碼了。

完整程式碼如下:
var request = require("request");
var cheerio = require("cheerio");

// 玉山銀行匯率
var url = "https://www.esunbank.com.tw/bank/personal/deposit/rate/forex/foreign-exchange-rates";
// 取得網頁資料
request(url, function (error, response, body) {
    if (!error) {
        // 用 cheerio 解析 html 資料
        var $ = cheerio.load(body);
        // 搜尋各種貨幣的匯率
        var queryResult = []
        $('.inteTable tr.tableContent-light').each(function(i, elem){
            queryResult.push($(this).text().split('\n')); // 把搜尋結果存到array
        });

        // 整理搜尋結果
        var output = []
        for(var i=0; i<queryResult.length; i++) {
            output.push({
                coin: queryResult[i][2].replace(/\s/g, ""), // 貨幣
                in: queryResult[i][6].replace(/\s/g, ""), // 現金買入
                out: queryResult[i][7].replace(/\s/g, "") // 現金賣出
            });
        }
        console.log(output); 
    } else {
        console.log("擷取錯誤:" + error);
    }
});
輸出:

[ { coin: '美元(USD)', in: '31.34', out: '31.79' },
  { coin: '人民幣(CNY)', in: '4.558', out: '4.688' },
  { coin: '港幣(HKD)', in: '4.013', out: '4.133' },
  { coin: '日圓(JPY)', in: '0.2757', out: '0.2817' },
  { coin: '歐元(EUR)', in: '33.26', out: '34.26' },
  { coin: '澳幣(AUD)', in: '23.49', out: '24.29' },
  { coin: '加拿大幣(CAD)', in: '23.75', out: '24.55' },
  { coin: '英鎊(GBP)', in: '38.39', out: '39.39' },
  { coin: '南非幣(ZAR)', in: '', out: '' },
  { coin: '紐西蘭幣(NZD)', in: '', out: '' },
  { coin: '瑞士法郎(CHF)', in: '', out: '' },
  { coin: '瑞典幣(SEK)', in: '', out: '' },
  { coin: '新加坡幣(SGD)', in: '', out: '' },
  { coin: '墨西哥披索(MXN)', in: '', out: '' },
  { coin: '泰銖(THB)', in: '', out: '' } ]

如果要取值出來用,以日圓買進為例:
output[3]["in"]
輸出會是
0.2757
以上就是NodeJS取得銀行匯率的教學。

2017年1月10日 星期二

Smart7688Duo-使用Arduino控制UVC Camera

聯發科的Smart 7688 DUO要使用UVC camera來做影像監視串流很簡單,不過網路上搜尋到的資料大都兩種教學:
  1. 透過終端機輸入指令
  2. 用聯發科的MCS網頁完成
第一種不實用。第二種自己使用還可以,但若要變成產品的話,不太可能依靠別人的網頁來生產。

一般監視產品,應該會透過兩種方式開啟監控:
  1. 硬體觸發
  2. 網路啟動
硬體觸發指的是有直接連接到Smart7688的按鈕開關或是感知器(如人體感知器),透過電位的High/Low來啟動監視。網路啟動則是透過例如手機傳遞指令,來開關監控。

這篇主要介紹硬體觸發,不過為了簡單,不會真的連接感知器,而是透過Serial Port輸入0/1模擬電位的High/Low。

程式主要是Arduino完成的。

首先需要知道開啟camera的Shell指令;
mjpg_streamer -i "input_uvc.so -f 20 -d /dev/video0" -o "output_http.so"
網路上一般7688教學文章都是透過終端機輸入的,我們要想辦法透過Arduino輸入這串指令。

整個程式架構大概長這樣;
sensorValue = Serial.read() # 讀取輸入
if sensorValue == 1 {
    # 使用上面Shell command開啟camera
} else {
    # 關閉camera
}

接下來要知道Arduino怎麼執行Shell指令:
Process p;
p.runShellCommand(Shell Command);

不過用Process之前要先透過終端機開啟bridge,不然無法用Arduino控制
root@mylinkit:~# uci set yunbridge.config.disabled='0'
root@mylinkit:~# uci commit
root@mylinkit:~# reboot


完整Arduino程式碼:
#include <Bridge.h>

void setup() {
  Bridge.begin();
  Serial.begin(115200);
  while (!Serial);
}

void loop() {
  int c = Serial.read();  
  if (c != -1) {
    switch(c) {
    case '0':      
      disableCamera();
      break;
    case '1': 
      enableCamera();
      break;
    }    
  }  // End if
}

void enableCamera() {
  Serial.println("Enable UVC camera");
  
  Process p;
  p.runShellCommand("mjpg_streamer -i \"input_uvc.so -f 20 -d /dev/video0\" -o \"output_http.so\" &");    
}

void disableCamera() {
  Serial.println("Disable UVC camera");
  
  Process p;
  p.runShellCommand("killall mjpg_streamer");  
}


2016年12月10日 星期六

用Sublime當Python IDE編譯器

先到Sublime官網下載


開啟Sublime後,輸入CTRL + `  (數字1左邊那個)


在下方指令列輸入以下字串,安裝Pakcage controll:
import urllib.request,os,hashlib; h = 'df21e130d211cfc94d9b0905775a7c0f' + '1e3d39e33b79698005270310898eea76'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)

之後選擇Preferences -> Package Control


輸入install選擇'Install Package'


然後輸入你想安裝的Pakcage。Sublime有許多套件可以用來開發Python,你可以Google "Sublime Python"來搜尋相關資訊。這邊我選用Anaconda。


之後進入Preference -> Package Settings -> Anaconda -> Settings - Default進行設定。


許多人會設定這兩個參數
"complete_parameters": true,
"complete_all_parameters": true,

引用函數的時候會自動幫你填寫參數。我沒有使用,因為覺得使用print()的時候列出一堆沒有用到的參數,要再砍掉很煩。


另外我會設定
"anaconda_linting": false,
當這個值是true的時候,你會發現出現一堆白色邊框

設定false就會不見。

最後,寫好程式碼要編譯,輸入CTRL + b即可。

Python: for-else



最近剛接觸Python, 碰到了之前其他程式語言沒有的for-else語法,紀錄一下。

for-else的else內容,主要是執行完for之後會執行的。
例如:

輸出是:
0
1
2
3
4
End for

可以看見先執行完全部的print(n)之後,等for結束後再執行else內容。

如果for內有break跳出的話,不會執行else內容。
例如:

輸出是:
0
1
2
3

在n==4的時候break,所以沒有印4與5,並且else內容也沒印了。

那麼,for-else會用在什麼時候呢?目前想到的是,處理for都沒有想要的結果的時候。例如,我要在尋找某個數字,如果找到就印出來,沒找到就顯示找不到。
以前我會用這種寫法:

多一個flag紀錄是否有找到,並且在後面要有一個if-else判斷。

現在不需要,直接融合在一起:


另外,Python是很注重tab的語言,很多時候少了tab會有error或者出現不一樣的結果。for-else也是。

輸出是:
沒找到
沒找到
沒找到
沒找到
我找到了4

else前面多了tab縮排,這時候會被判斷程if-else與法而不是for-else。

剛學python,只想到這樣,如果有更實用的方法可以提供喔!