Thứ Sáu, 25 tháng 7, 2014

Good Commit Messages And Enforcing Them With Git Hooks

I have used GIT for a year, commit and push hundreds of commits. However I still forgot our GIT naming convention and push a wrong commit last week. I wonder if there is a tool for checking the commit message before I press commit button.
Fortunately, GIT provides us many powerful hooks to do this. After two hours searching in Google, I found an awesome sample which is written by python but I prefer perl than python so I decide to write my own perl script.

 

 
 
Then, I copy perl.exe from my install git folder to .git/hooks
Finally, I modify the script commit-msg to call my perl script:
exec .git/hooks/perl.exe .git/hooks/check-commit-message.pl $1
Now, everytime I make a commit, the hook commit-msg will run and check my commit message
 

Thứ Ba, 15 tháng 7, 2014

How to suppress a rule on FxCop

Please follow the steps below to suppress:
  1. Right click on Project -> Properties -> Build -> input CODE_ANALYSIS into Conditional compilation symbol
  2. Add new GlobalSuppressions.cs file to Properties folder on your project.
  3. Using Microsoft FxCop tool to get quickly correct a SuppressMessage:
  • Start Menu -> All Programs -> "Microsoft FxCop" option and then click on FxCop

  • Go to Project Menu and click on “Add Targets…”. Select the EXE or DLL. Once it is done, click on Analyze button and your screen will look like below:

  • Right click on any message you want to suppress and go to Copy As ->Suppress-Message or Copy As ->Module-level Suppress Message.
  • Finally paste a suppress message into GlobalSuppression.cs.

Thứ Năm, 26 tháng 6, 2014

How to truncate git history by Git Extension

After a year working with project Legend, our team created about 1400 commits. However I don’t think anyone need to view the commit history of six or twelve months ago, so I would like to truncate too old commits.
If you love command line, you can use following awesome git commands:
 git checkout --orphan temp $1
 git commit -m "Truncated history"
 git rebase --onto temp $1 master
 git branch -D temp
 git gc
I’m a fan of GIT extension so I try converting those commands to Git Extension actions:
1. Open your git directory with Git extension
 
2. Create a temp branch at the last commit you would like to truncate
3. Reset MIX to the root commit
 
 
4. Amend commit with new message “Truncate 3 commits”
5. Check out master, rebase on temp
6. Enjoy the result, your old commit has been truncated

Chủ Nhật, 15 tháng 6, 2014

Draw Git history graph by HTML5

If you have intention to draw a GIT history graph in HTML you might think about HTML5.

In this example, I use NGIT to get GIT history graph information. I added SimpleAbstractPlotRenderer to namespace NGit.Revplot (because AbstractPlotRenderer doesn't work correctly) and created an override class SimplePlotRenderer to render history graph information. Finally, I use easelJs to draw GIT History graph




You can get my source code here: https://github.com/haison8x/git-history-html5.git

Build Summary plugin for Jenkins

I have used Jenkins as main tool of CI for 6 years. Jenkins helps me so much for monitoring the stability of my source code. When I received failed message from Jenkins, I understood that there was something wrong. Then I read the console log to find out the problem and fixed it immediately.



 
 

However it is inconvenience to read a long console log so I looked for a way to summarize the status of my build. Fortunately, Thommas has given me a very useful plugin: Summary Display
 
I set up and configured the plugin as Thommas said then I copied the xml file to the artifact directory but nothing happen. The summary build report shows empty.

 

I read the wiki again and I realized that I haven’t created the right format xml. The xml file must similar as the full section example:



Now I can enjoy Summary Display plugin


 
 
 

 
 
 

Thứ Tư, 11 tháng 6, 2014

Minify HTML with ASP.Net MVC 4 - Razor

Several months ago, my boss asked me to create a 5000 rows report. After I solved all problems related to business and server side performance, I’m still not satisfied with the HTML size. My report has to download about 20Mb HTML. Thank god, I can use gzip to make it smaller than 1MB. However I still think I can make it smaller by removing all unneeded whitespaces, similar as the minified javascript.
I found a solution in Arran Maclean’s blog. He used Action Filter to remove all unneeded whitespaces after ASP.MVC 4 render the html files.
His Action Filter renders the perfect minified html file, all unneeded whitespaces are removed. However, I think it consumes a little memory and CPU resource to remove all whitespaces of a 20MB file.
Why we don’t remove the whitespace of razor view? I have researched several hours in Google but nobody thought like me. So I decide to write small winform application to remove all whitespace of my razor view before I deploy my project.
 

The original Razor view:



The Razor view hash been removed whitespaces:



Here are my test results.



The “No trimming” section indicating that the server returns a 11.1MB file in about 1.85-3.45 seconds. The “Runtime trimming” section indicating that the server removes all whitespaces by Action Filter and returns a 6.4MB file in about 3.36-4.07 seconds. The last section indicating that the server renders HTML from a minified razor view and returns a 6.5MB file in 1.35-2.71 seconds.
My application doesn’t have the best algorithm to minify the razor view so I can’t afford the best result. However my solution reduces a little consumed resource of server


You can get my source code at herehttps://github.com/haison8x/razor-white-space-trimming. You are welcome for improving my algorithm and quoting my blog.