符號 說明
# id屬性
. class屬性
[] 自訂屬性
> 子元素
+ 兄弟元素
^ 升層
* 複製數量
$ 增量變數
$$ 增量變數(2位數)
{} 文字節點

$location Service (window.location)

用途: redirect action

path()

使用者可以使用『上一頁』的功能

1
2
3
$location.path(); // 取得目前的路徑

$location.path('path');//改變路徑

replace()

使用者沒有辦法使用『上一頁』

1
2
3
4
5
6
$location.path('path');
$locaton.replace();

// or

$location.path('path').replace()

absUrl()

取得完整的路徑

hash()

取得 # 之後的內容

get/set search part of the current URL

url()

get the URL of the current page

目的: 取得最後一筆的聊天紀錄

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
var result = (from o in db.messages
let msgFrom = o.fromUid == uid
let msgTo = o.toUid == uid
where msgFrom || msgTo
group o by msgTo ? o.fromUid : o.toUid into grp
let lastDate = grp.Max(m => m.createDate)
from p in grp
where p.createDate == lastDate
select new viewMessage
{
uid = p.fromUid == uid ? p.toUid : p.fromUid,
name = p.fromUid == uid ? p.toemployees.name : p.fromemployees.name,
msg = p.msg,
lastdate = p.createDate,
unread = p.unread
}).AsEnumerable();

緣由:Bluhost決定將所有的php版本升級到5.4.20, 那這樣子的行為會讓phalcon.so(php 5.3.27版本) 失效,然後問Bluehost, 他們不會提供降級的服務,也不會幫忙complie phalcon.so…所以,自己做。

作法:設定一個跟網頁空間一樣的環境, same os and php version, 然後在編譯phalcon, 成功編譯後上傳phalcon.so到主機上面。

步驟: 我是選擇centos6版,下載與主機服務商一樣作業位元的作業系統. (64bit or 32bit)

  1. http://isoredirect.centos.org/centos/6/isos/x86_64/ <= 64位元的版本
  2. 用Vmware將centos裝起來.
  3. 安裝完成後,用root的帳號登入,開啟terminal window
  4. 由於第一次安裝,所以先執行 yum update 讓系統先將所有的套件更新到最新的狀態
  5. yum groupinstall "Development Tools" 安裝一些跟開發有關係的元件,例如 git (必須安裝)
  6. 安裝rpm yum repository information, 因為php5.4是在不同的repository. 安裝方式如下 rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm
  7. 可以用 yum list | grep php 顯示跟php有關的套件。php54w就是我們要安裝的套件
  8. 要安裝以下套件 yum install php54w php54w-mysql php54w-devel
  9. 利用git取得phalcon git clone --depth=1 git://github.com/phalcon/cphalcon.git
  10. cd cphalcon/build
  11. ./install
  12. 如果complie成功, 會出現下面的畫面 2013-12-8 上午 12-38-32.png
  13. complie完後的檔案可以在build/modules/紅色框起來的資料夾下面看到 2013-12-8 上午 12-39-07.png
  14. 將phalcon.so複製到網頁空間主機php放extensions的資料夾下,並編輯php.ini啟動phalcon.so
  15. 打完收工

#流程

  1. 從gmail裡面讀取電子報(特定的寄件者)
  2. 取得郵件內容
  3. 分析html
  4. 取得所要的部份(s)
  5. 將要轉錄的文章發布到wordpress上
  6. 將已處理的信件從收件夾中移到另一個資料夾中
  7. 結束作業

#開發環境 python 3.3

#有用到的package

  • imaplib --> 用來處理imap type email
  • email --> email結構
  • re
  • BeautifulSoup4 --> work with python 3.3 --> from bs4 import BeautifulSoup
  • wordpress_xmlrpc --> 透過xmlrpc的方式新增文章

所遇到的問題

  1. 編碼 a. 信件 b. 信件內容
  2. html形式的email裡面藏有\xa0 , 還是因為編碼的關係

其實在使用bs4的過程中,也是花最多時間的地方是如何讓中文正常的顯示出來。其實在第一段要取得信件裡的內容時,就遇到中文編碼的問題。

demo 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import imaplib,email,re
from email.header import decode_header
from bs4 import BeautifulSoup
from wordpress_xmlrpc import Client,WordPressPost,WordPressPost,WordPressTerm
from wordpress_xmlrpc.methods import posts
from wordpress_xmlrpc.methods.posts import NewPost,EditPost
from wordpress_xmlrpc.methods.users import GetUserInfo

# 這樣子可以傳回中文字
def decode_subject(subject,encoding):
if encoding == None:
return subject
else:
return subject.decode(encoding)
# 用意跟上面的一樣, 只是為了處理編碼的問題
def showmessage(mail):
if mail.is_multipart():
for part in mail.get_payload():
showmessage(part)
else:
type = mail.get_content_charset()
if type == None:
return mail.get_payload()
else:
try:
return mail.get_payload(decode=1).decode(type)
except UnicodeDecodeError:
return mail

conn = imaplib.IMAP4_SSL("imap.gmail.com", 993)
conn.login('account','password)
conn.select("inbox") # connect to inbox.
typ, data = conn.search(None, 'ALL')
try:
for num in data[0].split()[-1:]: #從最新的信件開始讀起
typ, msg_data = conn.fetch(num, '(RFC822)')
for response_part in msg_data:
if isinstance(response_part, tuple):
msg = email.message_from_string(response_part[1].decode())
subject,encoding = decode_header(msg['subject'])[0]
mailsubject = decode_subject(subject,encoding)
#_from = msg['from']
body = showmessage(msg) # 編碼轉換
# 分析並將轉錄到wordpress上
for link in soup.find_all("table")[8:]:#start with 8th table element content = link.encode('big5').decode('cp950')
if content.find('class="contentword"') > -1:
news = BeautifulSoup(content)
for part in news.find_all('tr'):
td = part.find_all("td")
title = td[0].get_text()
puretext = re.sub('(\xa0)+',' ',td[1].get_text())
if title == '公布日期':
publishdate = puretext
elif title=='標題':
posttitle = puretext
elif title=='詳細內容':
postcontent = puretext
postToWP.post(posttitle,postcontent,"post tag")
move_mail(conn,num,'Archive.Today')
finally:
try:
conn.close()
except:
pass
conn.logout()

在3.3裡, email.message_from_string 傳進去的文字如果不加decode,會傳錯誤訊息出來。

1
email.message_from_string(response_part[1].decode())

發布文章到wordpress 參考網址: http://python-wordpress-xmlrpc.readthedocs.org/en/latest/index.html

class postToWP:
    def post(title,content,tag):
        client = Client('http://blog url//xmlrpc.php', 'username', 'password')        
        post = WordPressPost()
        post.title = title
        post.content = content
        post.terms_names = {
        'post_tag': [tag],              # 標籤(Tag)
        'category': [tag],              # 分類(Categories)
        }      
        post.post_status = 'publish'    # 如果沒有這一個,就會是草稿狀態
        post.id = client.call(NewPost(post))

#Grunt Need: Node.js installed

Install Steps

  1. Installing the CLI run command
1
npm install -g grunt-cli
  1. edit package.json and Gruntfile.js
1
2
3
4
5
6
{
"devDependencies": {
"grunt": "0.4.1",
"grunt-ts": "latest"
}
}

run npm install in command

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
module.exports = function (grunt) {
// load the task
grunt.loadNpmTasks('grunt-ts');

// Configure grunt here

grunt.initConfig({
ts: {
dev: {
// a particular target
src: ['app/**/*.ts'], // The source typescript files, http://gruntjs.com/configuring-tasks#files
html: ['app/**/*.html'], // The source html files, https://github.com/basarat/grunt-ts#html-2-typescript-support
reference: './reference.ts', // If specified, generate this file that you can use for your reference management
out: 'app/app.js', // If specified, generate an out.js file which is the merged js file
watch: 'app',
},
},
});
grunt.registerTask('default', ['ts:dev']);
};

run grunt in command

這樣子 grunt 就會監控 在 app 資料夾下的 ts 檔案異動,並同時做 complie 的動作,如果有錯誤,會產生 complie error 的訊息。

In projectname.csproj 新增

 <PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <TypeScriptTarget>ES3</TypeScriptTarget>
    <TypeScriptIncludeComments>true</TypeScriptIncludeComments>
    <TypeScriptSourceMap>true</TypeScriptSourceMap>
    <TypeScriptModuleKind>AMD</TypeScriptModuleKind>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <TypeScriptTarget>ES3</TypeScriptTarget>
    <TypeScriptIncludeComments>false</TypeScriptIncludeComments>
    <TypeScriptSourceMap>false</TypeScriptSourceMap>
    <TypeScriptModuleKind>AMD</TypeScriptModuleKind>
  </PropertyGroup>
  <Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />

在重新載入專案

#Form Validation with angularJs Basic: in .js $scope.form = {} $scope.form.$valid ==> 判斷form(name=「form」)內的物件是否有驗證有錯誤的物件存在

用法: formName.inputFieldName.property

Unmodified form A boolean property that tells us if the user has modified the form. This is true if the user hasn’t touched the form, and false if they have:

1
formName.inputFieldName.$pristine;

Modified form A boolean property if and only if the user has actually modified the form. This is set regardless of validations on the form:

1
formName.inputFieldName.$dirty

Valid form A boolean property that tells us that the form is valid or not. If the form is currently valid, then this will be true:

1
formName.inputFieldName.$valid

Invalid form A boolean property that tells us that the form is invalid. If the form is currently invalid, then this will be true:

1
formName.inputFieldName.$invalid

The last two properties are particularly useful for showing or hiding DOM elements. They are also very useful when setting a class on a particular form.

Errors Another useful property that AngularJS makes available to us is the $error object. This object contains all of the validations on a particular form and if they are valid or invalid. To get access to this property, use the following syntax:

1
formName.inputfieldName.$error

###Addtional CSS classes ng-valid Is set if the form is valid. ng-invalid Is set if the form is invalid. ng-pristine Is set if the form is pristine. ng-dirty Is set if the form is dirty.

##Input Validation

1
2
3
4
5
6
7
8
9
10
<input
ng-model="{string}"
[name="{string}"]
[required]
[ng-required="{boolean}"]
[ng-minlength="{number}"]
[ng-maxlength="{number}"]
[ng-pattern="{string}"]
[ng-change="{string}"]>
</input>

####可驗證項目(內建) requried ng-minlength ng-maxlength

####$error所對應的項目 formName.inputfieldName.$error.requried formName.inputfieldName.$error.minlength formName.inputfieldName.$error.maxlength

民國103年1月1日起,網際網路電子發票開始限制發票字軌只能使用丁種字軌,然後又推說如果利用網際網路電子發票開立B2B交易情形,只能接受丁種字軌,這表示,另外一方也必須用網際網路電子發票…看來國稅局在103年度要強推B2B的電子發票了。

不管怎樣,這個也是一個趨勢,雖然現在開立的方法或是平台(還得獎…這好笑了吧, 請個F2E處理一下你的頁面吧。還是說設計者都沒有自己操作過)都還很鳥,如果要利用媒體檔上傳的方式,這個門檻又很高,因為那個該死的規格書又寫的很艱澀。(只是要罵一下)…

帳號申請網址:電子發票整合服務平台

還是稍微整理一下開立流程:

一般開立

  1. 賣方開立發票
  2. 買方收到開立通知
  3. 買方接收開立發票
  4. 賣方收到接收通知
  5. 完成開立動作

退回發票

  1. 賣方開立發票
  2. 買方收到通知
  3. 買方退回發票
  4. 賣方確認發票退回
  5. 完成動作

作廢發要

  1. 賣方作廢發票
  2. 買方收到通知
  3. 買方確認發票作廢
  4. 完成動作

B2B交換資料,發票狀態有幾種,其意義為何?

銷項發票狀態 開立 :已新增發票,尚未憑證寄送 已寄送:已憑證寄送,資料傳送中 已讀取:買方已讀取 尚未完成進項發票寄送確認 已確認:買方已完成進項發票寄送確認 進項發票狀態 開立   :賣方已憑證寄送發票,買方尚未讀取 已讀取  :買方已讀取發票,尚未完成進項發票寄送確認 確認寄送中:進項發票寄送確認,資料傳送中 已確認  :買方已完成進項發票寄送確認

買方營業人若無工商憑證是否可接收發票?

請賣方營業人至基本資料/交易對象資料維護建立買方資料並設定交易暗語,買方即可以交易暗語寄送發票。 惟作廢發票及發票退回確認僅能使用憑證接收,不得使用交易暗語接收。

Tuples

很像list,但是一旦建立後值就沒有辦法被更改 (ex. list[1]= 『b』 <=會出錯) 用途: 用來儲存一些常用(const)變數

Set

set會將重複得值給排除掉(有distinct的味道) 建立set的方式有set() 或 a= {『something』,『something』} 如果要建立空的set,只能透過set()的方式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
>>> a = set('abracadabra')
>>> b = set('alacazam')
>>> a
{'d', 'r', 'a', 'c', 'b'}
>>> b
{'m', 'l', 'a', 'c', 'z'}
>>> a^b # value in a or b not in both, 不含兩邊都有值
{'r', 'z', 'd', 'b', 'm', 'l'}
>>> a-b # value in a not b
{'d', 'b', 'r'}
>>> a|b # value in a or b
{'r', 'z', 'd', 'a', 'c', 'b', 'm', 'l'}
>>> a&b # value in a and b
{'a', 'c'}

#Dictionaries as c# Dictionary<string, string> 操作方式

  • 指定: dict[key]= value
  • 刪除: del dict[key]
  • 列表: list(dict.key())
  • 排序: sorted(dict.key())

建立的方式

1
2
3
4
>>> dict([('sape', 4139), ('guido', 4127), ('jack', 4098)])
{'sape': 4139, 'jack': 4098, 'guido': 4127}
>>> dict(sape=4139, guido=4127, jack=4098)
{'sape': 4139, 'jack': 4098, 'guido': 4127}

##looping

1
2
3
4
5
6
>>> knights = {'gallahad': 'the pure', 'robin': 'the brave'}
>>> for k, v in knights.items():
... print(k, v)
...
gallahad the pure
robin the brave

#More on Conditions 比較的方法:

  • in, not in
  • is, is not
  • and, or : 當遇到第一個成立條件時,就跳出了

比較可以連續串接: eg: a<b==c tests whether a is thess then b and moreover b equals c

比較的順序: 左到右