說明:
使用LINQ找出DataTable內依欄位值最大的N筆資料
做法:
var TopN = (from row in dt.AsEnumerable() select row).OrderByDescending(x => x.Field<string>("Column")).Take(N);
參考資料:
http://stackoverflow.com/questions/5344805/linq-orderby-descending-query
http://www.dotblogs.com.tw/yc421206/archive/2014/07/14/145944.aspx
https://msdn.microsoft.com/zh-tw/library/bb552415(v=vs.110).aspx
http://stackoverflow.com/questions/10855/linq-query-on-a-datatable
2015年7月24日 星期五
[T-SQL] 如何產出0~0.9之間的亂數
說明:
如何產出0~0.9(小數位數1位)之間的亂數。
語法:
SELECT CAST(CAST(NEWID() AS binary(1))%10 AS float)/10
其中NEWID()會產生GUID(32個16進位),將之轉型為1 byte,因此值會在0-255之間,
mod 10後,值會在0-9之間,再除以10,值就會跑在0-0.9之間。
參考資料:
https://msdn.microsoft.com/zh-tw/library/ms190348(v=sql.120).aspx
http://caryhsu.blogspot.tw/2012/08/rand.html
如何產出0~0.9(小數位數1位)之間的亂數。
語法:
SELECT CAST(CAST(NEWID() AS binary(1))%10 AS float)/10
其中NEWID()會產生GUID(32個16進位),將之轉型為1 byte,因此值會在0-255之間,
mod 10後,值會在0-9之間,再除以10,值就會跑在0-0.9之間。
參考資料:
https://msdn.microsoft.com/zh-tw/library/ms190348(v=sql.120).aspx
http://caryhsu.blogspot.tw/2012/08/rand.html
2015年6月4日 星期四
[IOS/Swift] how to post data to RESTful WebService?
說明:
如何透過RESTful WebService來更新後台的資料?
語法:
如何透過RESTful WebService來更新後台的資料?
語法:
var strURL = WS URL;
var request = NSMutableURLRequest(URL: NSURL(string: strURL));
request.HTTPMethod = "POST";
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue.mainQueue()) { (response, data, error) in
if (response != nil)
{
var strResponse = NSString(data: data, encoding: NSUTF8StringEncoding);
//replace the '\' of strResponse
print(strResponse.stringByReplacingOccurrencesOfString("\"", withString: ""));
}
}
2015年6月3日 星期三
[C#/Excel PIA] Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 8000401a The server process could not be started because the configured identity is incorrect. Check the username and password.
說明:
使用Excel PIA寫schedule job產出Excel,程式放在64 bits server上,執行出現該錯誤。
解法:
出現此錯誤,主要是COM元件的存取帳戶被設為Interactive,
因此程式執行時,需要有帳戶登入該server。看過網路上的解法,
打開Administrative Tools下的component service -> Computers -> DCOM Config,
找到Microsoft Excel Application或{00024500-0000-0000-C000-000000000046},
右鍵Properties,找到Security tab或identity tab,將帳戶加進去,
但我找不到Excel Application,試過在command line下mmc comexp.msc /32等方法,還是沒顯示,最後是在登錄檔,HKEY_CLASSES_ROOT\AppID\{00020812-0000-0000-C000-000000000046},將某個屬性值的Interactive改掉即可。
參考資料:
https://ovaismehboob.wordpress.com/2013/07/06/production-deployment-issues-when-asp-net-web-application-access-com-component/
http://blogs.technet.com/b/the_microsoft_excel_support_team_blog/archive/2012/11/12/microsoft-excel-does-not-appear-in-dcom-configuration-snap-in.aspx
https://msdn.microsoft.com/en-us/library/ms678426(VS.85).aspx
http://www.cnblogs.com/fengjunkuan/
使用Excel PIA寫schedule job產出Excel,程式放在64 bits server上,執行出現該錯誤。
解法:
出現此錯誤,主要是COM元件的存取帳戶被設為Interactive,
因此程式執行時,需要有帳戶登入該server。看過網路上的解法,
打開Administrative Tools下的component service -> Computers -> DCOM Config,
找到Microsoft Excel Application或{00024500-0000-0000-C000-000000000046},
右鍵Properties,找到Security tab或identity tab,將帳戶加進去,
但我找不到Excel Application,試過在command line下mmc comexp.msc /32等方法,還是沒顯示,最後是在登錄檔,HKEY_CLASSES_ROOT\AppID\{00020812-0000-0000-C000-000000000046},將某個屬性值的Interactive改掉即可。
參考資料:
https://ovaismehboob.wordpress.com/2013/07/06/production-deployment-issues-when-asp-net-web-application-access-com-component/
http://blogs.technet.com/b/the_microsoft_excel_support_team_blog/archive/2012/11/12/microsoft-excel-does-not-appear-in-dcom-configuration-snap-in.aspx
https://msdn.microsoft.com/en-us/library/ms678426(VS.85).aspx
http://www.cnblogs.com/fengjunkuan/
2015年4月11日 星期六
[IOS/Swift] how to parse json from the webservice
說明:
json可以拆解成Array,以[]表示,例:[{"id": "#123", "name": "Apple"},{"id": "#321", "name": "Google"}]。
另一種是Object,以{"key": "value"}表示,如http://date.jsontest.com/提供的:
{
"time": "03:53:25 AM",
"milliseconds_since_epoch": 1362196405309,
"date": "03-02-2013"
}
這兩種格式可分別使用Swift內建NSArray跟NSDictionary來Parse,那Array內又有Array該如何Parse呢?
做法:
假設有一json如下:
{
"Parents": [ {"id": "#123",
"name": "Daddy1",
"Children": [ {"c_id": "#124",
"c_name": "kid1"},
{"c_id": "#125",
"c_name": "kid2"}]
},
{"id": "#234",
"name": "Daddy2",
"Children": [ {"c_id": "#235",
"c_name": "kid1"},
{"c_id": "#236",
"c_name": "kid2"}]
},
{"id": "#345",
"name": "Daddy3",
"Children": [ {"c_id": "#346",
"c_name": "kid1"},
{"c_id": "#347",
"c_name": "kid2"}]
}
]
}
var arrResult = json.objectForKey("Parents") as NSArray;
var row: NSDictionary;
var rowSub: NSDictionary;
var arrSubResult : NSArray;
var strID: String;
var strName: String;
var strC_ID: String;
var strC_Name: String;
var arrTotalResult = [DataModel]();
for var i=0 ; i < arrResult.count ; i++ {
row = arrResult[i] as NSDictionary;
arrSubResult = row.objectForKey("Children") as NSArray;
strID = row["ID"] as String;
strName = row["NAME"] as String;
for var j=0 ; j < arrSubResult.count ; j++ {
rowSub = arrSubResult[j] as NSDictionary;
strC_ID = row["C_ID"] as String;
strC_Name = row["C_NAME"] as String;
//使用data model
let data = DataModel(ID: self.strID, Name: self.strName, C_ID: self.strC_ID, C_Name: self.C_Name);
arrTotalResult.append(data);
}
}
json可以拆解成Array,以[]表示,例:[{"id": "#123", "name": "Apple"},{"id": "#321", "name": "Google"}]。
另一種是Object,以{"key": "value"}表示,如http://date.jsontest.com/提供的:
{
"time": "03:53:25 AM",
"milliseconds_since_epoch": 1362196405309,
"date": "03-02-2013"
}
這兩種格式可分別使用Swift內建NSArray跟NSDictionary來Parse,那Array內又有Array該如何Parse呢?
做法:
假設有一json如下:
{
"Parents": [ {"id": "#123",
"name": "Daddy1",
"Children": [ {"c_id": "#124",
"c_name": "kid1"},
{"c_id": "#125",
"c_name": "kid2"}]
},
{"id": "#234",
"name": "Daddy2",
"Children": [ {"c_id": "#235",
"c_name": "kid1"},
{"c_id": "#236",
"c_name": "kid2"}]
},
{"id": "#345",
"name": "Daddy3",
"Children": [ {"c_id": "#346",
"c_name": "kid1"},
{"c_id": "#347",
"c_name": "kid2"}]
}
]
}
var arrResult = json.objectForKey("Parents") as NSArray;
var row: NSDictionary;
var rowSub: NSDictionary;
var arrSubResult : NSArray;
var strID: String;
var strName: String;
var strC_ID: String;
var strC_Name: String;
var arrTotalResult = [DataModel]();
for var i=0 ; i < arrResult.count ; i++ {
row = arrResult[i] as NSDictionary;
arrSubResult = row.objectForKey("Children") as NSArray;
strID = row["ID"] as String;
strName = row["NAME"] as String;
for var j=0 ; j < arrSubResult.count ; j++ {
rowSub = arrSubResult[j] as NSDictionary;
strC_ID = row["C_ID"] as String;
strC_Name = row["C_NAME"] as String;
//使用data model
let data = DataModel(ID: self.strID, Name: self.strName, C_ID: self.strC_ID, C_Name: self.C_Name);
arrTotalResult.append(data);
}
}
2015年3月11日 星期三
[C#] Performance: 泛型 List V.S. ArrayList V.S. DataTable
2015年2月2日 星期一
[git/gerrit] Mac OS使用git將文件push上gerrit的branch
說明:git是分散式版本控制系統之一,gerrit是以git專案為基的code review系統,記錄在Mac OS下如何將code push上gerrit的branch。
做法:
1. 安裝git(http://git-scm.com/)。
2. 啟用gerrit之帳戶與建立SSH key。可參閱以下網址:
http://git-scm.com/book/zh/v2/Git-on-the-Server-Generating-Your-SSH-Public-Key
3. 測試本地電腦跟gerrit連線ok後,開啟電腦上的終端機,輸入defaults write com.apple.finder AppleShowAllFiles TRUE並按下Enter,再輸入killall Finder然後送出,讓電腦顯示系統的隱藏檔案,方便後續操作.git裡的config檔。
4. 在終端機輸入git clone ssh://ssh_user_name@gerrit_url:29418/project_name.git。
5. 專案複製到本地電腦帳戶下資料夾後 -> 打開此專案,修改某行程式碼儲存後,可將該檔案commit -> 輸入commit message -> commit送出。
6. 回到終端機視窗,輸入cd ~/project_name/,進到該專案下 -> 輸入git status,檢視目前專案異動狀態。
7. 輸入scp -p -P 29418 ssh_user_name@gerrit_url:hooks/commit-msg .git/hooks/,可將每次commit所需的Change_Id自動加進去commit message,否則可能會出現ERROR: missing Change-Id in commit message的訊息。
8. 打開Finder,進到本機帳號下的Project,打開隱藏的.git資料夾 -> 打開裡面的.config檔,加入以下指令,增加gerrit用來review code的branch,
[remote "review"]
pushurl = ssh://ssh_user_name@gerrit_url:29418/project_name
push = refs/heads/master:refs/for/master
9. 最後在終端上輸入git push review,即可將code push上gerrit review
code的branch -> 進gerrit即可看到剛push上去的記錄。
參考資料:
https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/xcode_guide-continuous_integration/PublishYourCodetoaSourceRepository/PublishYourCodetoaSourceRepository.html
http://stackoverflow.com/questions/8845658/gerrit-error-when-change-id-in-commit-messages-are-missing
http://vimeo.com/23609339
做法:
1. 安裝git(http://git-scm.com/)。
2. 啟用gerrit之帳戶與建立SSH key。可參閱以下網址:
http://git-scm.com/book/zh/v2/Git-on-the-Server-Generating-Your-SSH-Public-Key
3. 測試本地電腦跟gerrit連線ok後,開啟電腦上的終端機,輸入defaults write com.apple.finder AppleShowAllFiles TRUE並按下Enter,再輸入killall Finder然後送出,讓電腦顯示系統的隱藏檔案,方便後續操作.git裡的config檔。
4. 在終端機輸入git clone ssh://ssh_user_name@gerrit_url:29418/project_name.git。
5. 專案複製到本地電腦帳戶下資料夾後 -> 打開此專案,修改某行程式碼儲存後,可將該檔案commit -> 輸入commit message -> commit送出。
6. 回到終端機視窗,輸入cd ~/project_name/,進到該專案下 -> 輸入git status,檢視目前專案異動狀態。
7. 輸入scp -p -P 29418 ssh_user_name@gerrit_url:hooks/commit-msg .git/hooks/,可將每次commit所需的Change_Id自動加進去commit message,否則可能會出現ERROR: missing Change-Id in commit message的訊息。
8. 打開Finder,進到本機帳號下的Project,打開隱藏的.git資料夾 -> 打開裡面的.config檔,加入以下指令,增加gerrit用來review code的branch,
[remote "review"]
pushurl = ssh://ssh_user_name@gerrit_url:29418/project_name
push = refs/heads/master:refs/for/master
9. 最後在終端上輸入git push review,即可將code push上gerrit review
code的branch -> 進gerrit即可看到剛push上去的記錄。
參考資料:
https://developer.apple.com/library/ios/documentation/IDEs/Conceptual/xcode_guide-continuous_integration/PublishYourCodetoaSourceRepository/PublishYourCodetoaSourceRepository.html
http://stackoverflow.com/questions/8845658/gerrit-error-when-change-id-in-commit-messages-are-missing
http://vimeo.com/23609339
訂閱:
文章 (Atom)

