2012年11月23日 星期五
http://www.codeproject.com/Articles/43025/A-LINQ-Tutorial-Mapping-Tables-to-Objects
http://www.codeproject.com/Articles/43025/A-LINQ-Tutorial-Mapping-Tables-to-Objects
2012年11月22日 星期四
MessageBox for confirmation
Code snipplet:
var messageBoxResult = MessageBox.Show(AppResources.TextDeleteConfrimation,
AppResources.TextDelete, MessageBoxButton.OKCancel);
if (messageBoxResult == MessageBoxResult.OK)
{
DeleteSomething();
}
2012年11月21日 星期三
my common git commands
git checkout master
git pull --rebase
// switch the working branch to master branch
// then, pull the things back.
// these things includes: the commits on master by your colleagues and
// other branch name created by your colleagues
// Then, update master branch to the latest commit
// combo 技
// 切換到 master, 把其他人做的更動拉回來
// 然後快轉到 master 最新的 commit 狀態
// 拉回來的東西包括了: 其他人在 master 上的 commit 跟其他人創立的 branch name
git checkout -b newBranchName
// 創立一個 local的新的branch 叫做 newBranchName
// 然後切換過去
git branch --track workingLocalBranchName remote/remoteBranchName
// creates a local working branch name, called "workingLocalBranchName"
// which is tracking the remote branch name called "remoteBranchName".
// the remote branch name can be found by "git branch -a"
/*
通常早上做完這兩個指令以後
就開始寫 code
到下午, code改完了, bug修掉了以後 ...
*/
git gui
// it is better to do the commit and push here
// 最好在這裡做 commit 跟 push
gitk
// see the history of commits of the current branch
// each commit is identifed with unique SHA string, which can be found in this window
// 看目前 branch 的歷史紀錄
// 每一次 commit 都有一個 SHA id 對應
// 在這個畫面裡面可以看到每次 commit 的SHA id
/*
做 patch 了, 大家來 review
*/
git format-patch -1 --full-index
// if your modification only requires 1 commit
// this command is quicker
// 如果你只 commit 了一次
// 這個指令會做出這個 commit 的 patch 檔
git diff --full-index oldSHA..newSHA > patchFileName.patch
// diff all the commits from oldSHA to newSHA into the patchFileName.patch
// 把從 oldSHA 到 newSHA 的所有更動放到 patchFileName.patch
git diff --full-index master..localBranchName > xxx.patch
// diff between two branches
// 兩個 branch 做diff
/*
merge 到 master
*/
git cherry-pick SHA
// SHA represents a commit, no matter which branch it is on.
// this command grabs the commit identified by that SHA id,
// and put it on top of the local working branch.
// 把SHA所代表的那個 commit 拉過來, 丟到你打指令的這個 branch
git merge --squash localBranchName
// merge the working branch with localBranchNamebranch
// 把 localBranchName這個 branch 拉過來, merge到你打指令的這個 branch
git merge --squash origin/remoteBranchName
// merge with remoteBranchName branch
// 與遠端的 branch 做 merge
/*
如果 merge 有conflict... 請小心, 沒有指令可以幫你處理好conflict
*/
git reset --hard SHA
// 說對不起, 我想清楚再merge
// 回到SHA這個commit, 在這之後的commit都會不見
// 回到SHA這個commit, 在這之後的commit都會不見
git reset --soft SHA
// 說對不起, 我想清楚再merge
// 回到SHA這個commit, 在這之後的commit都會變成已修改狀態
// 回到SHA這個commit, 在這之後的commit都會變成已修改狀態
git gui
// 如果修好了conflict 記得要再 commit 一次
/*
其他指令
*/
git checkout localBranchName
// change the working branch to localBranchName branch
// ex: git checkout master
// Before checking out to another branch, there should not be any
// editting modifications in the working branch.
// Make sure you stash or commit everything you've modified
// 更改你目前的打指令的這個 branch 到 localBranchName 這個 branch
// 更改 branch 之前, 必須確定目前的 branch 是乾淨的
// 所以, 所有的更動請先放到stash或是commit
git checkout -b newLocalBranchName origin/remoteBranchName
// Grab the remoteBranchName into newLocalBranchName
// 把遠端 remoteBranchName 整串拉回來, 放到 newLocalBranchName
git status
// see the current status of tracked files,
// or any new files that are not tracked.
// 看目前git 追蹤的檔案裡面, 那些做過更改
// 或是那些檔案沒有被tracked
// put the current modifications into the stash area.
// it will 'clean' the current modifications and restore to
// the lastest commit
// 把目前所做的更動放到stash, 會把目前的更動清掉,
// 恢復到最新的commit的狀態
git stash apply -1
// apply the first stash item from the stash area to the current editting files.
// 把stash裡面第一個東西拉出來, 對目前的檔案做更動
git stash clear
// clear the stash area
// 把 stash 清掉
git push origin:remoteBranchName
git push origin --delete remoteBranchName
git push origin --delete remoteBranchName
// Remove remoteBranchName on the remote side.
// 把遠端的一個叫做 remoteBranchName 的 branch 殺掉
git branch -D localBranchName
// remove the localBranchName branch
// 把本地端的 localBranchName 這個 branch 殺掉
// 新的gerrit server有內建code review的功能
/*
以前都是做patch
丟上review board
過了以後
再cherry-pick到master branch
這個對我來說的新功能是
remote的branch有兩個同名同姓的
只是在不同的refs的HEAD
要先push到HEAD:refs/for/
commit就會出現在review board上了
review過了以後
這個 commit就會跑到 remote/origin/
*/
git push origin HEAD:refs/for/<remoteBranchName>
git apply --stat XXX.patch // see the stats of the patch files
git apply --check XXX.patch
git apply XXX.patch
// git ignore mode changes:
git config core.filemode false
// list files changed between two SHAs:
git diff --name-only SHA1 SHA2
2012年11月20日 星期二
Share something by email on windows phone 8
In xaml file, let's say we have a button like this:
In c#:
Where composeEmailBody() is a function that returns a string, you can implement it in your own needs.
<Button x:Name="tellAFriendButton" Width="352" Height="47"
Click="OnClickTellAFriendButton"
Style="{StaticResource TellAFriendButtonStyle}" Margin="174,241,274,0"
Template="{StaticResource TellAFriendControlTemplate}">
</Button>
In c#:
private void OnClickTellAFriendButton(object aSender,
System.Windows.RoutedEventArgs aRoutedEventArgs)
{
var emailAddressChooserTask = new EmailAddressChooserTask();
emailAddressChooserTask.Show();
emailAddressChooserTask.Completed +=
EmailAddressChooserTaskCompleted;
}
void EmailAddressChooserTaskCompleted(object aSender,
EmailResult aEmailResult)
{
var emailComposeTask = new EmailComposeTask();
emailComposeTask.To = aEmailResult.Email;
emailComposeTask.Body = ComposeEmailBody();
emailComposeTask.Show();
}
Where composeEmailBody() is a function that returns a string, you can implement it in your own needs.
Estimate an App
T-shirt size.
Tasks | Estimate
---------------------------------------------
Pre-development
Task A
Task B
..
..
Development
Task C
Task D
..
Post-development
Task E
Task F
..
------------------------------------------------
Total days
Tasks | Estimate
---------------------------------------------
Pre-development
Task A
Task B
..
..
Development
Task C
Task D
..
Post-development
Task E
Task F
..
------------------------------------------------
Total days
2012年11月15日 星期四
How to get the path to the image file that is associated to the image element on windows phone 8.
var bitmapImage = ImageElement.Source as BitmapImage;
if (bitmapImage != null)
ImagePath = bitmapImage.UriSource.ToString();
How to load string from resource in Windows phone 8.
Like this:
AppNameSpace.Resources.AppResourses.StringKeyName
this will work on windows phone 8.
AppNameSpace.Resources.AppResourses.StringKeyName
this will work on windows phone 8.
2012年11月11日 星期日
How to load a string from Resource.resw, and add a item to settings panel on Windows 8
The keyword is SettingsPane.
In OnLaunched() in App.xaml.cs:
Then implement CommandsRequested() itself.
In OnLaunched() in App.xaml.cs:
SettingsPane.GetForCurrentView().CommandsRequested += CommandsRequested;
Then implement CommandsRequested() itself.
private void CommandsRequested(SettingsPane aSender, SettingsPaneCommandsRequestedEventArgs aEventArgs)
{
// Retrieve all the strings first
var loader = new Windows.ApplicationModel.Resources.ResourceLoader();
string settingsCommandId = loader.GetString("aText");
string label = loader.GetString("aText");
//add the commands to the setting panel
aEventArgs.Request.ApplicationCommands.Add(
new SettingsCommand(settingsCommandId, label, aMethod));
}
2012年11月8日 星期四
Pivot item on Windows phone 8
<phone:Pivot Title="A_title">
<phone:PivotItem Header="History">
</phone:PivotItem>
<phone:PivotItem Header="Favorites">
</phone:PivotItem>
<phone:PivotItem Header="Scan">
</phone:PivotItem>
<phone:PivotItem Header="Creator">
</phone:PivotItem>
<phone:PivotItem Header="Settings">
</phone:PivotItem>
</phone:Pivot>
2012年11月7日 星期三
Use ZXing library to decode/encode 2D barcode
Using ZXing in c#
How to decode a 2D barcode into text
The code snippet:
try { // Get the width and height of the bitmap, //and change it to a WriteableBitmap object int width = mBitmap.PixelWidth; int height = mBitmap.PixelHeight; WriteableBitmap writableBitmap = new WriteableBitmap(mBitmap); // use RGBLuminanceSource and HybridBinarizer class to // process the WriteableBitmap into a BinaryBitmap var lsource = new RGBLuminanceSource(writableBitmap, width, height); Binarizer zer = new HybridBinarizer(lsource); BinaryBitmap binaryBitmap = new BinaryBitmap(zer); // Decode the binaryBitmap useing the QRCodeReader object QRCodeReader qrReader = new QRCodeReader(); Result result = qrReader.decode(binaryBitmap); // the decoded text in place in the Result object. Title.Text = result.Text; } catch (Exception ex) // catch the exception here!!! { System.Diagnostics.Debug.WriteLine(ex); }
How to encode a text into a 2D barcode
The library will encode the text into ZXing-defined ByteMatrix. Here is the code snippet:
string encodeText = TextToEncode.Text; if (!String.IsNullOrEmpty(encodeText)) { // use MultiFormatWriter class to encode. var qrCodeWriter = new MultiFormatWriter(); var matrix = qrCodeWriter.encode(TextToEncode.Text, BarcodeFormat.QR_CODE, 400, 400); var bitmap = ToBitmap(matrix); resultImage.Source = bitmap; }
Then, ToBitmap() function is used to get the BitmapImage object from the ByteMatrix:
private WriteableBitmap ToBitmap(ByteMatrix aMatrix) { int width = aMatrix.Width; int height = aMatrix.Height; var bitmap = new WriteableBitmap(width, height); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (aMatrix.get_Renamed(x, y) == -1) { bitmap.Pixels[y * width + x] = BitConverter.ToInt32(BitConverter.GetBytes(0xffffffff), 0); }else { bitmap.Pixels[y * width + x] = BitConverter.ToInt32(BitConverter.GetBytes(0x00000000), 0); } } } return bitmap; }
訂閱:
文章 (Atom)