2018年12月21日 星期五
python 開源項目列表
2018年11月17日 星期六
Markdown on Google blogger
<script src="https://cdnjs.cloudflare.com/ajax/libs/showdown/1.6.4/showdown.min.js"> </script> <script> // The > will replaced to > when using innerHTML, so replace it back to > // for showdown to render blockquote function blockquote(str) { return str.replace(/\n>/g,'\n>') ; } var converter = new showdown.Converter(); var posts = document.querySelectorAll(".post-body"); var s = ""; Array.prototype.forEach.call(posts, function(el, i) { var idx = el.innerHTML.indexOf("markdown"); if(idx != -1 && idx <= 1) { el.innerHTML = converter.makeHtml(blockquote(el.innerHTML).replace("markdown","")); var pres = el.querySelectorAll("pre"); for (var i = 0; i < pres.length; i++) { pres[i].classList.add("prettyprint"); pres[i].classList.add("linenums:1"); } } }); </script> <script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"> </script>程式相當簡單,不言自明,接著在寫 blog 時只需要注意兩件事 * 在要用 markdown 編寫的文章最開頭放一行 markdown 字串讓 script 知道這一篇文章是用 markdown 寫的,需要做轉換 * 編寫文章時要用 HTML 的模式編寫 上面的程式碼區塊除了 markdown 的轉換之外,也引用了 Google 的 prettify 函式庫來做程式碼的上色 關於程式碼上色的寫法其實跟用 markdwon 之前完全一樣,markdown 有一個好處是他跟 html 相容,你可以直接在 markdown 文件中寫 html 內容,markdown 轉換時不會去動到 html 內容的東西 比較可惜的是若程式碼內有用到角括號,還是要先將角括號轉換成 < 和 > 才能將角括號與角括號內的文字正確顯示出來 若是沒有用 < > 這類跳脫字元直接用 < > 的話,在使用 innerHTML 會被當成是 html tag 並且將角括號內的文字轉成小寫,因為 html 先天就是 case insensitive,各家瀏覽器實作時都將 innerHTML 中的 tag name 轉為小寫 這篇文章就是用 markdown 寫的,使用的感想是寫文時真的舒服多了,markdown 的一個最大優點是它很純粹,很乾淨,沒有要做的包山包海複雜化而是用一些簡單的符號做出連結、標題、段落等效果,寫 blog 其實就只需要這些功能而已,如果真的 markdown 有做不到的部分,大不了直接寫 html 在裡面就好了
2018年10月3日 星期三
Screenlighter Privacy Policy
samliu720 built the ScreenLighter app as an Ad Supported app. This SERVICE is provided by samliu720 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 ScreenLighter 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. 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.
2018年9月24日 星期一
python 2.7 exception message 無法印出中文
could not open port '123': WindowsError(2, '\xa8t\xb2\xce\xa7\xe4\xa4\xa3\xa8\xec\xab\xfc\xa9w\xaa\xba\xc0\xc9\xae\xd7\xa1C')
Google 找了很多資料,有講到用 CP950 decode 的,還有其他一些 decode 方式,不過試過後都沒用,有可能是因為網路上的範例所用的字串中還是 binary 的 data,而我遇到的情況是中文已經被轉為 \xa8t 這樣的 ASCII 字元了,所以需要找的解法應該是可以將 ASCII code 轉為 binary data 的方案
最後發現,用 "string_escape" decode 就可以達成
str(e).decode('string_escape')string_escape 的用途是把遇到 \x 後面的字串轉為 binary 的 data,而其他一般的字串就不作更動,所以只要把 exception message 整串丟給它,就會幫你轉好了,非常方便
2018年9月11日 星期二
Android vector drawable resize
因為 vector drawable 以 xml 的形式並且以 path 屬性描述圖案,所以要改變它的大小不是那麼容易,這時可以用 group 屬性來將圖案作縮小或放大
group 屬性原本是用來讓 xml 內的多個 path 包在一起讓想修改的效果同時作用在多個 path 上,但當然只有一個 path 的話也是可以用的,而 group 屬性提供的其中一種效果就是可以設定圖案的放大或縮小
可以看到 Android 官網上的說明,主要就是 pivotX、pivotY、scaleX、scaleY 這四個屬性可以作到放大縮小的效果
scale 屬性就是指定圖案要縮放的倍數,例如設為 2 就是放大為兩倍,設為 0.5 就是縮小一倍,pivot 屬性就是設定縮放的基準點位置在哪,這個會跟 drawable 的 viewportHeight 跟 viewportWidth 相關連,例如 viewportWidth 設定為 24,那 pivotX 通常會設為 12,也就是從中心點開始對圖案作縮放,例如下面的例子,就是將圖案縮小一倍
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="48dp" android:height="48dp" android:alpha="0.6" android:viewportHeight="24.0" android:viewportWidth="24.0"> <group android:scaleX="0.5" android:scaleY="0.5" android:pivotX="12" android:pivotY="12"> <path android:fillColor="#FF000000" android:pathData="M3,4L3,1h2v3h3v2L5,6v3L3,9L3,6L0,6L0,4h3zM6,10L6,7h3L9, 4h7l1.83,2L21,6c1.1,0 2,0.9 2,2v12c0,1.1 -0.9,2 -2,2L5,22c-1.1,0 -2,-0.9 -2,-2L3,10h3zM13, 19c2.76,0 5,-2.24 5,-5s-2.24,-5 -5,-5 -5,2.24 -5,5 2.24,5 5,5zM9.8,14c0,1.77 1.43,3.2 3.2, 3.2s3.2,-1.43 3.2,-3.2 -1.43,-3.2 -3.2,-3.2 -3.2,1.43 -3.2,3.2z"/> </group> </vector>