Wednesday, November 27, 2013

Upgrade from ASP.NET MVC 4 to ASP.NET MVC 5

Personally, I think Microsoft makes a mistake in not making ASP.NET MVC 5 compatible with Visual Studio 2012. You need to follow the instructions in these 2 links to make it work:

After giving it some thought, the underlying problem is that Visual Studio is highly coupled with specific versions of .NET (and there is no reason why it's done that way). After all, Visual Studio is just an IDE, and it (ideally) should be able to compile code for any version of .NET as long as you have the specific version of the .NET framework installed.

Friday, November 8, 2013

XMLHttpRequest cannot load http:/// Cross origin requests are only supported for HTTP

Lately I've been learning socket.IO in preparation for a new project. You'll come across simple errors as with any new tool you learn. The first error I had to figure out with this technology was: 

XMLHttpRequest cannot load http:/// Cross origin requests are only supported for HTTP

The solution is simple, but it's part of the learning process. It turned out that I was loading the page in a browser as E:\example.html instead of http://localhost:8081/example.html. Fortunately it only took me a few minutes to fix.

Tuesday, November 5, 2013

KnockoutJS Tips and Tricks

I wanted to share this video by Ryan Niemeyer, who talks about really useful things to know about KnockoutJS

Saturday, October 19, 2013

Autoformatting in Xcode

Xcode is not as helpful as Visual Studio when it comes to formatting code. Moreover, if your developers don't follow code standards as much as you'd like, you'll end up with ugly code. Probably the best option is to use Xcode formatter (, which uses uncrustify to achieve the formatting. You can even edit the rules to follow your own code standards. I found it very helpful, since you can run it after each build.

Monday, October 7, 2013

Auto Layout on iOS Versions prior to 6.0 error

It happened to me after updating to Xcode 5. There are possible solutions to this error. In my case first I tried disabling the auto layout checkbox in the xib's that were causing this error. But this didn't seem like a clean solution. I googled a little more and found that the deployment target was set to 4.3, when it should be set to 6.0 since I'm using auto layouts.

It seems like Xcode 4 should also throw this error, but it didn't. So this error isn't related to Xcode 5, it's just that Xcode 5 does tell you about it.

Wednesday, September 4, 2013

Knockout performance in Internet Explorer 8

Knockout offers a lot of advantages, but when in comes to IE8 there are some things to consider:

1) Minimize the number of observables you have. Sometimes it's not necessary to have observables for everything, so if you don't need to observe a variable, don't declare it as one. I have received an alert in IE8 saying "a script is running slow in the page" because of this.

2) Plugins and advanced techniques sometimes generate the same alert "a script is running slow in the page". This happened to me when I used the mapping plugin, so I ended up doing the mapping manually instead of using the plugin. My guess is that the flexibility of the plugin comes with the need to execute more lines of code. That's why sometimes it's better to "hardcode" the steps instead of letting knockout "do the magic". At least for IE8.

Tuesday, August 6, 2013

Nice tips for Xcode

I'd like to share this post about time saving tips in Xcode. The ones I like the most (because I didn't know them) are the shortcuts:

command + shift + O
command + control + up arrow

Monday, July 8, 2013

Ninject with MVC4: No parameterless constructor defined for this object

I've been a big fan of StructureMap, but a few days ago I decided to investigate a simpler framework for DI. I heard about Ninject a long time ago and decided it was time to learn it by applying it to the controllers in MVC4. There are a lot of usefule posts out there that explain how to use it, just keep in mind 2 things:

1) Put your code in App_Start/NinjectWebCommon.cs instead of the global.asax
2) After finishing the tutorials, I got the error "No parameterless constructor defined for this object". This post from StackOverflow has the correct answer! Basically you need these 2 code snippets:

public class NinjectControllerFactory : DefaultControllerFactory
    private IKernel ninjectKernel;
    public NinjectControllerFactory(IKernel kernel)
        ninjectKernel = kernel;
    protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
        return (controllerType == null) ? null : (IController) ninjectKernel.Get(controllerType);
ControllerBuilder.Current.SetControllerFactory(new NinjectControllerFactory(Kernel));

Friday, July 5, 2013

Setting the password for a Git repository in Continuous Integration systems

Continuous Integration systems like CC.NET or Hudson don't let you specify the username/password with which you'll connect to Git. But there's an easy way, just set the repository url to:

Sunday, May 19, 2013

Loading videos on the fly using video.js

Video.js doesn't have a lot of documentation when it comes to doing really cutom stuff. For example, loading videos using a partial postback and changing the subtitles. Fortunately I'm not the first one to run into this problem, and I found this link that shows how to do it. It works in Chrome and Firefox. IE 8/9 is different because it's Flash, so you have to check the browser type before executing the code.

Tuesday, May 14, 2013

Uncaught Error: ko.applyBindings: first parameter should be your view model; second parameter should be a DOM node

This problem happens when you call applyBindings. The problem here is that your view is a jQuery object, not a DOM element. It can be fixed by appending [0], as described here.

Monday, May 13, 2013

Binding a partial view with knockout

If there's a part of your view which you don't want to bind right away, you can defer it very easily. The basic solution is to include this code:

ko.bindingHandlers.stopBinding = {
    init: function ()
        return { controlsDescendantBindings: true };

        <!-- ko stopBinding: true -->        
        <!-- /ko -->

You can also check out this detailed solution.

Monday, April 1, 2013

IIS ends debugging session because of a timeout

When debugging SharePoint code in Visual Studio, sometimes the debugging session will end unexpectedly. If the error is "Web site worker process has been terminated by IIS", then removing the timeout is really easy. You just need to set Ping Enabled to false and the Ping Maximum Response Time to a really large number. You can also follow these instructions.

Thursday, March 28, 2013

HTML5 video

One of the best options is VideoJS. I recently looked into it and found these advantages:

1) It works with IE8. It seems to use a Flash player wrapper to play the mp4 video.
2) It supports subtitles and captions in different languages.
3) It's simple to use. You can get started with just a few lines of code.
4) I found Firefox doesn't support mp4, but ogg files will work.
5) It works in mobile devices without any support.
6) It's open source

Sunday, January 13, 2013

Continuous integration for iOS using Hudson

Lately I've been involved in mobile projects, and CC.NET is obviously not a choice for continuous integration. I've been reading a lot of good comments on Hudson so I gave it a try. It's really easy to install, just download Tomcat and drop the hudson .war file in the webapps folder. Then run ./ and you have Hudson running!

Well, that's the first part. The second part is configuring your projects. Everything is really simple, I just want to point out that you definitely want to install these plugins:

1) Subversion (or a plugin for your preferred source control system)
2) Email-ext
3) Log parses (this is necessary because Hudson was returning a successful build when it actually failed)

The configuration of these plugins is simple so I won't cover that. You'll get errors for sure but a quick google search will get you around them.

Sunday, January 6, 2013

Certificate error when connecting to SVN from Xcode

This is a really dumb error. Make sure that in the dialog "Verify Certificate" you click "Show Certificate" and then check "Always trust "servername" when connecting to "url". 

SharePoint ListView that points to List from another site in the same site collection

In a few words, it's not possible. SharePoint ListViews only load lists from the current site. My solution was to use a .NET ListView that has its DataSource property set to SPListItemCollection.GetDataTable().

Of course, you also have to set the Layout template of the ListView, as well as the EmptyTempate and the ItemTemplate. It's just a couple of extra lines of code to write.

Saturday, January 5, 2013

Best free SVN GUI client for OS X

There are not a lot of (free) options out there. I started using just the command line version of svn, and then briefly downloaded a trial version of Versions. Then finally I came across svnX. It has the basic functionality a developer needs on a daily basis (update, revert, commit and diff). However, if you are an administrator, it won't help you to create branches, new repositories and such. I highly recomment svnX for simple tasks.

Download it here.

Wednesday, January 2, 2013

How to -correctly- use SharePoint Property Bags

There are quite a few posts on property bags and how to use them. All of them are incomplete because:

1) There are several ways to access the property bags and the correct one is not always shown, and,
2) The code is incomplete.

Microsoft suggests that methods like SetProperty, AddProperty and DeleteProperty are used to access Property Bags. Also, remember to call SPWeb.Update() to save the changes. If you don't your changes won't persist.