What the hell is SOA?

SOA stand for service oriented architecture, has nothing to do with technology being used.
只是一種架構規範,與技術無關.

Define :
Unit – a unit can provide many service, for example a school department is a unit.
Service – an independent logic/process, such as registration service of administration department.
定義 :
單位 – 可以提供多種服務,例如學校行政組
服務 – 一個獨立的邏輯/流程,例如行政組的入學登記服務

SOA purpose is to let those services continuously being developed and accumulate, running separately. Cluster into new service.
In developer point of view. They should think of how to develop service instead of application. Think of stacking old services
to create new service. And the terminal of this is applications which consume services. In other word, think in the service oriented way.
SOA目的,讓服務可以持續累積/發展,分散運行.結合並產生新服務.
對於開發人員,應該去想開發甚麼服務,組合既有服務去建立新服務,到開發終端應用程式時去消耗這些服務.就是用服務導向的思維去想事情.

About the technology, we need to use open standards, such as web service, xml, ODBC, HTTP, etc.
Different web servers provide different services. When creating new application or service, you can consume multiple services from different source,
and then combine them into your new application or service.
關於技術,需要透過開放標準來組合服務,例如web service, xml, ODBC, HTTP 等.
不同的伺服器提供不同的服務,要開發新應用或服務時,可以從不同的來源找尋你需要的服務,再整合成你的新應用或新服務

Advantages
– service can explicitly reuse and accumulate
– integrate resources from different sources
– easily introduce redundancy
好處
– 服務可以較明確的重用/累積
– 整合不同來源的資源(前述的服務)
– 更容易做redundancy

OASIS defines SOA as the following:
A paradigm for organizing and utilizing distributed capabilities that may be under the control of different ownership domains. It provides a uniform means to offer, discover, interact with and use capabilities to produce desired effects consistent with measurable preconditions and expectations.

總結 : 在投入大量資源做SOA後,最難的就是怎樣去Discover那些service和安全性問題

資料庫正規化簡介(前四階段)

第一正規化(1NF) – 1. 排除重複群,即每欄位只放單一值 2. 每筆記錄都要有主鍵, 3. 同類事物只能用一個欄位

第二正規化(2NF) – 1. 1NF, 2. 每個欄都要跟整個主鍵有相依關係,而不是主鍵的部份有關,如果不是用複合主鍵,就一定是2NF

第三正規化(3NF) – 1. 2NF, 2. 非主鍵,屬性之間需互相完全無關

Boyce-Codd正規化(BCNF) – 1. 3NF, 2. 非候選鍵或候選鍵superset的欄位,限制了其他欄位的值,即存在欄位X->欄位Y的關係,就違反BCNF.如果表單裡沒有互相重疊的候選鍵,就必定BCNF

補充: 候選鍵即可唯一找出一筆資料的欄位組合,有可以作為鍵值潛力

還有四階NF, 4NF, 5NF, DKNF, 6NF, 通常用來處理特殊情況, 例如key不統一, 通常沒必要用到

Computer Cryptography Basic Knowledge è¨ˆç®—機密碼學基本知識

There are three basic types of encrypt/decrypt strategies.
Symmetric – use only one key, the secret key. Both encryption and decryption use this key. This method is fast but have key distribution problem. How do you share the key with people receiving cypher from you?
Asymmetric – Two keys involve the strategy, one public key and one private key. You spread your public key, people encrypt data with it and send the cypher back to you, you decrypt the cypher with private key. vice versa. This method is slower than symmetric one but without the key distribution problem.
Hybrid – Have the ablities of being both safe and fast by combining the above strategies. Solve the symmetric key distribution problem by encrypting the secret key with your given public key, send it back. The receiver will decrypt the secret key with his/hers private key. Then you get the speed of symmetric method by encrypting and decrypting data with secret key.

計算機理論裡有三種最基本的加密方法
對稱加密法 – 只用一把金鑰,叫秘密金鑰好了. 加密跟解密都使用這一把金鑰完成. 這個方法很快,但缺點是金鑰發佈問題. 你要怎樣安全地把金鑰送給密件收件人呢?
非對稱加密法 – 要用兩把金鑰, 一把公用金鑰和一把私有金鑰. 你把自己的公用金鑰發佈出去, 想傳資料給你的人用這金鑰加密並把密件回傳給你. 你用你的私有金鑰解密. 相反也用同樣做法. 這方法比對稱法慢但沒有金鑰發佈問題.
混合法 – 結合上面兩種方法使之既快速且安全的. 把秘密金鑰先用別人給你的公用金鑰先加密,發佈出去. 收件人再用其私有金鑰把秘密金鑰取出. 接著雙方就可以用同個秘密金鑰互送資料.

Simple arithmetic expression evaluation C# ç°¡å–®ç®—式運算

This is a very basic algorithm which CS student must have came across. Whereas non-CS programmer may not aware its exsistence.
I learned it in my university lesson but never thoroughly implement it. Single digit without parentheses, unsigned integer, without UI doesn’t count.
So, I implement it to practice and see how am I difference from my school days. This implementation support nested parentheses, percentage, exponent, negative number and fractional number.
這是每一個計算機科學學生都學過的演算法,但非本科的程式人員可能不知道它的存在.我也是在大學時學到的,但從未認真的去實作它. 單位數沒有括號,只能用非負數整數,沒有使用者介面的不算數.
所以,我就實作這個作為練習和看看自己畢業幾年後在寫程式有甚麼差別了.這一次支援括號,百分比,次方,負數和小數.
It is a procedure that start with re-organizing the expression so that parentheses are invisible and it is in evaluation priority descending order. And then you can easily evaluate that expression. You can somehow extend its ability by adding more supported operators.
You can use postfix or prefix(polish) notation, either one will do. I am going to use postfix notation because it actually matches the left to right order while evaluating it. And I think it is easier this way.
You will need a stack for this algorithm. I use .NET generic stack and which is great that is has Peek() to see what is on the top of the stack without poping it out.
這個程序要先重排你的算式,移除括號卻保留算式的運算順序.然後你就可以輕易的做計算.你可以增加支援的運算符去提升這演算法的計算方法.
你可以選擇用後置式或前置式去重排,任何一個都可以.我準備用後置式因為它真的是由左至右運算.而且我想它比前置式容易.
你需要一個堆疊去實作這個演算法,我用.NET附的泛型堆疊.它有一個很好的方法Peek()讓你可以不用彈出也能看到堆疊最上面的內容.
You read the expression from left to right, one unit at a time, a unit can be an operator, a parenthese or an operand.
If you get an open parenthese, push it into the stack so that you can match with the close parenthese later.
if you get a close parenthese, pop the stack and append it to output expression until you have the open parenthese on the top of the stack. Remove the open parenthese from the stack, neither append any parenthese to your output expression nor push it into your stack.
If you get an operator, compare its priority with the stack top operator, while its priority is higher, pop the stack and append it to the output expression. Then push your current operator to the stack. Or if the stack is empty, push.
If you get an operand, append it to the output expression.
After the input expression is use up, append anything left in the stack to the output expression.
Here comes the part to evaluate the output expression. Read the output from left to right.
If it is an operand, push it into the stack. If it is an operator, pop out two operands, first one as right operand, second one as left operand, use the operator to evaluate these two. Push the result back. Get the answer from the stack when the output expression use up. That’s it.
從左至右的讀入算式,一次一個單位,一個單位可以是運算符,括號或運算子.如果你拿到的是開括號,把它加到堆疊,你之後會用它來對上閉括號.
如果你拿到的是閉括號,從堆疊拿出資料,加到你準備好的結果算式,直到你拿到開括號.丟掉開括號和閉括號,不要把任何閉括號加到你的堆疊或輸出.
如果你拿到的是運算符,跟堆疊最上面的運算符做比較,如果你手上的運算符順序較高,就輸出堆疊最上面的元素並加到輸出算式.直到你手上的運算順序低放埋疊頂的元素,又或者堆疊空了,把你手上的加到堆疊.
如果你拿到的是運算子,把它加到輸出算式.
等到輸入算式都讀完,把堆疊裡的元素都拿出來加到輸出算式.
完成後就開始計算輸出算式,由左至右拿出單位,如果是計算子,把它加到堆疊.如果它是一個計算符,從堆疊拿出兩個計算子,第一個作為右邊運算子,第二個作為左邊運算子,用你的計算符去計算它們.把結果加回堆疊.最後算式用完,從堆疊取出結果.完成!
Source code here, please do not hand it in as your assignment. All rights reserved.
原始碼在這裡here,請不要用來交作業. 版權所有.

Regular expression basics

Expression Description Example
Any character except [\^$.|?*+() All characters except the listed special characters match a single instance of themselves. { and } are literal characters, unless they’re part of a valid regular expression token (e.g. the {n} quantifier). ‘a’ match ‘a’
\ (backslash) followed by any of [\^$.|?*+(){} make special character function as normal character ‘\+’ match ‘+’
\Q…\E Matches the characters between \Q and \E literally, suppressing the meaning of special characters. ‘\Q+-*/\E’ matches ‘+-*/’
\xFF Matches the character with the specified ASCII/ANSI value, which depends on the code page used. Can be used in character classes. ‘\xA9’ matches ‘©’ when using the Latin-1 code page.
[] matches one character inside square brackets,can use ‘-‘ for range. [^] is complement class of [] [abc] matches a, b or c, [0-9] matches any digit in 0 to 9
\n, \r and \t Match an LF character, CR character and a tab character respectively. Can be used in character classes. \r\n matches a DOS/Windows CRLF line break.
\d,\w,\s,\D,\W,\S \d any digit from 0 to 9, \w any digits and/or letters(e.g. fj490fj), \s whitespace. \D\W\S are their complement [\d\s] matches a character that is a digit or whitespace
. Matches any single character except line break characters \r and \n. Most regex flavors have an option to make the dot match line break characters too. ‘.’ matches ‘x’ or (almost) any other character
^$ indicates start and end of a regular expression, most regex support them to match line break. ‘^[0-9][A-Z]$’ matches ‘4D’
\A,\Z,\z \A Matches at the start of the string the regex pattern is applied to. Matches a position rather than a character. Never matches after line breaks.
\Z Matches at the end of the string the regex pattern is applied to. Matches a position rather than a character. Never matches before line breaks, except for the very last line break if the string ends with a line break.
‘\A.’ matches ‘a’ in ‘abc’, ‘.\Z’ matches ‘f’ in ‘abc\ndef’
\b,\B \b Matches at the position between a word character (anything matched by \w) and a non-word character (anything matched by [^\w] or \W) as well as at the start and/or end of the string if the first and/or last characters in the string are word characters.
\B Matches at the position between two word characters (i.e the position between \w\w) as well as at the position between two non-word characters (i.e. \W\W).
‘.\b’ matches ‘c’ in ‘abc’, ‘\B.\B’ matches ‘b’ in ‘abc’
| (pipe) means or, matches left part or right part of it abc(def|xyz) matches abcdef or abcxyz
? (question mark) Makes the preceding item optional. Greedy, so the optional item is included in the match if possible. abc? matches ab or abc
*, *? * Repeats the previous item zero or more times. Greedy, so as many items as possible will be matched before trying permutations with less matches of the preceding item, up to the point where the preceding item is not matched at all.
*? (lazy star) Repeats the previous item zero or more times. Lazy, so the engine first attempts to skip the previous item, before trying permutations with ever increasing matches of the preceding item.
“.*” matches “def” “ghi” in abc “def” “ghi” jkl
{n} {n} Repeats the previous item exactly n times.
{n,m} Repeats the previous item between n and m times. Greedy, so repeating m times is tried before reducing the repetition to n times.
{n,m}? Repeats the previous item between n and m times. Lazy, so repeating n times is tried before increasing the repetition to m times.
{n,} Repeats the previous item at least n times. Greedy, so as many items as possible will be matched before trying permutations with less matches of the preceding item, up to the point where the preceding item is matched only n times.
{n,}? Repeats the previous item n or more times. Lazy, so the engine first matches the previous item n times, before trying permutations with ever increasing matches of the preceding item.
a{3} matches aaa, a{2,4} matches aaaa, aaa or aa, a{2,4}? matches aa, aaa or aaaa, a{2,} matches aaaaa in aaaaa, a{2,}? matches aa in aaaaa