View gist:d55c91376228659f3207
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function truncate(s, n, tail) | |
local c = 0 -- 判斷字寬, 中文: 2, 西歐字母: 1 | |
local c2 = 0 -- 判斷字元 (中文大部分3byte, TODO) | |
local add_tail = false | |
local r = "" | |
for i in s:gmatch("[\1-\127\194-\244][\128-\191]*") do | |
if c > n then | |
add_tail = true | |
break | |
end |
View mb_len.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function mb_len(s) | |
local c = 0 -- 判斷字寬, 中文: 2, 西歐字母: 1 | |
local c2 = 0 -- 判斷字元 (中文大部分3byte, TODO) | |
local add_tail = false | |
local r = "" | |
for i in s:gmatch("[\1-\127\194-\244][\128-\191]*") do | |
if string.byte(i) > 127 then | |
c = c + 2 | |
c2 = c2 + 3 | |
else |
View landsat5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -.- coding: utf-8 -.- | |
""" | |
Usage: | |
landsat5.py <username> <password> | |
Requirements: | |
beautifulsoup4==4.0.5 | |
requests==2.0.1 |
View gist:5e7842bddadf928a09a7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:(function(){t='['+decodeURIComponent(document.title)+']('+decodeURIComponent(window.location.href)+')';win=window.open('','_new','location=no,links=no,scrollbars=no,toolbar=no,width=550,height=150');win.document.write('<form><textarea%20name="a"%20rows="5"%20cols="50"%20onClick="javascript:this.form.a.focus();this.form.a.select();">'+t+'</textarea></form>');})() |
View elisp 跑步計算機
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun run-calc (d hh mm ss) | |
"running calculator" | |
(interactive "nDistance (km): \nnHours: \nnMinutes: \nnSeconds: ") | |
(let ((km (* d 1000)) | |
(tm (+ (* hh 3600) (* mm 60) ss))) | |
(setq hkm (/ tm d 60.0)) | |
(setq hkm-m (/ tm d 60)) | |
(setq hkm-s (% (/ tm d) 60)) | |
(setq mpr (/ tm d 2.5))) ;;沒有進位 | |
(message "%dkm, %02d:%02d:%02d => %.2f m/km (%dm%ds), %.2f s/round" d hh mm ss hkm hkm-m hkm-s mpr) |
View gist:6589902
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local function info() | |
print("========= display info =========") | |
print(string.format("pixel: %dx%d, ratio: %.02f", | |
display.pixelWidth, | |
display.pixelHeight, | |
display.pixelHeight/display.pixelWidth)) | |
print(string.format("content: %dx%d, ratio: %.02f", | |
display.contentWidth, | |
display.contentHeight, | |
display.contentHeight/display.contentWidth)) |