• Installing dropbox and dropbox-nautilus in ArchLinux

    If you've tried to install dropbox-nautilus from the source found in the <a href=http://www.dropbox.com>Dropbox</a> website, you'll find that you can't successfully complete the ./configure step of the package due to an error of the script not finding pygtk. This is an issue with Archlinux because of the way python binaries are handled in this distribution. However, you can use the AUR packages to install dropbox and its integration with Nautilus thank to the people that tweaked the scripts to work with Arch.

    The first step you have to take is download the AUR packages. You'll need to download both dropbox and nautilus-dropbox. Save both .tar.gz files at you preferred location and uncompress them using this command:

    tar xvfz <filename.tar.gz>

    Obviously, change <filename.tar.gz> with the filenames you have downloaded. Each tar command will create a folder. Go to the dropbox folder and run this package:

    makepkg -s

    This will build a package and install the required dependencies while doing it if needed (it will ask for your root password if you're doing this without being root). If everything went ok, you'll find a file with the extension .xy in the folder you're in. This is what you need to install, using our beloved pacman (use sudo if you're not root):

    pacman -U <filename.xy>

    This will install dropbox. After this, do the same for the other package: nautilus-dropbox. makepkg -s, pacman -U <filaneme.xy> and you're done, you have Dropbox integrated with Nautilus. Just start Dropbox from your Applications menu and enjoy the service!

  • Routing a hiearchical path in ASP.NET MVC

    If you wonder how to make a GitHub (and other websites) like routes to access to hierarchical paths or files, here's the way to do it in ASP.NET MVC. GitHub is a GIT hosting service, and allows you to browse the repositories. When doing so, it uses a path as a routing parameter, as seen in this URL: https://github.com/erikzaadi/GithubSharp/blob/master/Core/Models/Commit.cs. This includes slashes and so to represent the directories, and is a parameter that depends on the file location inside the repository. A route like this can be done in ASP.NET using the called catch-all parameter.

    The catch-all parameter allows you to use a wildcard on a route, so it takes everything after a given route as a single parameter. You can find the explanation of this feature in the ASP.NET Routing MASDN help page.

    All you need to do to make a route like the one in the example to work is add this code to your Global.asax file, in the RegisterRoutes method:

    routes.MapRoute(
        "Blob",
        "{*path}",
        new { controller = "Blob", action = "GetContents" }
    );

    This will pass the controller Blob a parameter called path that will contain the parameter you want (in the example that would be master/Core/Models/Commit.cs. All you have to do now is use this parameter as you wish so you can access the desired file and show it's contents on a web page.

  • Get the number of days in a month in .NET

    If you've ever wondered how to get the number of days for a given month in .NET, the solution is pretty easy:

    System.DateTime.DaysInMonth(int year, int month)

    Hope it helps!

  • Execute javascript code every time a form is loaded via Ajax.BeginForm

    If you've ever used the Ajax.BeginForm code to render a form in ASP MVC using Ajax (via jQuery, for example), you may have wondered there's an object you can pass to the call called AjaxOptions. This object allows you to pass the BeginForm call some interesting options to further enhance the form when it's rendered. One of those options is specially useful if you want some javascript to be executed just after the form has been rendered. You can always use the $(document).ready in jQuery, but this code will not be called if, for example, the form is rendered after a postback and you have some validation errors (a missing required field, for example). Fortunately, you can use the AjaxOptions object to tell the form to execute a method right after the form has been loaded (for the first time or after a postback).

    Read on →

  • Creating and consuming JSON data in MVC 2

    Recently I started working in a project using MVC 2. I found out a very useful feature to retrieve JSON data from the server using an Action in a Controller.

    This feature is in the base Controller class, which we inherit when we create a new controller. If you take a look into the different methods this class has you'll find those ones:

    //
    // Summary:
    //     Creates a System.Web.Mvc.JsonResult object that serializes the specified
    //     object to JavaScript Object Notation (JSON).
    //
    // Parameters:
    //   data:
    //     The JavaScript object graph to serialize.
    //
    // Returns:
    //     The JSON result object that serializes the specified object to JSON format.
    //     The result object that is prepared by this method is written to the response
    //     by the MVC framework when the object is executed.
    protected internal JsonResult Json(object data);

    Along with this method, there are some overloads that allow more parameters, you can see them all in here: Controller.Json Method. In this example I'll use the first one, which is the simplest.

    Read on →