2011年12月7日 星期三

安裝DPP時沒有光碟怎麼辦?

存成一個檔案, 附檔名為.reg
Windows 32bit
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Canon\EOS Utility]
[HKEY_LOCAL_MACHINE\SOFTWARE\Canon\DPP]
[HKEY_LOCAL_MACHINE\SOFTWARE\Canon\ZoomBrowser EX]


Windows 64bit
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Canon\EOS Utility]
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Canon\DPP]
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Canon\ZoomBrowser EX]

點兩下執行他...
這樣一來就可以直接安裝下載回來的DPP


2011年9月21日 星期三

F# Lists -1

記得Tuple是用小(圓)括號嗎? F#的List則是用中(角)括號。

> let list123 = [1;2;3];;
val list123 : int list = [1; 2; 3]

可以看到list123是一個 int list的型別, 內容是1; 2; 3, 也可以知道list裡的分隔是用";"來代表的, 和tuple不同, tuple是用","來做為分隔, 這一點很重要, 避免誤用。

2011年9月19日 星期一

F# Arithmetic Operators (算數運算符號)

介紹這種東西, 我自己都覺得有點多此一舉, 不過在F#的世界裡, 很多東西都和C/C++不同, 身為一個C/C++ programmer, 當然也要把這基本的東西搞定才行。

2011年9月18日 星期日

F# Tuples

F#裡最重要的就是Tuple, 這也是很多人對於小圓括弧產生誤解的東西, 在一般的程式語言中(類C/C++), ()<== 這個東西是用來當成function傳入參數, 或是if(), for(), someFun()使用的, 而在裡面的","是用來分隔不同的expression, 並不用來當成數學形式上的數對使用。
但是在F#的世界裡, (a, b, c)就會被當成數對囉。看一下下面的例子:

2011年8月26日 星期五

C# high resolution/performance counter/timer

The codes show that by using the QueryPerformanceCounter, to implement hight performance/resolution timer and counter. I have tried the from WinForm UI and CLI. The resolution can be 1ms. Of course, this will satisfy us for our normal using.

The code is blow. Enjoy it.

2011年8月22日 星期一

F# Language Concepts–Types 型別

F#裡的型別, 其實和大多數的程式語言都相同, 如int, bool, double…等, 其他內建在語言的型別包含 Tuple、清單、陣列、序列、記錄和已區分的聯集, 所以如果想知道F#可以使用什麼型別, 可以參考.Net的使用方法, 只不過F#裡一並可以使用.Net的資源, 和一般寫C#並無太多的不同。

2011年8月12日 星期五

F# Language Concepts - Functions

這一部分的東西是直接從Microsoft MSDN上面取得的, 就想成是中文化後的就行了, 至於真正MSDN上面有沒有中文化我就不得而知了, 個人的習慣是比較喜歡直接看英文, 反正字也不多。下面並沒有直的直接翻譯所有的文字, 全都是領悟之後所寫下來的, 如果有什麼地方不好, 也請和我說明, 我會做修改。
第一部分介紹的是function, 看一下下面的定義…

2011年8月11日 星期四

Plurk API 2.0 test

http://www.plurk.com/API

Plurk API已經進化到2.0了, 雖然不再需要API key這東西, 但是取而代之的是要使用者去授權你的APP, 你可以得到一APP key, 之後就可以做自己想做的事情..

2011年8月8日 星期一

F#, Quick sort in F#

F# is a powerful programming language, but there is few lesson to learn on the internet. I try to introduce the F# and write some articles to let me to record what I learn.

2011年8月4日 星期四

Trend Micro Pc-cillin 2012 測試版

image

最新版的已經可以下載試用了, 有興趣的朋友可以試試看, 這一次外觀還可以自訂喔, 雖然對於防毒這件事沒啥大幫助, 但是換個底圖讓自己心情好一點也不錯是吧…

image

2011年7月26日 星期二

Goto使用的時機點?

從開始學寫程式開始, 就有一種東西老師總會千叮嚀萬交待的說, 千萬不要使用(亂用)goto, 那這東西為何而來呢?其實要了解goto, 得先從組語開始了解起, 組語裡因為接近真實cpu操作的指令, 所以跳來跳去是很正常的一件事, 為了這個原因, 當初在設計C的大老, 自然就會引近相同的功能, 那就是goto啦..
仔細看一下各種語言裡, 雖然大多數的人現在都很少用到goto, 但為何在每個語言裡都還是把goto列為保留字呢? 原因就在於他還是有一些用途的...
Java裡不能使用goto, 但在Java的原文教材裡, 有這麼一句話, [Java編程語言不使用關鍵字goto和const], 只是Java還是把goto列為了保留字, 不談各語言間的優缺點, 我們來看看如何使用goto讓程式變得更簡潔, 看完之後再來說, 為什麼goto還是有其存在的必要性...

天才群

天才群

生長在那個年代的天才, 改變了人們對於世界的認知, 偉大!!

2011年4月25日 星期一

map initialize的方法

Overloading兩個operator來達成這件事情, 說簡單不簡單, 說難也不難..
  1. overload () 並回傳自己的referernce
  2. overload cast (), 並回傳map
這樣做有什麼好處呢?一來可以在global map或是static map產生時就initialize, 也就不用另外寫一個function叫XXXInit之類的了, 二來這樣寫似乎可讀性也比較好, 把map的initialize的code也refactor過一次, 看來這是不錯的做法...

2011年2月15日 星期二

c++ string tokenizer

This is string splitter for STL string. If there is any problem, please contact me. This version is used wstring. You can modify it into "tstring" version for all condition.

 

    void Tokenize(const wstring& str, list<wstring>& tokens, const wstring& delimiters = L" ") {

        // Skip delimiters at beginning.

        wstring::size_type lastPos = str.find_first_not_of(delimiters, 0);

        // Find first "non-delimiter".

        wstring::size_type pos = str.find_first_of(delimiters, lastPos);

        while (wstring::npos != pos || wstring::npos != lastPos) {

            // Found a token, add it to the vector.

            tokens.push_back(str.substr(lastPos, pos - lastPos));

            // Skip delimiters.  Note the "not_of"

            lastPos = str.find_first_not_of(delimiters, pos);

            // Find next "non-delimiter"

            pos = str.find_first_of(delimiters, lastPos);

        }

    }

 

int _tmain(int argc, _TCHAR* argv[]) {

    wstring wstrInput = L"This;Is;A;Test;;;;;;";

    list<wstring> tokens;

    Tokenize(wstrInput, tokens, L";");

    return 0;

}

 

2011年2月14日 星期一

OO設計原則

OO的設計很多人都知道

 

•Encapsulation (封裝)

–Encapsulate member into a class

–Modularity

–Information hiding

–Reusing

•Inheritance (繼承)

–Override

–Extension from super classes

•Polymorphism (多型)

–Re-implement interfaces from super classes

–Overload

 

但是, OO設計的原則, 卻很少人提及...

•SRP:Single Responsibility Principle(單一職責)

•OCP: Open Closed Principle(開放封閉)

•DIP : Dependency Inversion Principle(依賴倒轉)

•ISP:Interface Segregation Principle(介面隔離)

•LSP : Liskov Substitution Principle(替換)

•CARP:Composite/Aggregate Reuse Principle(合成/聚合複用)

•LoD : Law of Demeter(迪迷特-最小最少認知)

其中最容易理解, 卻也最難做到的, 正是單一職責及開放封閉原則

第一, 何謂單一職責!?

一個class不該擁有兩種以上的能力(功能), 也就是說, 一個class只做一件事, 當然這件事的大小, 可以再分割下去, 直到寫程式不再是一件難事就行, 但是如果這個class慢慢的被加大, 那就該考慮是不是該用refactor方法, 再分割這個class, 但為什麼這很難達成呢?

答案是:偷懶, 每次加一點code, 就像青蛙在水褚被煮一樣, 你不會有所感覺, 直到有一天真的很大了, 也難分割了, 就以就放著讓他爛...

最好的解法: 當然有, 但..要看到一個class加了一個新的功能時(不影響主功能)就分割, 可能要有點經驗的人才知道這樣的分法是好一點的, 有的class很小, 有的class很大, 寧可讓所有的class都是小的再結合成大的, 也千萬不要讓class長大再refactor, 如果你有maintain很大型的code經驗, 你知道我在說什麼

第二, 何謂開放封閉原則!?

一段程式碼, 應該對於修改採取封閉, 對新增功能採取開放..

也就是我不允許別人修改我寫完的code, 但是對於要新加的功能是可以的, 最好的做法就是繼承, 當然這也不是解決"開放封閉原則"最好的方法, 最好的方法是程式寫好都不要動, 所有的功能都放在另一個地方去指定, 把這功能都組合起來就可以達到你想做的事情, 但....

答案是: 不可能

在設計的最初這件事情不可能達成, 但設計後總有design document, 可以指定哪些東西不得修改(這是這個程式最主要的功能, 沒有這功能其他都免談的地方), 也就是不可修改程式必須的功能, 但對於擴充功能是要可以的..

可是可是...這個也很難達成是吧...一個巨型的計劃中, 所有的功能不但可能改變, 更有可能被要求加入和先前設計完全不同的功能..這時就得輪到主管出馬了

總之問題的發生在於人對於"程式"的想法..如果有不能解決的, 還是得溝通一下...

謹記在心, 如果有天你發現加了新的功能要改到原有的code, 或是要改到很多地方的code...那你一定是違反了開放封閉原則了

 

2011年1月26日 星期三

How to delete items from the end of a list

We can erase vector and list from any iterator of itself, but if we want to erase a number of items from the end, HOW??

The "erase" can not accept the reverse_iterator type. It only accepts the iterator. So, we have to use the reverse_iterator.base() to get current iterator. You can trace into the source code to get the point of the implementation of STL about the reverse_iterator. When you "++" a reverse_iterator, it will return --current. Got it!? The reverse iterator uses the order by reversing!

Following is the sample code to erase the list from the end.

How about the vector? If you change the list to vector, this code will fail. Think about it. vector can get the size. If you want to erase a number of items (n Items), just erase(vector.begin() + n, vector.end()); That all of it. List can not use this method. Why not? Try to use list.begin() + n, you will get some errors.

 

#include <list>

using namespace std;

int main(int argc, char* argv[])

{

    list<int> listInt;

    listInt.push_back(1);

    listInt.push_back(2);

    listInt.push_back(3);

    listInt.push_back(4);

    listInt.push_back(5);

    listInt.push_back(6);

    list<int>::reverse_iterator rIt = listInt.rbegin();

    for(; rIt != listInt.rend(); ++rIt) {

        listInt.erase(--rIt.base());

    }

    return 0;

}