-
About Me
高雄人!
目前興趣:
量化投資、物聯網、工業 4.0主要語言: Python
主要社群:
Kaohsiung Python User Group-
Recent Posts:
Monthly Archives: July 2013
[Javascript] getCurrentPosition() + setInterval()
在WebMatrix中,嘗試跑下面的程式,想要知道Browser會不會持續report目前的位置! 結果,在WebMatrix上按下Run之後,不知為何Browser總是只有回報一次. 最後發現按下Run了之後,需要在Browser上按下refresh,新的code才會被載入.… 囧…
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<!DOCTYPE html> <html> <body> GeoLocations: <p id="demo"></p> <button onclick="myFunction()">Try It</button> <script> var x=document.getElementById("demo"); function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else{x.innerHTML="Geolocation is not supported by this browser.";} } function showPosition(position) { x.innerHTML+=Date() + "- Latitude: " + position.coords.latitude + ", Longitude: " + position.coords.longitude+"<br/>"; } function myFunction() { setInterval(getLocation,1000); } </script> </body> </html> |
[工具] 怎麼使用Visual Studio來編寫執行檔的16進位碼?
為什麼要編寫執行檔16進位碼?主要的原因,當然是因為要破解軟體. :p 你可以使用 Sublime Text, Notepad++ 加上 Plug-in 來編輯16進位碼. 如果你的電腦上面有安裝Visual Studio,其實使用Visual Studio就可以編寫16進位碼了! 使用的方法可以參考底下連結! 參考資料: Can I hex edit a file in Visual Studio?
[Python] 什麼是WSGI?
我的理解是下面這樣,錯了之後再修正! :p WSGI是Web Server Gateway Interface的縮寫,他是一個介於Web Server跟Python的Web Framework中間的中介軟體(Middleware). 定義這個Interface的優點有很多,譬如說只要符合這個介面標準的Web Server,理論上隨時抽換,程式都可以運作良好. 我目前打算使用 nginx (Web Server) + uWSGI + Flask (Web Framework) 來架個站試試看! 參考資料: Web Server Gateway Interface 化整為零的次世代網頁開發標準: WSGI
[Web] 什麼是反向代理伺服器?
不要想的太複雜,其實它就只是在伺服器端的代理伺服器,主要功能之一就是做負載平衡。 客戶端 前向代理 Internet 反向代理 伺服器 參考資料: 反向代理
[Python] CGI Programing in short
1. import cgi 2. form = cgi.FieldStorage() All key-value pairs are in form then. Reference: CGI Programming @ Tutorialspoint
[Python] [轉貼] print 跟 sys.stdout.write() 的差別
相同点:都是输出 不同点: 1、print()可以输出任何东西:字符串/数字/字典/数列等 2、sys.stdout.write()只能输出字符串。 例1: >>>for i in range(0,3): print(i) 0 1 2 但是,不能用sys.stdout.write(i)进行输出。 3、print()后面自动有回车,在sys.stdout.write()后面没有回车,如果要回车,需要增加\n。 例2: >>>import sys >>>sys.stdout.write(“itdiffer\n”) itdiffer >>> 如果写成:sys.stdout.write(“itdiffer”),则显示结果为: itdiffer>>> 參考資料: print与sys.stdout.write()
[Python] Reverse a string
1 2 |
x="Hello World!" x=x[::-1] |
[Python] Python 2.x 跟 Python 3.x 的 input()函式?
Python 2.x 跟 Python 3.x 的 input 的定義似乎不太一樣。 在 Python 2.x 中,input() 可以用來讀取使用者輸入的數值資料或算式,但是如果輸入未被定義的字串,則會出現錯誤。 在 Python 3.x 中,好像沒有這個問題。 在 Python 2.x 中,如果要讀入字串,需要使用 raw_input()。
[Python] 開啟檔案時的 encoding=”utf-8″的選項?
看到網路上很多Python 3的檔案操作範例裡面使用:
1 |
file = open(name, 'w', encoding = 'UTF-8') |
在Python 2.7裡面執行時,出現如下錯誤訊息: Traceback (most recent call last): File “C:/Users/Victor/Documents/python/FileIO/WriteToFile01.py”, line 10, in file = open(name, ‘w’, encoding = ‘UTF-8’) TypeError: ‘encoding’ is an invalid keyword argument for this function 怎麼辦? 最簡單的解法就是:
1 |
import io |
使用io.open(),但是需注意的是,這樣做讀寫檔案的速度會比較慢! 參考資料: Backporting Python 3 … Continue reading