Main menu

Learning

I’ve been working on this app spec for weeks at work. In an effort to improve on what I’d accomplished, I reached out to my friend, and one of the smartest people I know, Peter Becan. I wanted him to teach me how to do it right. Peter’s been doing this sort of thing for a lot longer than I have, and has a particular knack for it. Learning to correctly prepare an application specification is harder than learning to program, IMHO.

As my spec writing progressed, I’d email Peter PDF output from Scrivener as I accumulate enough new content worthy of a dispatch. marked, which I’m using to preview MultiMarkdown markup in my Scrivener document, generates the formatted PDFs. I realize that as time progresses, keeping Peter in the loop requires a different method. In order to keep him informed, and not have to email him a new PDF every so often, I needed to make use of the web to post the formatted output.

Scrivener

Scrivener supports outputting HTML generated by the MultiMarkdown processor as a Compile For target. There are instructions on how to use MultiMarkdown with Scrivener here, however the instruction appear out of date. I’m using Scrivener 2.2 and some of the preferences mentioned in the instruction have either moved, or no longer exist. Luckily, by setting options using MultiMarkdown metadata and a simple change in the compile settings, I obtained the necessary output.

For posterity’s sake, what I did not find was MultiMarkdown Settings… under the File menu

Two things are necessary to produce the desired output for inclusion in a WordPress page. First, as mentioned in the instructions, I had to enable the exporting of Titles for both Documents and Groups within Scrivener. You do this by checking the check box under Title in the Formatting options of the Compilation Settings sheet.

Second, I opted to use a Meta-Data file at the very top of my Scrivener doc to coerce the MultiMarkdown processor to produce the necessary output. The metadata fields that I use are:

Title: Contractor Spec
Format: snippet

The key is the Format field. What that does is instruct the MultiMarkdown processor to only create the HTML for the given markup and not an entire XHTML page. Clearly if I am including the output in a WordPress page, only the HTML associated with the MultiMarkdown markup is necessary; the cruft associated with a well-formed XHTML page (i.e. HEAD, BODY, etc.) would be in the way. With all the correct metadata and settings in place, I use Compile… with a Compile For of MultiMarkdown -> HTML and save that in its own subfolder within my source tree.

Git

Git. Love it or hate it, it’s the linchpin in the operation. My Git repo resides on the same server as my WordPress installation. Having that scenario started me thinking about how I would get the HTML snippet residing within the repo into a place that I could serve just that content and not the entire source tree. I started Googling update website with git, and sure enough I found what I was looking for. After sifting through several top results, I found that this was the best answer.

I have an addendum to those instructions. For the remote path, I used a file:// path pointing to the path of the real repo on the server. Found that here.

The key to copying the HTML to a place I can include it from is using a post-receive hook in Git. Very simply put:

The post-receive hook runs after the entire process is completed and can be used to update other services or notify users. (taken from Pro Git)

However, if you follow the steps set out in the instructions, you’ll wind up with your entire repo in the web directory. While that may work in most cases, it was not ideal for what I was trying to do. Next pass at Google had me looking for ways to only checkout a subset of the entire repo. The key to that is something entitled a sparse checkout. I used the steps outlined here to only checkout the folder (and it’s content) that contained the HTML snippet. One exception however about the sparse checkout instructions, you will need to include a ‘*’ at the end of the path. Otherwise you will receive from Git:

error: Sparse checkout leaves no entry on working directory

For my “local” repo on the server, I picked a spot outside of the root of the WordPress installation to checkout the files to.

WordPress

Last step in the process. How do I insert a snippet of HTML that resides on disk into a WordPress page? Create your own page template and use a custom field. In the end, this was rather easy, once I learned how to do it. This page at the WordPress codex explains how to create the custom template and where to upload it to your server. Scroll down a bit till you get to the Using Custom Fields section. For this, I’m using a custom field called doc_path. Here is my custom template named docs.php:

This allows me to specify the full path to the HTML snippet on disk that I want included in the WordPress page.

Make sure, as I forgot this the first time I saved my new Page, to set the template for the Page to your custom template like this:

Final Output

Because the application I’m writing the spec for is proprietary, I can’t share the real fruits of my labor with you. However, what I did do is create another page containing a snippet of sample.html from the MultiMarkdown source at github. My sample page is here. P.S. Yes, I am aware that the sample page has a broken image link.

Aside

As I mentioned in my earlier post, the comment spam came in right away after installed WordPress. Now, that’s not to say it was WordPress’ fault. I guess I just didn’t notice them before with Movable Type. Anyway, I simply installed the Disqus plugin. Do understand that I’m not endorsing Disqus; I installed it, and it works.

WordPress

Today I migrated the site off of MovableType and onto WordPress. I had been wanting to do this for quite some time. The hurdle I had to overcome was porting the data from MovableType in such a way that permalinks wouldn’t 404. The first import utility I tried didn’t maintain the entry IDs stored in MovableType. At that point, it wasn’t important enough and I left it alone. I came back to it today, months later, when I went looking for a MovableType theme based on Twitter Bootstrap. When I didn’t find what I was looking for in MT, I found it in WP. Now I had to find a way to get the data across.

Movable Type Backup Importer

I found this plugin in the WP plugins directory. First thing is it used the actual XML backup file created by MT when you select backup and not just export. I had to fix a few ilegal characters that were in spam trackbacks before the plugin would import the data because the XML was invalid. I used a combination of Sublime Text 2 and Firefox (yes, I’m a Chrome user but Firefox does a more explicit job of pointing out errors in an XML doc) to clean up the XML. As for spam, I didn’t bother cleaning it up. I’m confident that the comments on the blog are mostly clean, and I don’t think trackbacks are were all that important.

Once I imported the data, the same issue persisted from the first time I attempted a data import; the IDs were reset on import. So, first thing is I touched base with the author of the plugin, rogerdudler. I then went off on my own to see if there was a way to allow this to work. As it turns out, there is. On line 2582 of wp-includes/post.php, the code comment was clear:

// If there is a suggested ID, use it if not already present

Armed with this new found knowledge, I went back to Roger’s plugin, and added

$post->import_id = $id;

after line 407. That was it. I used another plugin, WordPress Reset, to flush the database. The second import worked like a charm. The WordPress Post IDs matched the MT entry IDs. Almost done. WordPress is dynamic, and MovableType is static. Now, .htaccess and mod_rewrite to the rescue, and a setting change in WordPress, which I’ll get to in a second. Here is the .htaccess file

The first part is what I added, the latter being programmatically generated by WordPress. The setting change came in Settings>Permalinks. I changed the setting to Numeric in order for the links to be similar to MT, and I prefer a flat, static looking permalink. It seems more SEO friendly. After that setting change, everything appears to be working correctly. For example, if you Google “Avistar Sucks” the link is the old MT style until Google updates my permalinks. Clicking on it redirects you to the WP entry. By the way, did you notice the use of R=301 in the rewrite rule? By default, mod_rewrite would issue a 302, which is a temporary redirect. Search engines do not care for 302s. They want to see a 301, which is a permanent redirect. I learned about the 302/301 issue here. Let’s just hope I don’t mess up years of search rankings.

Markdown on Save Improved

While in the process of writing a spec for an app I’m developing at work to interface between SedonaOffice and eOriginal, I grew an affinity for using Markdown syntax. I use Scrivener to collect my thoughts, and then I can export to MultiMarkdown (a superset of Markdown). The ease of use is a huge effort saver. With that, I went looking for a Markdown plugin for MT, and I wasn’t happy with what I found. What I did find for WP was Markdown on Save Improved. It works well. As I understand, this plugin stores the Markdown and the HTML in separate columns so the Markdown->HTML occurs when the post is saved, and not for each request. Much faster that way.

The Bootstrap

My search for a Twitter Bootstrap theme let me to this one. It installed in a flash, and is using the reactive stylesheets. One quick install and my blog is all good for desktop, mobile, and tablet.

P.S.

Just as an aside, since I went live about 30 minutes ago, I already have spam comments to moderate. Oh boy.

I had a need to import some CAD drawings into my Visio document. The CAD drawings were provided to me as PDF documents. Visio has no native way to insert a PDF into a drawing. SnagIt to the rescue. Besides being an excellent app for making screenshots, it installs itself as a printer. Well, all I did was print my PDF to the SnagIt printer, saved the image as a TIFF, and then inserted the TIFF into my Visio drawing.

The resolution was quite good and I achieved exactly what I wanted. Gotta love it when shits works out!

I’ve been toying around with SQL Server CE replication. For whatever reason, my code was failing with the following exception when I called Synchronize():

Failure to connect to sql server with provided connection information. sql server does not exist, access is denied because the iis user is not a valid user on the sql server, or the password is incorrect.

As it turns out, if you use the follow form of the SqlCeReplication ctor (as observed using Reflector):

the PublisherSecurityMode is set to SecurityType.NTAuthentication. Otherwise, if you use the parameterless ctor, PublisherSecurityMode is left to its default, which is SecurityType.DBAuthentication. This assignment is NOT documented.

I am working on a SQL Server 2005 Reporting Services (SSRS) report that has differing row colors based on a value in each data row. The color value is defined in the database. When I initially created the report, each row had a variable background color but the foreground color was black. The first time I ran the report, my dark blue background didn’t contrast well with my black foreground. I quickly realized that I needed a way to vary the foreground color programmatically based on the background color. After first discussing things over with Nate, here is the expression I came up with for the Color property of the table row:

Let me explain where this all comes from. First off, the color that is stored in the database is used by a VB6 program. VB6 stores colors as BGR and .NET stores colors as RGB (well, technically aRGB). The first step is to break down the value from the database to its constituent parts (red, green, and blue) using bitshift operations I learned from Keith Peters and then apply the contrast formula I found from Colin Lieberman‘s website. I then determine that if the blackground is a dark color, then we use white and for a light background, black. This appears to working like a charm.

Last night we purchase an Apple TV (as well as a Mac Mini, 20″ Cinema Display Monitor, wired keyboard, and wireless mouse). Today I had the unfortunate happenstance of making this little gem of a unit find, and talk to iTunes running on my Mac Pro. I’ll save you the gory details buy my switch is a Linksys SRW224G4P and in the end, I had to disable IGMP Snooping. Otherwise the multicast traffic wasn’t flowing around correctly. This fix came as “well, let’s just see if we turn the helper off”. Well sure as shit, it worked. Yippee for me!

ASP.NET MVC 4 In my ASP.NET MVC 4 partial view, I was having an issue where VaidationSummary and VaidationMessageFor were coming up blank. I scratched my head on this for quite some time. I finally came across this entry at the MVC forums at MSDN. It turns out I wasn’t passing the ViewData from parent… […]

The need for stability Meg’s sites, megbitton.com and soulsimagined.com have uptime requirements that far and away exceed those of mine. Almost the entirety of her business is predicated on a persistent Internet presence. As I’m sure you understand, a few minutes of downtime could lead to a belief that she’s no longer in business. This… […]

What catalog is that file in? That’s what I hear often from my wife Meg; a professional photographer. Meg uses Adobe Photoshop Lightroom for cataloging the pictures she takes for her business as well as the pictures she take of our family. An underlying frustration that I find with Lightroom is the fact that photos… […]

The MultiMarkdown ToC Do you ever feel like you’re never finished? I do, and I’m not happy with the fact that I haven’t been able to make Scrivener trigger the mmd-xslt script following a compile to MultiMarkdown HTML. Fine. As with the original XML epiphany, I knew there had to be code to perform an… […]

To snippet or not to snippet My last post spoke of the need to use a snippet of XHTML in order to include it in a WordPress Page. This rule was short-lived. Why am I recanting my story? I switched to MultiMarkdown 3 and attempted the use its XSLT transformation capabilities; something of which requires… […]

Learning I’ve been working on this app spec for weeks at work. In an effort to improve on what I’d accomplished, I reached out to my friend, and one of the smartest people I know, Peter Becan. I wanted him to teach me how to do it right. Peter’s been doing this sort of thing… […]

I had a need to import some CAD drawings into my Visio document. The CAD drawings were provided to me as PDF documents. Visio has no native way to insert a PDF into a drawing. SnagIt to the rescue. Besides being an excellent app for making screenshots, it installs itself as a printer. Well, all… […]

I’ve been toying around with SQL Server CE replication. For whatever reason, my code was failing with the following exception when I called Synchronize(): Failure to connect to sql server with provided connection information. sql server does not exist, access is denied because the iis user is not a valid user on the sql server,… […]

I am working on a SQL Server 2005 Reporting Services (SSRS) report that has differing row colors based on a value in each data row. The color value is defined in the database. When I initially created the report, each row had a variable background color but the foreground color was black. The first time… […]

Don’t forget when you update the RT_SiteConfig.pm file, you need to restart httpd. I was banging my head against the wall of this one until I had a moment of clarity. The post Request Tracker RT_SiteConfig.pm appeared first on Code No Evil.