Tuesday, May 29, 2012

Friday, September 2, 2011

Git + Dropbox = Crazy Delicious

Here’s a nifty trick I learned from a Tekpub video:  Use git to push your stuff to a dropbox folder on your machine.  That folder is the “master” repository and then it’s automatically synched with Dropbox.  You can even share it with other people if you’d like.  Here’s how (in git bash):

cd c:/dev/projects/theAwesome
git init
git add .
git commit -am "initial commit"
mkdir c:/dropbox/repos/theAwesome
git remote add origin c:/dropbox/repos/theAwesome
cd c:/dropbox/repos/theAwesome
git init --bare
cd c:/dev/projects/theAwesome
git push origin master

Monday, January 24, 2011

How to Bin Deploy an ASP.NET MVC 3 App

If you need to deploy an MVC 3 application to a server that doesn’t have MVC 3 installed in the GAC, it’s pretty easy to do:

1. Add References

Add the following references to your project:

  • Microsoft.Web.Infrastructure
  • System.Web.Razor
  • System.Web.WebPages.Deployment
  • System.Web.WebPages.Razor

 

2. Set References to “Copy Local”

Set “Copy Local” to true for the following references:

  • Microsoft.Web.Infrastructure
  • System.Web.Helpers
  • System.Web.Mvc
  • System.Web.Razor
  • System.Web.WebPages
  • System.Web.WebPages.Deployment
  • System.Web.WebPages.Razor

 

3. Setup URL Rewriting for Virtual Directories

You only need to do this if you are deploying to a virtual directory.  Say you are deploying to the sub-domain “turtles.mrdustpan.com”, which actually corresponds to a “turtles” virtual directory.  Without the following URL rewrite, your MVC URLs would look like:  turtles.mrdustpan.com/turtles/Home/Index  instead of turtles.mrdustpan.com/Home/Index.

To rewrite the URLs, add this to the system.webServer section of your web.config:

<system.webServer>
    <rewrite>
      <rules>
          <rule name="Remove Virtual Directory">
              <match url=".*" />
              <action type="Rewrite" url="{R:0}" />
          </rule>
      </rules>
    </rewrite>
</system.webServer>

Thursday, January 6, 2011

My Git Cheat Sheet

Here’s a nice little cheat sheet of the most common commands I’ve been using in Git, to push my changes out to Github:

cd /c/dev/projects change directory to c:\dev\projects
git status get the status of current directory
git add . stage all pending adds/updates
git add -u stage all pending updates/deletes
git commit –m "my message" commit the changes with a message
git push origin master push the committed changes to github
git branch myBranch create a new branch named “myBranch”
git branch list all existing branches
git checkout myBranch switch to the “myBranch” branch
git checkout master switch to the “master” branch
git merge myBranch merge “myBranch” into the current branch

cheatsheet

Tuesday, December 14, 2010

Ninject with ASP.NET MVC 3…Easy As 1, 2, 3

  1. Add references to Ninject.dll and Ninject.Web.Mvc.dll (You can use NuGet to add Ninject, but for now you’ll have to download and build Ninject.Web.Mvc yourself).
  2. Create 1 or more modules:

    public class MyModule : NinjectModule
    {
        public override void Load()
        {
            Bind<IFoo>().To<Foo>();
        }
    }
    
  3. Make your HttpApplication (typically global.asax.cs) extend NinjectHttpApplication and override the CreateKernel() method:

    public class MvcApplication : NinjectHttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }
    
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
            routes.MapRoute(
                "Default",
                "{controller}/{action}/{id}",
                new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );
        }
    
        protected override void OnApplicationStarted()
        {
            base.OnApplicationStarted();
    
            AreaRegistration.RegisterAllAreas();
    
            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
    
        protected override IKernel CreateKernel()
        {
            return new StandardKernel(new MyModule());
        }
    }

That’s it.  Now you’re all set to go, even your controllers will be created with Ninject which means all of their dependencies will be resolved using your Module(s).

Thursday, November 18, 2010

Setting Up Git

I’ve never used Git (or any distributed revision control system) before, so I thought this would be a good opportunity to get my hands dirty.  I found a few really helpful resources:

Rather than rehash what these resources wonderfully describe in detail, I’ll just summarize the steps I went through to get msysgit up and running and setting up the repository on Github.  As I said, I’ve never used Git before and I am certainly no expert, so hopefully I won’t get any of the terms wrong.

Installing msysgit

For this I pretty much followed Jason’s instructions step by step for installing msysgit on Windows:

  1. Download the latest version.
  2. Run through the installation steps.
  3. Run Git Bash from the start menu and set the global user.email and user.name settings:
    1. git config --global user.email my@email.com
    2. git config --global user.name “Your Name”
  4. Generate an SSH key pair:
    1. ssh-keygen –C “my@email.com” –t rsa
    2. Press enter when prompted on file location, and twice more for both pass phrase questions.
  5. Right-click on the folder where the project source will live and select “Git Bash here”.
  6. In the Git Bash console, type: git init

Setting up Github

I want to use Github as the central host for my code.  It’s pretty easy to do (Github’s help is also very…helpful):

  1. Create a Github account.
  2. Go to your account settings and click on “SSH Public Keys” and then “Add another public key”.
  3. Open the public key file that was generated above and paste the contents into the Key field.
  4. Create the Atmosphere repository in Github.
  5. Follow the steps on the next page to initialize a local folder as a Git repository.
  6. Create some files.
  7. Create a .gitignore file by typing touch .gitignore
  8. Add ignored folders and files to the .gitignore file (such as obj and bin).
  9. Run git status to see status of changed/added files.
  10. Run git add . to “stage” the files.
  11. Run git commit to commit the changes.
  12. Run git remote add origin git@github.com:MrDustpan/Atmosphere.git to set origin to Github.
  13. Run git push origin master.

And there you have it, the Atmosphere repository is up and running:

https://github.com/MrDustpan/Atmosphere

Hey I’m Gonna Build My Own Blog

I’ve decided to take on the task of writing my own blog engine.  Inspired as I often am by Rob Connery, and filled with a desire to work on some sort of open source project, I figured this would be a good place to start.

Why Would I Do This?

Lots of reasons.  Like I said, Mr. Connery told me to.  Plus I want to try some new things.  I’ve wanted to learn git/github for a while now so I think I’ll put my code out there.  Plus I’ve been meaning to use NHibernate in a real project (and blog about it) for a long time.

I’m going to build this using “best practices” so maybe it will be helpful for others too.  The reason I have that in quotes is because I’ll be using the best practices I know of, which means there’s a good chance they’re not actually the best.  But if everything goes as planned, I’ll learn a lot in the process and maybe have a cool new blog engine that I can call my own.

Features

I want to keep things simple at first, mainly so I’ll actually finish a v1.  In the future I’m sure I’ll add some awesome features, like the ability to make me a sandwich.  Here’s my list for v1:

  • Posts
    • Ability to add/edit/remove posts
    • Ability to tag posts
    • Ability to group posts into a series (I really like this idea)
    • Ability to remove comments
  • Comments
    • Ability to add comments
    • Maybe use markdown?

Time to Get to Work

Well it’s not much, but at this point I have a basic idea of where I want to go.  First steps will be to get the plumbing working, and I’ll start with getting source control setup.  Only thing I need to do now is come up with a name for my blog engine…how about Atmosphere?  Sounds pretty awesome to me.