Thursday, August 30, 2012

Open Blogger Drafts In Windows Live Writer

Blogging is a feast or famine activity for me.  Sometimes the topics and words just flow out as they have recently.  The recent update to Blogger’s administration interface and editing to be themed more like Google+ and Docs is long deserved and an excellent enhancement.  It does miss the ability to handle the displaying of syntax highlighted code, but you can still do it if you want to always view the HTML while writing.  Sometimes I like using the web interface, sometimes I like to use an actual application.  It isn’t very obvious that you can open Blogger drafts and in fact it took me a while to figure it out.   In hind sight, it is rather easy to open your draft posts in Windows Live Writer. 

  1. Start from a normal post window
  2. Click the drop down menu to the left of the “Home” ribbon menu
  3. Click “Open recent post”
  4. Select your blog in the left pane
  5. All of the posts on the blog will display in the list area on the right

At first glance, it looked like it was only posts that were published. This however is not the case; it contains a list of ALL published, scheduled, and drafts. The application doesn’t denote the status of a post (thus my confusion), but at least it is possible to open drafts.

Saturday, August 18, 2012

Visual Studio 2010 Find/Replace with Regular Expressions

I recently encountered a situation that required that I change a nontrivial amount of strings in multiple files where the strings were predictable except for and id. The solution was using regular expressions in Visual Studio. Regular expressions in Visual Studio give to you all the power of .Net's engine plus some useful additions. I am sure there is a way to reduce the escaping, but it worked for me. Here are some examples, some of them are changed slightly from the previous example to accommodate a slightly different case. I am not going to comment on each as the examples should speak for themselves.
Find Regular Expression:
[$]\(\'input\[id[$]=\\\'{:i}\\\'\]\'\)\.focus\(\);

Matches string:
onfocus="$('input[id$=\'btnName\']').focus();"

Replace:
focusCtrl(\'\1\');

Find Regular Expression:
[$]\(\"input\[id[$]=\'{:i}\'\]\"\)\.focus\(\);

Test match string:
$(function () { $("input[id$='btnName']").focus(); });

Replace:
focusCtrl(\'\1\');

Find Regular Expression:
return process\(\'{:i}\', \'{:i}\'\);

Test match string:
return process('txtNameID', 'txtName');

Replace:
return process(\'\1\', \'\2\', \'<%= NameID %>\');

Result:
return process('txtNameID', 'txtName', '<%= NameID %>');

Find Regular Expression:
alt=\"Validation Error\" title=\"[^"]+\" src="/_layouts/images/EXCLAIM.GIF"

Test match string:
<img alt="Validation Error" title="Name is required" src="/_layouts/images/EXCLAIM.GIF" />

Replace:
onprerender="Validator_PreRender" runat="server"

Find Regular Expression:
alt=\"Validation Error\" title=\"[^"]+\" src="/_layouts/images/EXCLAIM.GIF"

Test match string:
<img alt="Validation Error" title="Name is required" src="/_layouts/images/EXCLAIM.GIF" />

Replace:
onprerender="Validator_PreRender" runat="server"

Find Regular Expression:
\<img alt=\"Validation Error\" title=\"[^"]+\" src="/_layouts/images/EXCLAIM.GIF" /\>[ ]*

Test match string:
<img alt="Validation Error" title="Name is required" src="/_layouts/images/EXCLAIM.GIF" />

Replace:
<img onprerender="Validator_PreRender" runat="server" />

Find Regular Expression:
\<span class="ms-error"\>\<img src="/_layouts/images/EXCLAIM.GIF" /\>\</span\>[ ]*

Test match string:
<img alt="Validation Error" title="Name is required" src="/_layouts/images/EXCLAIM.GIF" />

Replace:
<img alt="Validation Error" title="" src="/_layouts/images/EXCLAIM.GIF" />

Tuesday, August 14, 2012

Blogger Template Edit HTML Font Fixup

On occasion I update the HTML of my blog using bloggers built in editor and it displays using something resembling Times New Roman. It is a terrible font to view code with. I tried to see what errors were occurring and FireBug didn't reveal anything. After some digging, I openned Venkman and discovered this little gem:
Error: downloadable font: download not allowed (font-family: "Open Sans" style:normal weight:normal stretch:normal src index:1): content blocked
source: http://themes.googleusercontent.com/static/fonts/opensans/v5/u-WUoqrET9fUeobQW7jkRT8E0i7KZn-EPnyo3HZu7kw.woff
Source Code:
@font-face {   font-family: "Open Sans";   font-style: normal;   font-weight: normal;   src: local("Open Sans"), url("//themes.googleusercontent.com/static/fonts/opensans/v5/u-WUoqrET9fUeobQW7jkRT8E0i7KZn-EPnyo3HZu7kw.woff") format("woff"); }
I felt like i was hot on the trail. After a while googling and not finding any good way to fix it, I created the following GreaseMonkey script.
// ==UserScript==
// @name        Blogger Template Edit HTML Fixup
// @description Script that fixes the HTML template editor dialog's text area.  monospace font unavailable, defaulting to consolas.  Firefox gives me: Error: downloadable font: download not allowed (font-family: "Open Sans" style:normal weight:normal stretch:normal src index:1): content blocked.
// @namespace   net.intellectualponderings.BloggerTemplateEditHTMLFixup
// @include     http://draft.blogger.com/*
// @include     https://draft.blogger.com/*
// @grant       GM_addStyle
// @grant       GM_getValue
// @grant       GM_setValue
// @version     1
// ==/UserScript==

(function () {
  var cssTemplateEditHTMLFixFont = (<>).toString();
  
  //Initial Styles
  GM_addStyle( cssTemplateEditHTMLFixFont );
})();

UPDATE 2012-09-04: Added the @grant statements in the header to make the scripts work with GreaseMonkey 1.0.

Wednesday, August 8, 2012

Make Applications Work With Remote Domain Environment On Unconnected Computer

Working remotely via VPN in an environment where you are not attached to the domain is a pain if windows authentication is in use. Windows doesn't handle domain changes as gracefully as it should, especially if I was only going to be on it for a couple weeks. Fortunately, there are ways that you can remove the road blocks by creating some shortcuts and modifying the shortcuts.

Here are some examples of the shortcut targets I made: (obviously, change the domain\username to your domain credentials for the remote environment)
C:\Windows\System32\runas.exe /user:domain\username /netonly "C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe"
C:\Windows\System32\runas.exe /user:domain\username /netonly "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe"
C:\Windows\System32\runas.exe /user:domain\username /netonly "%comspec% /k \"C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat\" x86"
C:\Windows\System32\runas.exe /user:domain\username /netonly "C:\Program Files (x86)\Microsoft Visual SourceSafe\ssexp.exe"

In some cases you may need to run the applications as administrator. The easiest way I found to escalate privileges:
  1. Right-click on the shortcut
  2. Click Properties
  3. On the "Shortcut" tab, click "Advanced..."
  4. Check the "Run as administrator" checkbox
  5. Click OK (closes the Advanced Properties dialog)
  6. Click OK (closes the Properties dialog)
Now anytime you run that shortcut, it will run as administrator.

This method removed all of my authentication issues and I could development as usual.