gaskell.org http://gaskell.org picking up where teh rest leave off Thu, 01 Jan 2009 05:06:40 +0000 http://wordpress.org/?v=2.7 en hourly 1 undefined method ‘guard_condition’ when using subdomain_fu on Rails 2.2 http://gaskell.org/undefined-method-guard_condition-when-using-subdomain_fu-on-rails-22/ http://gaskell.org/undefined-method-guard_condition-when-using-subdomain_fu-on-rails-22/#comments Thu, 01 Jan 2009 05:06:40 +0000 andy gaskell http://gaskell.org/?p=110 frank and charlieWhile working with subdomain_fu I was having some issues with routes and it was suggested in the railscasts comments that installing from the plugin was different than the gem.

keyJ says:

I found that I makes a difference whether you install it as a plugin (from github) or a gem. With the gem I could not get the route to accept the :subdomain-condition correctly. But then I installed the plugin with ./script/plugin install…
and all of a sudden it worked fine.

This got me a step closer. When I restarted Apache I got this error message:
undefined method `guard_condition' for class `ActionController::Routing::Optimisation::PositionalArgumentsWithAdditionalParams'

I eventually figured out that this code was added a couple months ago - I removed the code referenced in the blog post and now my routing issues are resolved.

]]>
http://gaskell.org/undefined-method-guard_condition-when-using-subdomain_fu-on-rails-22/feed/
Hey Nick, let us know how you really feel http://gaskell.org/hey-nick-let-us-know-how-you-really-feel/ http://gaskell.org/hey-nick-let-us-know-how-you-really-feel/#comments Wed, 08 Oct 2008 14:37:54 +0000 andy gaskell http://gaskell.org/?p=100 At least I’m not running for vice president…

He's a happy boy!

He's a happy boy!

]]>
http://gaskell.org/hey-nick-let-us-know-how-you-really-feel/feed/
Rails helper distance_of_time_in_words ported to C# http://gaskell.org/rails-helper-distance_of_time_in_words-ported-to-c/ http://gaskell.org/rails-helper-distance_of_time_in_words-ported-to-c/#comments Mon, 29 Sep 2008 06:31:10 +0000 andy gaskell http://gaskell.org/?p=85 kabouter can scale.While learning rails I came across a very cool helper method called distance_of_time_in_words. You’ve probably seen this method in action if you’ve used Twitter - no guessing about time zones and as a user I think it’s a nice touch. So on to the port itself…

The Good
C# is automatically faster because everyone knows Ruby is slow and that rails can’t scale.
Seriously though, the port to C# uses resource files so internationalization is handled by simply adding a translated resource file to your project.

The Bad
C# doesn’t have the concept of static extension methods. To me DateTime.DistanceOfTimeInWords would be much nicer than DateHelper.DistanceOfTimeInWords.
Range support in the language is hokey at best. No ranges in switch statements. bleh.

The Ugly
The code! If you compare the C# version to the Ruby version it’s a little ahhhhhhhhhhh… inelegant? The Ruby version weighs in at 28 lines of readable code. The C# version is a b-e-a-s-t with 55 lines of code including 2 helper methods. I’m open to any suggestions in making the C# code shorter or more readable.

The Rest
The method time_ago_in_words has also been ported. Altogether the helper code is 74 lines - also included is over 250 lines of test code. All examples listed on the Rails page were also included in the test.

You can grab the code here or at the subversion repository http://svn.gaskell.org/helpers

]]>
http://gaskell.org/rails-helper-distance_of_time_in_words-ported-to-c/feed/
Bulletproof Ajax with ASP.NET MVC (this time with jQuery) http://gaskell.org/bulletproof-ajax-with-aspnet-mvc-this-time-with-jquery/ http://gaskell.org/bulletproof-ajax-with-aspnet-mvc-this-time-with-jquery/#comments Sun, 10 Aug 2008 22:11:11 +0000 andy gaskell http://gaskell.org/?p=81 As a follow up a recent post about using unobtrusive javascript and Ajax in your ASP.NET MVC applications, I ported the Bulletproof Ajax bookstore application to use jQuery instead of Hijax. This led to more terse code - lines of javascript were reduced from 178 to 41. If you’ve spent at least few hours jQuery then you should find that the new code is also more readable. No server side code changes were necessary.

jQuery is also really easy to extend - I wrote a couple of extensions that would be usable throughout an application. Here’s the extension I wrote to produce the ubiquitous yellow fade effect:

(function($) {
   $.fn.yellowFade = function() {
    return this.css({backgroundColor: "#ffffcc"})
    .animate({backgroundColor: "#ffffff"}, 1500, "linear");
   }
 })(jQuery);

Calling this method flows with the rest of jQuery style chaining of methods:

function(data) { $("div#basket").html(data).yellowFade(); });

This one liner is a callback from our http post to the /Cart/AddProduct. The data parameter contains the response from the server. $("div#basket") is getting the container div from our shopping cart. Then we replace the html within the shopping cart div with the response from the server and follow it up with a yellow fade to provide user feedback.

Code is downloadable here. The demo.

]]>
http://gaskell.org/bulletproof-ajax-with-aspnet-mvc-this-time-with-jquery/feed/
Microsoft’s Ajax Support for ASP.NET MVC Fails (for now) http://gaskell.org/microsofts-ajax-support-for-aspnet-mvc-fails-for-now/ http://gaskell.org/microsofts-ajax-support-for-aspnet-mvc-fails-for-now/#comments Tue, 05 Aug 2008 04:10:22 +0000 andy gaskell http://gaskell.org/?p=73 But it’s not an epic fail (for now). It’s important that my sites function without javascript or Ajax support. Ajax should be used enhance usability and is not a requirement to access my content.

I was checking out Hanselman’s Ajax example (the truly lazy can download the code here) and I was pretty bummed when I disabled javascript and saw this:

failure on the ajax front

Oops. That’s probably not what the user expected. Maybe there’s some way to get the AjaxHelper to save us but none of the 10 overloads for the ActionLink or Form methods stood out to me. Until I get around to really learning jQuery, I’ll stick with writing Ajax by hand. This allows me to request different urls based on whether or not javascript is enabled. And writing your own javascript really isn’t that hard - go grab a good book.

]]>
http://gaskell.org/microsofts-ajax-support-for-aspnet-mvc-fails-for-now/feed/
Bulletproof Ajax with ASP.NET MVC http://gaskell.org/bulletproof-ajax-with-aspnet-mvc/ http://gaskell.org/bulletproof-ajax-with-aspnet-mvc/#comments Sun, 03 Aug 2008 03:26:26 +0000 andy gaskell http://gaskell.org/?p=59 After reading the excellent Bulletproof Ajax by Jeremy Keith, I thought porting the Bulletproof Books sample application to ASP.NET MVC would be a great first attempt at building an ASP.NET MVC application. One of the main points of Bulletproof Ajax is that Ajax should be used to enhance usability and not to make Ajax a requirement to access your content. My version of the Bulletproof Books Shop also makes Javascript and XMLHttpRequest support optional.

Keeping the site accessible to most web browsers took some extra work and consideration when building the Controllers. I decided that any HomeController actions would render html for the entire page.

   13         public ActionResult Index()

   14         {

   15             ViewData.Model = Product.Products;

   16             return View(“Index”);

   17         }

   18 

   19         public ActionResult AddProductToCart(string productID, int quantity)

   20         {

   21             CartController cartController = new CartController();

   22             cartController.AddProduct(productID, quantity);

   23             return Index();

   24         }

   25 

   26         public ActionResult RateProduct(string productID, string rating)

   27         {

   28             RatingController ratingController = new RatingController();

   29             ratingController.RateProduct(productID, rating);

   30             return Index();

   31         }

Controllers that refresh partial chunks of html will know how to respond to actions (add product to cart, rate a product) and render views mapped to MVC user controls. The client will make http requests to different urls based on javascript support in the browser. For example to add a product to a cart with javascript enabled, the javascript will make a post to /Cart.mvc/AddProduct and the server will response with a chunk of html. To add a product with javascript disabled the client will post to /Home.mvc/AddProductToCart and the server will respond with an entire page. The HomeController ends up forwarding the call to the appropriate controller so we’re able to avoid duplicating logic.

   28         public ActionResult DisplayCart()

   29         {

   30             Cart cart = GetCart();

   31             return View(“Cart”, cart);

   32         }

   33 

   34         public ActionResult AddProduct(string productID, int quantity)

   35         {

   36             Cart cart = GetCart();

   37             Product product = Product.Products.Find(s => s.ID == productID);

   38             cart.AddProduct(product, quantity);

   39             SetCart(cart);

   40             return View(“Cart”, cart);

   41         }

One thing I’m not sure about is state management in ASP.NET MVC, so I’m currently storing the cart and ratings in session.

   22         private Rating GetRatings()

   23         {

   24             Rating rating = System.Web.HttpContext.Current.Session["Rating"] as Rating;

   25             if (rating == null)

   26             {

   27                 rating = new Rating();

   28             }

   29             return rating;

   30         }

   31 

   32         private void SetRating(Rating rating)

   33         {

   34             System.Web.HttpContext.Current.Session["Rating"] = rating;

   35         }

You can download the source here.
]]>
http://gaskell.org/bulletproof-ajax-with-aspnet-mvc/feed/
Getting access to MSDN downloads with the Empower ISV program http://gaskell.org/getting-access-to-msdn-downloads-with-the-empower-isv-program/ http://gaskell.org/getting-access-to-msdn-downloads-with-the-empower-isv-program/#comments Sat, 12 Jul 2008 06:50:04 +0000 andy gaskell http://gaskell.org/?p=58 Ok, so like 99% of my blog entries are about things not working quite the way I think they should and here’s another example. When linking your Passport account to your MSDN Subscription you’re asked to provide your Benefit Access Number. The number they’re looking for is your Technical ID available on Microsoft Parter Program site. Under Requirements & Assets click Assign Contact Roles.

This method didn’t work for me on the day I received my MSDN shipment - I had to wait a couple days for it to work.

]]>
http://gaskell.org/getting-access-to-msdn-downloads-with-the-empower-isv-program/feed/
Installing pymedia on Ubuntu http://gaskell.org/installing-pymedia-on-ubuntu/ http://gaskell.org/installing-pymedia-on-ubuntu/#comments Thu, 10 Jul 2008 03:51:37 +0000 andy gaskell http://gaskell.org/?p=57 I’ve been trying to install pymedia on a clean install of Ubuntu Hardy Heron and I was wasn’t able to get it to build using the official docs. Fortunately I found a couple of great blog posts. I ended up having to make a couple of changes:

To install the dependencies I used:

sudo apt-get install python-dev libogg-dev libvorbis-dev liblame-dev libfaad-dev libasound2-dev python-pygame

I had to go to /usr/bin and run this as Michael suggests:

ln -s g++-3.4 g++
]]>
http://gaskell.org/installing-pymedia-on-ubuntu/feed/
Free (and not so free) Windows FTP Clients http://gaskell.org/free-and-not-so-free-windows-ftp-clients/ http://gaskell.org/free-and-not-so-free-windows-ftp-clients/#comments Thu, 10 Jul 2008 02:29:43 +0000 andy gaskell http://gaskell.org/?p=56 SmartFTP started charging for their Windows FTP client so I decided to look for a suitable truly free replacement (not a lite version or one with nag screens) and FileZilla seems like the best option out there.

Filezilla isn’t quite as pretty as SmartFTP but FileZilla does have a local and remote browser similiar to SmartFTP - super easy to use. I’ve used it to upload and modify files on my host as well as FTP files over to a WinCE device that I’m developing on - so far it’s worked great.

]]>
http://gaskell.org/free-and-not-so-free-windows-ftp-clients/feed/
Disable Blocked File Protection Control in Windows Vista http://gaskell.org/disable-blocked-file-protection-control-in-windows-vista/ http://gaskell.org/disable-blocked-file-protection-control-in-windows-vista/#comments Fri, 27 Jun 2008 04:54:30 +0000 andy gaskell http://gaskell.org/?p=52 In my neverending quest to make Vista more usable, I finally caved and took the time to figure out how to disable Blocked File Protection Control. This “feature” requires you to unblock files you download before they are usable (for the most part). This is a bad decision in my opinion - I decided to download a file and of course I’m going to want to work with it. I don’t want to figure how how to unblock before I can use it. What a pain - anyway enough with the rant.

Unblocking files sucks

If you want to be able to use your files after you download them, you’ll need to either use the Group Policy Editor described here in as Method #3 or edit the registry.

Unfortunately I happen to be running Windows Vista Home Premium on one of my systems - this means no gpedit. The entry we need to set is:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Attachments\SaveZoneInformation

This value needs to be a DWORD set to 1. You can enter this manually or download the reg file and “Unblock” your last file! Be sure to close all instances of Internet Explorer or reboot your computer after making the change to your registry.

]]>
http://gaskell.org/disable-blocked-file-protection-control-in-windows-vista/feed/