Category Archives: Uncategorized

30 Days with IE11

I decided that when I installed Windows 8.1 I was going to give Internet Explorer 11 a try. Put aside my historical prejudices and see if in fact IE11 is a better IE. Well I used it as my exclusive primary browser for 30 days on my home machine. No Chrome and no Firefox (other than developing against, yay! Firebug).

After 30 days (that’s today) I am moving back to Chrome. I can say that IE11 is infact a better IE, in fact I can say its (and I almost have to clinch my teeth to get this out) isn’t a horrible browser. There are some great improvements in particular with the Javascript and HTML engine and I was more than once impressed at how fast the rendering engine rendered a busy page.

That’s right I said it, IE11 isn’t the scourge that IE once was, and in fact I will go so far to say that IE11 is actually a decent browser. If your wondering “well if its not so bad why are you going back to Chrome?”.

Simple IE11 has improved the experience for the user when surfing the internet when using Internet Explorer, however its still IE. What?! Meaning the internet is still written to handle IE in a “different” way. Several websites have IE specific coding and CSS layouts because of the IE of yesterday. It’s a real pain to have to add a site to the “Compatibility View Settings” so that IE11 renders that page like IE10 – just to get the page to work.

Why do I like Chrome better than Firefox? One simple reason: it syncs better with my Google account. I use Chrome on several computers and its awesome to have my bookmarks, passwords, history synced up across those machines – and to have that all linked with my Google account. I know Firefox has a sync capability but its with Mozilla and frankly its not as slick as the integration you get with Chrome and Google.

My Pylons (Pyramid) Notes

I had this idea that I would make a new site using Pylons as the framework. So I headed over to www.pylonsproject.org and I see that its no longer Pylons its Pyramid. Ok so be it.

Well download the doc and I find out the Pyramid guy doesn’t seem to like MVC for web development, eh?:

You Say Pyramid is MVC, But Where’s The Controller?
The Pyramid authors believe that the MVC pattern just doesn’t really fit the web very well. In a
Pyramid application, there is a resource tree, which represents the site structure, and views, which
tend to present the data stored in the resource tree and a user-defined “domain model”. However,
no facility provided by the framework actually necessarily maps to the concept of a “controller”
or “model”. So if you had to give it some acronym, I guess you’d say Pyramid is actually an
“RV” framework rather than an “MVC” framework. “MVC”, however, is close enough as a general
classification moniker for purposes of comparison with other web frameworks.

So right off the bat i got a bad taste as I personally *LOVE* MVC and I cannot understand why anyone with any real experience in using it would say otherwise in a decent size web application.

At any rate I start to get into Pylons, er excuse me Pyramid, kudos to that team for some great documentation. After reading, perhaps browsing is better stated?, the 700+ page PDF I decided its not really the framework I would use in any production environment.

Why? Well several things struck me as very odd;
1. The author of a web framework doesn’t like MVC – yea really that’s a big deal for me.
2. Since its not using “controllers” per say its a bit confusing the “routing” – again a hangup for me with my MVC heavy background.
3. Too many choices. Yes really this is a complaint. I say this as the docs point out 3 ways to do something good, but really nothing done well. I rather take an opinionated stance and show how to do what you think is best – well.
4. Seems either over enginered or just complicated by the many config files; setup.cfg, *.ini, setup.py.
5. Static asset routing seems really odd. I guess I expect to just set a route to a path and that automatically serve requests for objects in that view. Meaning I would expect “/favicon.ico” is served via a route setup pointing “/” to a folder – not having to setup a static route for every file.

Its an interesting framework, just not for me. I kept reading the documentation thinking – this would be so much easier and cleanly implemented in MVC.

Ah well onto CherryPy.

Ruby Impressions So Far

Well I have decided to try to learn Ruby and see what I can create with its web frameworks (something like Sinatra or even Rails). So I picked up a couple of books and started reading.

So far here are my (read; from a long time C# developer) Ruby take aways.
* Class inheritance is single (like C#) but you can include unlimited number of “modules” as you like
* All Classes are partial.
* Basic built in classes is small set; Fixnum, Bignum, String, Range, Array and Hash
* Several of the “methods” do different thing based on case, ie “%w” and “%W” string delimiter – eek
* The inclusive and exclusive range of “..” and “…” is well weird.
* True, False, “0” and “1” are all logically “true” and only nil is “false” – uhm wow; this seriously tweeks my head.
* An array can contain any type (or object) which means “Array” is like Dictionary
* .freeze will let you make a class that cannot be modified – but evidently you will be ostracised by the Ruby community for using it.
* Class “Attributes” are like Clas Properties.
* The distinction between “@variable” and “@@variable” is that the single is instance variable and double is class variable (persists, think const).
* Methods (code that is def … end) doesnt need a “return” it magically returns the last value in the method. This is very strange to me as I want to see the “return batman;” – syntactical sugar I realize.
* Mixin method inheritance call is seemingly backwards from constants in their order of location. Is this just to confuse people? Seems like it to me.
* Same as JS with the ‘==’ and ‘===’ comparison operator. I wish C# had this operation as succient as this. The “is” and comparision of typeOf works but isnt as clear.
* “Unless” conditional statement is interesting. Its like reverse of an “if”.
* Statement modifiers are nice, but I can see it being confusing as its the logic to perform the statement after the statement, but it does make for succient code.
* Case statements dont have “fall through”
* “while” and “until” are opposite. “while” loop is as long as the condition is true, and “until” is until the condition is false.
* “for” loop is like “for each” in C#, meaning you get a local variable in the loop scope for iteration through a variable collection.
* “rescue” is like “catch” in exception handling
* “ensure” is like “finally” in exception handling
* “raise” is like “throw” in exception handling
* Exceptions bubble up the stack if no “rescue” handler is found – exactly like C#
* For a class definition the “<" is the same as ":", ie "class MyError < RuntimeError" same as "class MyError : RuntimeError" * Class method "initialize" is same as "~" * Using the "File.Open ... end" block is like a using() statement, in that the File is closed on block exit. * Threading is much simplier in design in Ruby over .NET threading - much.

Arch Linux + lighttpd + Mono == ASP.NET MVC 3

I had a time getting my cheap linux box hosting configured to host my ASP.NET MVC 3 application. These notes are how I got it working using mono 2.6.10 on my Arch Linux 200510

In this example I setup a directory to host my application (I will get to what files and how later) I placed these files in the ‘/srv/http/mysite’ folder.

1. Install mono, lighttpd and fcgi on the box

pacman -Sy
pacman -S mono lighttpd fcgi

2. Setup lighttpd to use FastCGI edit the ‘/etc/lighttpd.conf’ file and modify this line;

server.document-root    = "/srv/http/mysite"

3. Add this line to the end of your ‘/etc/lighttpd.conf’ file;

include "fastcgi.conf"

4. Put this into your ‘/etc/lighttpd/fastcgi.conf’ file;

include "mono.conf"
server.modules += ( "mod_fastcgi" )
fastcgi.server = (
        "" => ((
                "socket" => mono_shared_dir + "fastcgi-mono-server4",
                "bin-path" => mono_fastcgi_server,
                "bin-environment" => (
                        "PATH" => "/bin:/usr/bin:" + mono_dir + "bin",
                        "LD_LIBRARY_PATH" => mono_dir + "lib:",
                        "MONO_SHARED_DIR" => mono_shared_dir,
                        "MONO_FCGI_LOGLEVELS" => "Standard",
                        "MONO_FCGI_LOGFILE" => mono_shared_dir + "fastcgi.log",
                        "MONO_FCGI_ROOT" => mono_fcgi_root,
                        "MONO_FCGI_APPLICATIONS" => mono_fcgi_applications
                ),
                "max-procs" => 1,
                "check-local" => "disable"
        ))
)

5. Put this in your ‘/etc/lighttpd/mono.conf’ file;

index-file.names += ( "index.aspx", "default.aspx", "Default.aspx" )
var.mono_dir = "/usr/"
var.mono_shared_dir = "/tmp/"
var.mono_fastcgi_server = mono_dir + "bin/" + "fastcgi-mono-server4"

### The root of your applications
# For apps installed under the lighttpd document root, use:
var.mono_fcgi_root = server.document-root

### Application map
# A comma separated list of virtual directory and real directory
# for all the applications we want to manage with this server. The
# virtual and real dirs. are separated by  a  colon.
var.mono_fcgi_applications = "/:."

Make sure you didn’t fat monkey up the conf files by doing this;

$ lighttpd -t -f /etc/lighttpd/lighttpd.conf

Should return a “OK”

Now go into your ASP.NET MVC app and setup the references to be “Copy Local” True on these assemblies (if you don’t have the assembly reference by the project add it, you might need to look in “Assemblies -> Extensions” to find some of these) ;

System.Web.Helpers.dll
System.Web.Helpers.xml
System.Web.Mvc.dll
System.Web.Mvc.xml
System.Web.Razor.dll
System.Web.Razor.xml
System.Web.WebPages.Deployment.dll
System.Web.WebPages.Deployment.xml
System.Web.WebPages.dll
System.Web.WebPages.Razor.dll
System.Web.WebPages.Razor.xml
System.Web.WebPages.xml

Make sure you DO NOT have the Microsoft.Web.Infrastructure.dll file, it doens’t work with Mono and causes errors.

Now just publish your project to a folder somewhere, then go into that folder and get the entire contents to the ‘/srv/http/mysite’ folder. Sure you can setup FTP and all that fanciness but I just use WinSCP and copy directly from my publish folder into the ‘/srv/http/mysite’ folder.

Now start lighttpd on the box and you should have the joy of ASP.NET MVC 3.

Enjoy!

References;

http://www.mono-project.com/Release_Notes_Mono_2.10#ASP.NET_MVC3_Support
http://redmine.lighttpd.net/wiki/1/Docs:Configuration
https://wiki.archlinux.org/index.php/Lighttpd
http://www.mono-project.com/FastCGI_Lighttpd

Just delete the damn folder…

So I run into a problem where there are folders on my “Storage” drive (like drive “D:” that is way bigger than my boot drive) that for some unknown friggin’ reason I am unable to delete, Windows 7 just gives me some run around and makes me want to take a sledgehammer to the damn thing.

So searching around and I found how to delete it; Change the owner the admin, change the acl’s, then use rmdir from cmd line.

Like so (to whack folder “D:\delete_damnit”);

  • Right-click on folder -> Properties -> Security Tab
  • Click on Advanced button -> Owner tab
  • Edit.. button
  • Select Administrators in ‘Change owner to’, check ‘replace owner on subcontainers and objects’
  • Open cmd.exe as administrator
  • Run ‘cacls D:\delete_damnit /T /e /g Administrators:f’
  • Run ‘rmdir /S D:delete_damnit’

Enjoy!

Adventures in dlna with Blu-Ray players

So the wife and I decided that we would get on NetFlix and be able to stream movies versus going out to BlockBuster. We thought we would go ahead and pick up a new Blu-Ray player that has the streaming built in, and hey while we are at it get one that will also be dlna compliant and connect to my Arch linux powered minidlna media server.

Well getting minidlna setup on Arch via Yaourt is super simple, just a “yauurt -S minidlna” and boom installed. Yay for just works! yay!

So onto getting the Blu-Ray player hooked up to stream pictures, music and video from the dlna server, should be easy enough to get a dlna certified player and, ah, it just happen, right? Pffft.

Off to NFM to pick up a Sony BDP-S470 seems they have it on sale for around $125 and from the manufacturer site it has evertyhing and then some.

I set it up and sure it sees the dlna server, plays the pictures and the music but does not see any movies – no avi, mkv, wmv – nothing. Grrrr. I Make sure the dlna server is working by playing movies via the Xbox 360; works fine indeed.

So return that player and then pick up the Panasonic DMP-BD65, heck its on sale for around $90 and from my cursory search on the net it is dlna certified.

Get it home, hook it up. Humm. Where is the dlna part? Look around the web and find out that the dlna part is only for the European market; not available in the US models. Good grief.

Then off to pick up the LG BD-570 its the most expensive one in my adventure, around $165, but it seems to have Wifi built in and it does have the dlna sticker on the box.

Get it home, hook it up. Endure looks from the wife that I am losing my mind and working on becoming some sort of Blu-Ray exporter. Aha! Eureka right off the bat it sees my dlna server and, wait for it …. Yes! it plays the movies, pictures and music just fine.

Sure the WiFi part stutters a bit playing back some 1080p video (Big Buck Bunny ftw!) but connected on the wired it seems to be excellent in both video and audio.

After some more checking the NetFlix and Vudu works as well. Woot!

Enjoy!

Redirect old aspx to new MVC

I upgraded Dvdcrate.com to be ASP.NET MVC and one of the problem is the old pages are indexed by search engines and being served on search results. So I have the old *.aspx page that I need to fix up and send along to the MVC page.

An example of the page in the search database;
www.dvdcrate.com/viewdvd.aspx?upc=5027035006161

And I need it to go to the new MVC controller and action like this;
www.dvdcrate.com/Media/Detail/5027035006161

So I did it this way, I put this in the Global.aspx.cs file;

        protected void Application_BeginRequest (object sender, EventArgs e)
        {
            var requestUrl = Request.Url.ToString().ToLower();
            if (requestUrl.Contains("/viewdvd.aspx"))
            {
                var equalPos = requestUrl.LastIndexOf("=") + 1;
                var upc= requestUrl.Substring(equalPos, requestUrl.Length - equalPos);
                Context.Response.StatusCode = 301;
                Context.Response.Redirect("/Media/Detail/" + upc);
            }
       }

Probably not the most elegant, but it does work.

Enjoy!

jQuery UI Themeswitcher Cookie Expires

So I disagree with the current setup that is the default configuration with jQuery UI Themeswitcher, it expires the cookie at the end of the session. I mean really if the user is going to change the cookie to some color scheme they like chances are its going to be for longer than the current session and for crying out loud the user is going to expect your site to load the theme they selected last – else it looks broken. Just a poor decision in my opinion – so here is how I fixed it to last 1 year.

Download the themeswitcher.js and save it locally wherever you like.

Now add the “cookieName” below this to the options defition in the file;

    var options = jQuery.extend({
        loadTheme: null,
        initialText: 'Switch Theme',
        width: 150,
        height: 200,
        buttonPreText: 'Theme: ',
        closeOnSelect: true,
        buttonHeight: 14,
        cookieName: 'jquery-ui-theme',
        cookieExpires: 365,
        onOpen: function () { },
        onClose: function () { },
        onSelect: function () { }
    }, settings);

Now modify where the cookie gets made to use this new “cookieExpires” option (line 49);

        $.cookie(options.cookieName, themeName, { expires: options.cookieExpires });

Know you can either use the default set here (365) or set your own in the initializer in your calling script;

    $('#switcher').themeswitcher({ cookieExpires: 365, path: '/', loadTheme: "Sunny"});

Enjoy!

Securing ELMAH with ASP.NET MVC

So I like Elmah and its logging of my unhandled exceptions suer, but I don’t need every yahoo with visibility to that. This is the steps I took to only allow Elmah access to users in the “Admin” role and have it still work with ASP.NET MVC.

Put this into the web.config;

  
    
      
        
      
      
        
        
      
    
  

Now put this into your global.asax, up top (before all the other routing) is best;

            routes.IgnoreRoute("admin/elmah.axd");
            routes.IgnoreRoute("admin/{resource}.axd/{*pathInfo}");

You don’t have have any controller action setup, the handler builds this on the fly to handle the incomding axd request. Nice and simple.

Enjoy!

Simple merging object to object

I use View Models to hand to my MVC views, nice and slim with little if any methods on them and I use a think ORM model that has all my business logic and is generated by my ORM (BLToolkit).

So the problem is I wanted to take the View Model and update the ORM model with the modified values from the post, kind of a reverse AutoMapper (or BLToolkit.Mapper).

So a ORM class like this;

    public class Contact
    { 
         public int Id { get; set; }
         public string Firstname { get; set; }
         public string Lastname { get; set; } 
         // Loads of other properties
    }

And a View Model like this (note the type and name should be “EXACTLY” the same;

    public class ContactModel
    { 
         public int Id { get; set; }
         public string Firstname { get; set; }
         public string Lastname { get; set; } 
    }

Then with this generic Extension method;

        public static void MergeWith(this T1 primary, T2 secondary)
        {
            foreach (var pi in typeof(T2).GetProperties())
            {
                var tpi = typeof(T1).GetProperties().Where(x => x.Name == pi.Name).FirstOrDefault();
                if (tpi == null)
                {
                    continue;
                }
                var priValue = tpi.GetGetMethod().Invoke(primary, null);
                var secValue = pi.GetGetMethod().Invoke(secondary, null);
                if (priValue == null || !priValue.Equals(secValue))
                {
                    tpi.GetSetMethod().Invoke(primary, new object[] { secValue });
                }
            }
        }

So you make the magic in the Controller (for example) like this;

[Authorize]
[HttpPost]
[ValidateAntiForgeryToken]
[ValidateInput(false)]
public ActionResult EditContact(ContactModel model)
    Contact c = Repo.Get<Contact,long>(model.Id);
    c.MergeWith<Contact,ContactModel>(model);
    Repo.Update<Contact>(c);
}

Yea its cheesy, but it works for me 😉

Enjoy!