Wednesday, January 26, 2011

Use Git on Windows (Add files into github)

I want to start to use Git to store some practice projects on GitHub, I used to use Mercurial to store it on google code.  I enjoyed using Mercurial Tool, and google code has more generous storage and I think I will still use it as the primary hobby code storage. I use TFS at my workplace. The best tutorial I found online is this three part series, but here is my own summary for my reference in the future.

1. Go To msysgit, and download the installation file, if you are not sure which one to download, then I will suggest using the one which has the most download count.

2. After installing, start GitBash (which runs inside minGW environment), and the first thing which needs to be done is to create SSH keys with the following command “ssh-keygen –C ‘your@mail.com’ –t rsa”  .  This will generate two keys inside the .ssh directory , and you need paste the public key into your SSH Public Keys inside your account.

 image

If these files are already generated on the other computer, they can be copied over instead of being regenerated.

3. Do some initial configuration, use git config – - globla , I only configured three variables: name, emailaddress, and .gitingore file. Those commands are

$ git config --global user.name "Tekkub"

$ git config --global user.email tekkub@gmail.com

$ git config --global core.excludesfile tekkub@gmail.com

There are a lot of other commands, but those are enough to help me started.

4. Now, you can navigate to the folder you want to add to the github. use the following commands reference on this page.

$git init  [This will initialize the direcotry]

$git add. [This will add the the files under the current folder]

$git commit –m ‘commit message’ [This will commit the changes]

$git remote add origin ******(replace the *** with the url on github)

$git push origin master

 


 

Thursday, December 30, 2010

Visual Studio Shortcut

  1. Ctrl + .  Generate Method Stub.
  2. Alt + U Go To File. DPack
  3. Alt + G Go To Member. DPack

Vim Shortcuts

  1. yank all lines to clipboard
    :%y+

  2. Copy multiple line
    V (Start highlight) + normal move keys to select + y 

  3. Replace word in file
     :r(use % to replace whole file)s/foo/bar/a 


  4. Replace word in file
     CTRL-V (CTRL-G is CTLV-V is used for paste on windows)+Select + I(UpperCase)+ comment+ESC 


Monday, August 10, 2009

Pro ASP.NET MVC Framework

I just finished reading Pro ASP.NET MVC Framework and really enjoyed reading this book. I have briefly read other asp.net mvc books such as Professional ASP.NET MVC 1.0 and ASP.NET MVC in Action, but enjoyed reading this book mostly.

Pro ASP.NET MVC Framework takes a very practical approach on how to build the applications with asp.net mvc. The book didn’t go through every asp.net mvc feature, but it takes you to a natural direction on what kind of feature you will need on a particular step of building the application. Professional ASP.NET MVC 1.0 is more about what the asp.net framework contains regarding building the application, while Pro ASP.NET MVC Framework is about how you should utilize certain feature when building application.

This book also touches other open source frameworks such as the Castle Project when building the IOC container for the controller, and jQuery when building the Ajax part. Even those are not built-in part of the asp.net mvc frameowork, they are essentially building blocks in normal asp.net mvc application building.

Monday, July 06, 2009

Error handling issue in Asp.net mvc contact manage example.

I am going through the codes in the asp.net mvc contact manger example. There is one piece of code which will mislead when some error happens.

In the controller, we have this code.

      [AcceptVerbs(HttpVerbs.Post)]
public ActionResult Create(int groupId, [Bind(Exclude = "Id")] Contact contactToCreate)
{
if (_service.CreateContact(groupId, contactToCreate))
return RedirectToAction("Index", new {id=groupId});
AddGroupsToViewData(groupId);
return View("Create");
}


And then in service class, it has this piece of code.



   public class ContactManagerService : IContactManagerService
{
private IValidationDictionary _validationDictionary;
private IContactManagerRepository _repository;

#region IContactManagerService Members

public bool CreateContact(int groupId, Contact contactToCreate)
{
// Validation logic
if (!ValidateContact(contactToCreate))
return false;

// Database logic
try
{
_repository.CreateContact(groupId, contactToCreate);
}
catch
{
return false;
}
return true;
}
}


Here is the problem, if the _repository.CreateContact(groupId, contactToCreate) throws out some error, the error is silently eaten by the function, and the user will have no idea what had happened. I think it will make much more sense to re-throw this error and take the user to some error page and give the user more information on what’s going on.



   public class ContactManagerService : IContactManagerService
{
private IValidationDictionary _validationDictionary;
private IContactManagerRepository _repository;

#region IContactManagerService Members

public bool CreateContact(int groupId, Contact contactToCreate)
{
// Validation logic
if (!ValidateContact(contactToCreate))
return false;

// Database logic
try
{
_repository.CreateContact(groupId, contactToCreate);
}
catch
{
throw;
}
finally
{
_repository.Dispose();
}
return true;
}
}

Thursday, July 02, 2009

A circular dependency in Asp.Net mvc contact manager example

I wrote a post about my understanding of asp.net mvc contact manager example, this is a very good example to  demonstrate how to separate your code into different parts of application. Particularly, the example introduced a service layer IContactManagerService to wrapper the repository and validation logic.  The controller doesn’t talk to the repository layer directly, instead , the controller talks to service layer. All in fine unless you try to use some dependency injection framework such as NInject.

Here is the problem, the controller constructor takes IContactManagerService as a parameter.

    public class ContactController : Controller
{
private IContactManagerService _service;

public ContactController()
{
_service = new ContactManagerService(new ModelStateWrapper(this.ModelState));
}

public ContactController(IContactManagerService service)
{
_service = service;
}

}


The ContactManagerService needs take IValidationDictionary as a parameter, however, the implementation of IValidationDictionary ModelStateWrapper needs to take a ModelStateDictionary, and this ModelStateDictionary needs to be the ModalState object of the controller, so it introduces a dependency on the controller.




public class ModelStateWrapper : IValidationDictionary
{
private ModelStateDictionary _modelState;

public ModelStateWrapper(ModelStateDictionary modelState)
{
_modelState = modelState;
}

public void AddError(string key, string errorMessage)
{
_modelState.AddModelError(key, errorMessage);
}

public bool IsValid
{
get { return _modelState.IsValid; }
}
}


Everything is fine until you try to use an injection framework to create the controller, then it will complains the circular dependency.



image

Saturday, June 20, 2009

CSS positioning

The css style is easier to understand compare to the css positioning.  The css positioning has four values:

static | relative | absolute | fixed

  • Elements that don't use any positioning methods are called static. This is the normal case.The values absolute and fixed imply that the element must be a block. The value of the display property is ignored in this case. Elements that are not static make use of the four positioning properties: top, right, bottom, and left. In other word, if the elements are static, those positioning properties don’t make sense here.
  • Containing block
    • The containing block for a fixed positioned element is always the viewport.The parent, or even any other positioned elements, has no influence on the position of an element with position: fixed.
    • Relatively positioned elements, like normal static elements, don't have a containing block. The positioning properties bottom, left, top, and right move the element up, right, down, or left from its normal position. Fixed elements stay fixed to the window. If the window has a scroll bar, the fixed elements do not move with the scroll bar. Absolutely positioned elements, even if they are initially placed relative to the window, move along with the scroll bar.
    • Relative positioning: However, the typical use of relative positioning is to position elements away from their normal position without influencing the position of other elements. There aren't many reasons for doing that in a style sheet, and the main reason relative positioning exists at all is to provide a way for scripts to animate the text – to make it "explode" when a page is unloaded or make it slowly move into place when the page is loaded.
    • The containing block for a fixed element is thus always the viewport, we need set width, either the left or right, and the top or bottom.
    • There are two major ways in which absolute positioning can be used. One is to have a few small absolutely positioned elements in an otherwise normal document; for example, to put a logo in a corner. The other way is to create "areas" for parts of the document, much like the last example for fixed positioning in the previous section. The difference is that the size of the window isn't taken into account. Although most browsers will use the width of the window for the width of the initial containing block, the height of the initial containing block is unspecified.

Friday, June 19, 2009

CSS margin and Padding

 

image

 

The difference between “margin” and “padding” is that Margin is outside of the box,while the padding is inside the box.