WordPress new install on Windows IIS 7 with 500 Internal Server Error

Wasted 3 hours of my night working on this.  I was asked by a friend to install WordPress for them so that they can do everything.  Sounds like very little work for me.  Sounds like money for old rope.  No problems I thought. BOOM!  500 Internal Server Error. Continue reading WordPress new install on Windows IIS 7 with 500 Internal Server Error

Low Facebook page views (or why have I done all this work for nothing?)

So Facebook seem to have a random algorithm for posting to peoples’ news feeds. I did a test over the last couple of days.  I posted 3 different types of posts to my Facebook page (not timeline, a company page and it only has 450 likes) to see what the number views would be – Facebook page owners get to see how many folks viewed a post.  I was quite shocked actually.  Here are the results to find out why you might have low page views. Continue reading Low Facebook page views (or why have I done all this work for nothing?)

Tables not aligning center in some mail clients

Another one of those pesky email clients not working properly.  With the advent of MailChimp and cool CSS stuff, you kinda get lazy.  I did and forgot to add the old school version of layouts on tables.  I only added the style=’margin: 0 auto’ but Hotmail web based client actually stripped that out!

The Solution

Add align=’center’ as well as the style=’margin: 0 auto;’.  Another simple thing I know I will forget – hence adding it here.

Remove jQuery validation on specific button

So you’ve just built what is the best form ever! It has 1 set of fields, 3 buttons – save, delete, cancel. Pixel perfect styling as per the designers Photoshop file, and the CSS that anyone would dream of. And then it stops working! You click the cancel button! It validates the form!! NO! It’s a cancel button. It should stop what you are doing. Really simple fix, and am just writing it down here because I will forget.

The Solution

Add a css class of cancel on to your button. That’s it. Simple!

IIS, Trailing Slashes, and HTML extension

I hate URLs that don’t end in something.  I do.  I REALLY do.  That’s why most of the website I have built end in .html or for the MVC ones, a trailing slash.  But don’t you just hate it when a search engine or user somehow picks up a URL that doesn’t have the trailing slash? e.g. /my-lovely/url/without-a-slash ARGH!  I see it a lot on WordPress sites because of the amount of sharing going on.  I would have thought this would have come up more often, but it seems people don’t mind it.  I mind.  I think I have trailing slash and .html OCD.  I found this post on stackoverflow which was great but as always it didn’t work – too many blogs saying it does, when it does.  So for posterity here is what I did: Continue reading IIS, Trailing Slashes, and HTML extension

Pixastic Desaturate images with jQuery on mouseover, mouseenter, mouseleave

Had another great morning wangling my way around 4 browsers (7 if include each version of IE). The client had a requirement an image would have a black and white version and this would flip when the user moused in, over, out, etc.

Problem was we couldn’t rely on the client loading a black and white image, or know how to create one…these are clients after all! And having them contact us each time to create the black and white version each time is not going to happen (unless they paid…).

Enter Pixastic.

This is one of the coolest widgets I have the pleasure to work with. It plays with your images soooo nicely and seems to be completely cross browser compatible. Nice work boys! However…

The Problem

When you apply Pixastic’s desaturate code to the image the image disappears out the DOM and a Canvas element replaces it. So if you have done the standard $(image id or class).hover() with jQuery (or mootools or whatever) then when you mouse over it works, but is instantly remove from the DOM so you straight away get a mouse out event being fired. Damn! Not what you want! Worse still the image now reappears causing a mouse over event which, yes you guessed, it flips it back. You get a nice wee flicker happening – not good if you don’t like flash photography!!

The Solution

I won’t go into the depths of what I did. I will just add the code so you get back to your day job and make tonnes of money.

$(window).load(function () {
    $("div.parent").each(function (index, obj) {
        $("#" + $(obj).attr("data-image")).pixastic("desaturate"); // make it black n white
    });

    $("div.parent").mouseenter(function (e) {
        var self = document.getElementById($(e.currentTarget).attr("data-image"));
        Pixastic.revert(self); // make it colour
    });

    $("div.parent").mouseleave(function (e) {
        // make it black n white again (yes I should refactor this...)
        $("#" + $(e.currentTarget).attr("data-image")).pixastic("desaturate");
    });
});

However what you will notice is instead of the code being in the $(document).ready() function call, it’s in the $(window).load(). Images are not fully loaded at $(document).ready() in Webkit (Chrome and Safari). As Pixastic checks to see if the image is loaded with “this.complete” before processing it (otherwise it could try to process something that isn’t there…) then your code needs to be in this function call.

But once you do that, it works a treat! Check out my demo to prove that it works!

Bureaucratic nonsense – or how cookies are going to end the internet

Today website developers in the EU (not including UK for the time being) have to inform users explicitly that they are about to place a cookie on their machine.  They will then need to inform the user that they need to set another cookie on their machine to remember that they have given permission to set the first cookie on the machine.  What.The.Fuck?

Poor Google Analytics

Google Analytics is going to be most hit.  They have the biggest slice of the tracking pie, so how do they set about tell a visitor they are about to set a cookie on the person’s machine.  Or I take it the law will make the website owner state that Google is going to do this?

Poor people that delete cookies on browser shut down

If you clear the cookies from your browser session when you close it, then every time you visit a website you will be asked all these yes or no questions.

That’s just a bit of a pain in the fucking ass.  Stupid European Law makers sitting on some high seat in Brussels over thinking the internet and how they can control it.  Fuck off and leave us alone.

Solution?

It will be hard.  If you are a .NET developer you will know that Session variables can use Cookies.  You will need to change that straight away.  You can use the database solutions, but that’s not really easy to do.  Cookieless URLs become nasty to deal with and will really impact site.  Although I suppose if you are using Session cookies you are probably an application and will be exempt from the regulations.

So my solution would be for the some sort of super cookie.  One that is based on a certificate of some variety, like SSL that shows on the browser chrome, so you get warned that a cookie has is about to be set – a red flashing button.  The user would then click it, a message appears “can this site place the cookie [yes/no]”, with javascript/browser functionality pausing until an answer is given.  Am sure the browsers can tell when new cookies are being set.

Or the really simple option is…if you don’t know how to use your browser, to stop all cookies being set by using Private Browsing mode or the security features already built in, then get off the internet.  You should need a licence to be allowed a computer 😀

Rant not over, more will surely appear.

Depude and randomise 2 lists

I was asked to take 2 lists of names and dedupe the newer list with the names in the older list, so we only had a list of new names in a specific period (no dates here to help out!).  Turned out to be a lot simpler than I thought.  At first I thought Excel spreadsheet as the data wasn’t in a database.  I thought I could do some fancy filter action, but nope!  That was harder than a diamond on a bouncer’s knuckle!

Solution

The solution was a real simple tiny bit of .NET code:

 var likes = System.IO.File.ReadAllLines(@"D:\likes.txt");
 var olds = System.IO.File.ReadAllLines(@"D:\lomb-likes.txt");
 var duped = new List<string>();

 Array.ForEach(likes, like =>
 {
     var found = false;
     Array.ForEach(olds, old =>
     {
         if(old == like)
         {
             found = true;
         }
     });

     if(!found)
     {
         duped.Add(like);
     }
 });

 var result = duped.OrderBy(dupe => Guid.NewGuid()).ToList();

Simples!  Now get on with your work and stop reading my blog!

Microsoft.Web.Administration.dll Scripting IIS 7.0 on Vista

This is not a full article on how to script IIS7.0.  It’s about getting to that point on how to do it.  And as per usual the internet was full of incomplete information.  Here’s my complete solution when I faced problems.

Firstly the namespace Microsoft.Web.Administration was not available, nor was it in the .NET of the “Add reference” menu option.  To solve it I had to browse to:

C:\Windows\System32\inetsrv

and reference the

Microsoft.Web.Administration.dll

in that folder.  The namespace was available, and so I was rocking…straight into another brick wall!  What these other websites again forget to tell you is to set permissions on a specific file that the code I will give in a second, needs to have to be able to run.  So the file is found here:

C:\Windows\System32\inetsrv\config\redirection.config

and you need to give it the ASP.NET/NETWORK SERVICE user in security with READ access.  But guess what!?  Yes that still didn’t solve the issue!  I had to go into IIS7.0, choose the Application Pool I was working with, and change the Identity value to LocalSystem.  So thats:

Open IIS > Expand IIS > Application Pools > [select your application pool] > Advanced Settings > Process Model > Identity = LocalSystem

Job done.  Yes at last!  Woo!  I could then add new Rewrite rules into the web.config without having to manually go into IIS!

The code as promised

using System;
using Microsoft.Web.Administration;

public partial class new_iis : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        using (ServerManager serverManager = new ServerManager())
        {
            Configuration config = serverManager.GetWebConfiguration("HIE");

            ConfigurationSection rulesSection = config.GetSection("system.webServer/rewrite/rules");
            ConfigurationElementCollection rulesCollection = rulesSection.GetCollection();

            ConfigurationElement ruleElement = rulesCollection.CreateElement("rule");
            ruleElement["name"] = @"GoToGoogle2";
            ruleElement["stopProcessing"] = true;

            ConfigurationElement matchElement = ruleElement.GetChildElement("match");
            matchElement["url"] = @"^google$";

            ConfigurationElement conditionsElement = ruleElement.GetChildElement("conditions");
            conditionsElement["logicalGrouping"] = "MatchAll";
            conditionsElement["trackAllCaptures"] = "false";

            ConfigurationElement actionElement = ruleElement.GetChildElement("action");
            actionElement["type"] = @"Redirect";
            actionElement["url"] = @"http://www.google.co.uk";

            rulesCollection.AddAt(0, ruleElement);

            serverManager.CommitChanges();
        }
    }
}

But I never wrote the code. I found it at http://forums.iis.net/t/1150481.aspx so I have to massively thank them for showing how easy it is.  And remember you will be able to edit any part of the web.config via this code, or similar code ’cause you will need to edit it to your needs.