<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Brett's Software Development Blog &#187; Software Development</title>
	<atom:link href="http://brett.batie.com/category/software-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://brett.batie.com</link>
	<description>Thoughts of a Software Engineer.</description>
	<lastBuildDate>Fri, 03 Sep 2010 14:38:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Java Live Messenger (MSN) Robot</title>
		<link>http://brett.batie.com/software-development/java-live-messenger-msn-robot/</link>
		<comments>http://brett.batie.com/software-development/java-live-messenger-msn-robot/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 14:34:00 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://brett.batie.com/software-development/java-live-messenger-msn-robot/</guid>
		<description><![CDATA[I recently had a project to setup an Instant Messenger Robot for Windows Live Messenger. A IM robot can have many purposes such as:

Keeping track of when contacts are online/offline and when they were last seen. 
Broadcasting a message to all contacts. 
Automatically answering common questions. 
Notifying contacts about new events. A newer site http://notify.me [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had a project to setup an Instant Messenger Robot for Windows Live Messenger. A IM robot can have many purposes such as:</p>
<ul>
<li>Keeping track of when contacts are online/offline and when they were last seen. </li>
<li>Broadcasting a message to all contacts. </li>
<li>Automatically answering common questions. </li>
<li>Notifying contacts about new events. A newer site http://notify.me has a nice IM Robot that notifies you when a RSS feed is updated. This works well in conjuction with sites like craigslist. </li>
<li>Keeping track of code snippets </li>
<li>Checking the weather </li>
<li>Checking server status </li>
</ul>
<p>An IM robot can be setup to automate just about any task. </p>
<h4>What IM Library to Use</h4>
<p>Setting up a IM robot can be a bit of work especially if starting from scratch. There are a lot of libraries out there that can be used to help simplify the process. The trouble is a lot of libraries are not kept up to date and fail to work as IM protocols change. </p>
<p>I did some digging and found a library that would provide a good foundation to build a IM Robot that can do just about anything. I saw implementations in PHP, C, Java, Perl and Python. After some testing I concluded the <a href="http://sourceforge.net/apps/trac/java-jml">Java MSN Library</a> would be a very good fit.</p>
<h4>How To Use It</h4>
<p>Using this library with java is pretty straight forward. First, the library must be added to the classpath. The step to take to complete this will depend on how your developing your java code. The most basic method to add a library to your classpath is to do this at run time with a command such as:</p>
<pre class="brush: java;">java -classpath MyLibrary.jar MyPackage.MyClass</pre>
<p>A better approach would be to setup the classpath in a <a title="Manifest File" href="http://download.oracle.com/javase/tutorial/deployment/jar/manifestindex.html">manifest file</a>. The manifest file is then placed inside the jar file and tells the executable jar where to look for the libraries. This manifest file should look something like the following (note the class-path on line 5):</p>
<pre class="brush: java;">Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 14.3-b01 (Sun Microsystems Inc.)
Main-Class: imstatus.Main
Class-Path: lib/jml-1.0b4-full.jar lib/httpcore-4.0.1.jar lib/mysql-co
 nnector-java-5.1.6-bin.jar
X-COMMENT: Main-Class will be added automatically by build</pre>
<p>This is setup so that the 3 required libraries are in the lib folder. These 3 libraries are needed for setting up an IM robot and can be downloaded from the following locations:</p>
<ul>
<li><a href="http://sourceforge.net/projects/java-jml/files/java-jml/jml-1.0b4/jml-1.0b4-full.jar/download">jml-1.0b4-full.jar</a> </li>
<li><a href="http://apache.imghat.com//httpcomponents/httpclient/binary/httpcomponents-client-4.0.1-bin.zip">httpcore-4.0.1.jar</a> </li>
<li><a href="http://dev.mysql.com/downloads/connector/j/">mysql-connector-java-5.1.6-bin.jar</a></li>
</ul>
<p>Now that the libraries are setup we can begin to use them.</p>
<h4>Developing the IM Robot Code</h4>
<p>There are a few examples of using the Java MSN Library on the <a href="http://sourceforge.net/apps/trac/java-jml">main page</a>. However, they are a tad confusing as it creates a new BasicMessenger class. This is confusing as the library already has a BasicMessenger class which is abstract. The library also has a SimpleMessenger class which is a subclass of BasicMessenger. This class appears to be the correct implementation that we would want to use to create a new IM Robot. However, the original authors made the constructor protected so that we cannot instantiate the class outside of the original package. Since we want a simple way to create an IM Robot I have modified the original source code to have a public constructor for the SimpleMessenger class. This new package can be downloaded from <a href="http://softwareprojects.com/files/jml-1.0b4-full.jar">our server</a>.</p>
<p>With this new package we can very easily create a new IM Robot with the following two lines of code (make sure to replace yourLogin and yourPassword):</p>
<pre class="brush: java;">SimpleMessenger messenger = new SimpleMessenger(Email.parseStr(&quot;yourLogin@msn.com&quot;), &quot;yourPassword&quot;);
messenger.login();</pre>
<p>With that code in our main funtion we can run it and test that the Robot automatically logs into Windows Live Messenger.</p>
<p>Of course, that code just logs the Robot into Windows Live Messenger. The next step is to setup the robot to do something interesting. This is one feature that is very nice about the Java MSN Library as it has listeners for many different events. For example we can detect when the robot has finished logging in with the following:</p>
<pre class="brush: java;">messenger.addListener(new MsnAdapter() {
	// Setup the login completed event

	@Override
	public void loginCompleted(MsnMessenger messenger) {
		MsnOwner owner = messenger.getOwner();
		owner.setInitStatus(MsnUserStatus.ONLINE);
		owner.setStatus(MsnUserStatus.ONLINE);

		// Setup the contact list event
		messenger.addContactListListener(new ContactListAdapter());
	}
});</pre>
<p>Then we can take this a step further and detect when a status changes for one of the robots contacts with something like the following:</p>
<pre class="brush: java;">messenger.addListener(new MsnAdapter() {
	// Setup the login completed event

	@Override
	public void loginCompleted(MsnMessenger messenger) {
		MsnOwner owner = messenger.getOwner();
		owner.setInitStatus(MsnUserStatus.ONLINE);
		owner.setStatus(MsnUserStatus.ONLINE);

		// Setup the contact list event
		messenger.addContactListListener(new ContactListAdapter());
	}
});</pre>
<p>The above code will detect when the robot has finished logging in and then setup a new listener to detect when a contacts status has changed. The new listener invokes the ContactListAdapter class when a status has changed. This contactListAdapter class is setup as followes:</p>
<pre class="brush: java;">class ContactListAdapter extends MsnContactListAdapter {
	@Override
	public void contactStatusChanged(MsnMessenger messenger, MsnContact contact) {
		System.out.println(contact.getEmail()+&quot; is currently &quot;+contact.getStatus());
		// Can add code here to store the status in a database
	}
}</pre>
<p>We can still take this a step further and setup the robot to handle automatically adding contacts when a contact requests it. This logic can be added to the ContactListAdapter class with something like the following:</p>
<pre class="brush: java;">class ContactListAdapter extends MsnContactListAdapter {
	@Override
	public void contactListSyncCompleted(MsnMessenger messenger) {
			MsnContact[] contacts = messenger.getContactList().getContactsInList(MsnList.AL);
			for (int i = 0; i &lt; contacts.length; i++) {
				contactStatusChanged(messenger,contacts[i]);
			}
	}

	@Override
	public void contactAddedMe(MsnMessenger messenger, MsnContact contact) {
		messenger.addFriend(contact.getEmail(), contact.getDisplayName());
	}

	@Override
	public void contactAddedMe(MsnMessenger messenger, MsnContactPending[] pending){
		for(int i=0; i&lt;pending.length; i++){
			messenger.addFriend(pending[i].getEmail(), pending[i].getDisplayName());
		}
	}

	@Override
	public void contactStatusChanged(MsnMessenger messenger, MsnContact contact) {
		System.out.println(contact.getEmail()+&quot; is currently &quot;+contact.getStatus());
		// Can add code here to store the status in a database
	}
}</pre>
<p>There you have it! Put all of the above code together and you will have a robot that knows how to automatically add contacts and keep track of when a contact&#8217;s status changes.</p>
<p>This article was <a href="http://www.softwareprojects.com/resources/programming/t-msn-messenger-integration-java-robot-script-1994.html">cross-posted from Software Projects</a></p>
]]></content:encoded>
			<wfw:commentRss>http://brett.batie.com/software-development/java-live-messenger-msn-robot/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UltraMon Breaks After Remote Desktop Connection (RDP)</title>
		<link>http://brett.batie.com/software-development/ultramon-breaks-after-remote-desktop-connection-rdp/</link>
		<comments>http://brett.batie.com/software-development/ultramon-breaks-after-remote-desktop-connection-rdp/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 19:42:00 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://brett.batie.com/software-development/ultramon-breaks-after-remote-desktop-connection-rdp/</guid>
		<description><![CDATA[I use the application UltraMon to help manage my multiple monitor setup. Overall this application is awesome as it makes moving applications between monitors a breeze and supports a separate task bar on each monitor, among other things.
However, I have had this issue for a while where UltraMon will not move applications between monitors after [...]]]></description>
			<content:encoded><![CDATA[<p>I use the application <a href="http://www.realtimesoft.com/ultramon/">UltraMon</a> to help manage my multiple monitor setup. Overall this application is awesome as it makes moving applications between monitors a breeze and supports a separate task bar on each monitor, among other things.</p>
<p>However, I have had this issue for a while where UltraMon will not move applications between monitors after a Remote Desktop Connection has been established, instead UltraMon acts as if there is only one monitor.</p>
<p>In the past the only solution I had for this issue was to restart my computer. This is not an ideal solution for me as I&#8217;m often multi-tasking and running many applications at the same time. </p>
<p>In order to reboot I have to close down each application, save my work, reboot, and then start up every application again after the reboot. This is not a major amount of time but it does add up if I have to do it on a regular basis. Plus, I am one who likes to optimize everything to achieve as much efficiency as humanly possible in a given day.</p>
<p>So, I spent a few minutes and fiddled with UltraMon and found a way to fix this RDP flaw without requiring a reboot. The steps are as follows:</p>
<ol>
<li>Close UltraMon<a href="http://brett.batie.com/wp-content/uploads/UltramonBreaksAfterRemoteDesktopConnecti_ACA5/sshot201004055.png"  rel="lightbox" rel="lightbox[roadtrip]"><img style="border-bottom: 0px; border-left: 0px; display: inline; margin-left: 0px; border-top: 0px; margin-right: 0px; border-right: 0px" title="sshot-2010-04-05-[5]" border="0" alt="sshot-2010-04-05-[5]" align="right" src="http://brett.batie.com/wp-content/uploads/UltramonBreaksAfterRemoteDesktopConnecti_ACA5/sshot201004055_thumb.png" width="121" height="130" /></a> </li>
<li>Right click on your desktop and select <strong>Screen Resolution</strong></li>
<li>Disable the monitor that the application cannot be moved to and click apply (screenshot on right). Repeat for all monitors that are suffering from this issue.</li>
<li>Start UltraMon</li>
<li>Enable all monitors that were disabled in step 3.</li>
</ol>
<p>After completing the above steps UltraMon will be as good as new. </p>
<p>I have only tested this on Windows 7 so let me know if this works on other Windows versions as well. </p>
<p>Anyone up for automating the above steps? If I get a break I might try and tackle it.</p>
]]></content:encoded>
			<wfw:commentRss>http://brett.batie.com/software-development/ultramon-breaks-after-remote-desktop-connection-rdp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Format Credit Card with X&#8217;s and Dashes using PHP (credit card masking)</title>
		<link>http://brett.batie.com/software-development/post-about-format-credit-card-with-xs-and-dashes-using-php/</link>
		<comments>http://brett.batie.com/software-development/post-about-format-credit-card-with-xs-and-dashes-using-php/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 19:16:57 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[credit card]]></category>
		<category><![CDATA[masking]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://brett.batie.com/private/spi/to-do/post-about-format-credit-card-with-xs-and-dashes-using-php/</guid>
		<description><![CDATA[I recently had a project where I needed to accomplish the following two tasks:

Replace all but the last four digits of a credit card with X&#8217;s 
Format the credit card with dashes in the appropriate places 

There are many different approaches that can be taken to accomplish the above two tasks. The simplest approach would [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had a project where I needed to accomplish the following two tasks:</p>
<ol>
<li>Replace all but the last four digits of a credit card with X&#8217;s </li>
<li>Format the credit card with dashes in the appropriate places </li>
</ol>
<p>There are many different approaches that can be taken to accomplish the above two tasks. The simplest approach would be to do something like the following:</p>
<pre class="brush: php;">&lt;?php
echo 'XXXX-XXXX-XXXX-'.substr($cc,-4);
?&gt;</pre>
<p>I have often seen credit cards masked with the above approach. For the most case this solution will work fairly well. However, I am not a huge fan of this approach as it displays the credit card at a fixed length of 16 digits. This can be a bit confusing since credit cards can very in length from 13 to 16 digits.</p>
<p>To better address this issue I put together two functions. One function is to apply a mask to a credit card and the other is to format the credit card with dashes. These functions will keep the original length of each credit card.</p>
<pre class="brush: php;">&lt;?php

/**
 * Replaces all but the last for digits with x's in the given credit card number
 * @param int|string $cc The credit card number to mask
 * @return string The masked credit card number
 */
function MaskCreditCard($cc){
	// Get the cc Length
	$cc_length = strlen($cc);

	// Replace all characters of credit card except the last four and dashes
	for($i=0; $i&lt;$cc_length-4; $i++){
		if($cc[$i] == '-'){continue;}
		$cc[$i] = 'X';
	}

	// Return the masked Credit Card #
	return $cc;
}

/**
 * Add dashes to a credit card number.
 * @param int|string $cc The credit card number to format with dashes.
 * @return string The credit card with dashes.
 */
function FormatCreditCard($cc)
{
	// Clean out extra data that might be in the cc
	$cc = str_replace(array('-',' '),'',$cc);

	// Get the CC Length
	$cc_length = strlen($cc);

	// Initialize the new credit card to contian the last four digits
	$newCreditCard = substr($cc,-4);

	// Walk backwards through the credit card number and add a dash after every fourth digit
	for($i=$cc_length-5;$i&gt;=0;$i--){
		// If on the fourth character add a dash
		if((($i+1)-$cc_length)%4 == 0){
			$newCreditCard = '-'.$newCreditCard;
		}
		// Add the current character to the new credit card
		$newCreditCard = $cc[$i].$newCreditCard;
	}

	// Return the formatted credit card number
	return $newCreditCard;
}

?&gt;</pre>
<p>Below are a couple examples of how to use these functions and the results they create.</p>
<pre class="brush: php;">&lt;?php
echo maskCreditCard('5362267121053405').'&lt;br&gt;'; // Prints XXXXXXXXXXXX3405
echo formatCreditCard('5362267121053405').'&lt;br&gt;'; // Prints 5362-2671-2105-3405
echo formatCreditCard(maskCreditCard('5362267121053405')).'&lt;br&gt;'; // Prints XXXX-XXXX-XXXX-3405
?&gt;</pre>
<pre class="brush: php;">&lt;?php
$creditCard[] = '5362267121053405'; // Mastercard
$creditCard[] = '4556189015881361'; // Visa 16
$creditCard[] = '4716904617062'; // Visa 13
$creditCard[] = '372348371455844'; // American Express
$creditCard[] = '6011757892594291'; // Discover
$creditCard[] = '30329445722959'; // Diners Club
$creditCard[] = '214927124363421'; // enRoute
$creditCard[] = '180012855304868'; // JCB 15
$creditCard[] = '3528066275370961'; // JCB 16
$creditCard[] = '8699775919'; // Voyager

for($i=0;$i&lt;count($creditCard);$i++)
{
	echo FormatCreditCard(MaskCreditCard(($creditCard[$i]))).&quot;\n&quot;;
}
?&gt;</pre>
<p>Output:</p>
<pre class="brush: shell; gutter: false">XXXX-XXXX-XXXX-3405
XXXX-XXXX-XXXX-1361
X-XXXX-XXXX-7062
XXX-XXXX-XXXX-5844
XXXX-XXXX-XXXX-4291
XX-XXXX-XXXX-2959
XXX-XXXX-XXXX-3421
XXX-XXXX-XXXX-4868
XXXX-XXXX-XXXX-0961
XX-XXXX-5919</pre>
<p>Let me know if you find these functions useful or have any suggestions on how to tweak them.</p>
]]></content:encoded>
			<wfw:commentRss>http://brett.batie.com/software-development/post-about-format-credit-card-with-xs-and-dashes-using-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Update .htaccess with Dynamic DNS IP Address to Prevent Password Protection</title>
		<link>http://brett.batie.com/software-development/update-htaccess-with-dynamic-dns-ip-address-to-prevent-password-protection/</link>
		<comments>http://brett.batie.com/software-development/update-htaccess-with-dynamic-dns-ip-address-to-prevent-password-protection/#comments</comments>
		<pubDate>Tue, 09 Mar 2010 18:37:00 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://brett.batie.com/software-development/update-htaccess-with-dynamic-dns-ip-address-to-prevent-password-protection/</guid>
		<description><![CDATA[I was working on a password protected site that needed to allow one specific user access without requiring a login/password to access it. The site was already using .htaccess to password protect the entire site so the quickest solution was to use the following type of setup in the htaccess file:
Order deny,allow
Deny from all
AuthGroupFile /dev/null
AuthName [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on a password protected site that needed to allow one specific user access without requiring a login/password to access it. The site was already using .htaccess to password protect the entire site so the quickest solution was to use the following type of setup in the htaccess file:</p>
<pre class="brush: shell; highlight: 8">Order deny,allow
Deny from all
AuthGroupFile /dev/null
AuthName "A Blog"
AuthType Basic
AuthUserFile /home/admin/domains/domain.com/.htpasswd/public_html/.htpasswd
require valid-user
Allow from person.getmyip.com
Satisfy Any</pre>
<p>The main addition that I added to the password protection is line 8 &#8220;Allow from&#8221;. This line allows a specific IP address or host to have access without requiring password protection.</p>
<p>However, the host that needed to be used was a <a href="dyndns.com/">Dynamic DNS</a> hostname. This creates a problem as Apache takes the following steps when the user requests access.</p>
<ol>
<li>Grab IP from user requesting access</li>
<li>Do a reverse DNS lookup</li>
<li>Compare the results to the host in the Allow from line (person.getmyip.com)</li>
</ol>
<p>In this case when a reverse DNS lookup is completed on the users IP address it will not find the <a href="dyndns.com/">Dynamic DNS</a> hostname. Instead, it will find the hostname that is associated with your ISP which might look something like this 8.sub-79-231-223.myvzw.com.</p>
<p>There are a number of ways to get around this issue. In my case I wanted to use a small script to dynamically populate the .htaccess file with the correct IP address.</p>
<p>Below is the following PHP script that handles updating .htaccess with the latest IP address. The main requirement is that there is a comment &#8220;# Allow from person.getmyip.com&#8221; somewhere in the .htaccess file. This line tells the script where to insert the IP address on the very next line.</p>
<pre class="brush: php;">&lt;?php
// Rewrites the entire htaccess file. When a line starts with '# Allow from brett.getmyip.com' the
// very next line will be replaced with the actual ip associated with brett.getmyip.com
$htaccessFile = "/home/admin/domains/batie.com/public_html/.htaccess";
$handle = fopen($htaccessFile, "r");
if ($handle) {
	$previous_line = $content = '';
	while (!feof($handle)) {
		$current_line = fgets($handle);

		if(stripos($previous_line,'# Allow from person.getmyip.com') !== FALSE)
		{
			$output = shell_exec('host person.getmyip.com');
			if(preg_match('#([0-9]{1,3}\.){3}[0-9]{1,3}#',$output,$matches))
			{
				$content .= 'Allow from '.$matches[0]."\n";
			}
		}else{
			$content .= $current_line;
		}
		$previous_line = $current_line;
	}
	fclose($handle);

	$tempFile = tempnam('/tmp','allow_');
	$fp = fopen($tempFile, 'w');
	fwrite($fp, $content);
	fclose($fp);
	rename($tempFile,$htaccessFile);
	chown($htaccessFile,'admin');
	chmod($htaccessFile,'0644');
}
?&gt;</pre>
<p>I quickly wrote this script and realize that there is room for improvement. However, this meet the need and solved the problem.</p>
<p>After the script was completed adding a simple line to the crontab (crontab -e) file got it running on a regular basis to automatically update the file with the current IP.</p>
<pre class="brush: shell;"># Script to update ip access for dynamic dns host - it allows person.getmyip.com
*/5 * * * * /usr/local/bin/php /home/admin/scripts/allow_person.php &gt;/dev/null 2&gt;&amp;1</pre>
]]></content:encoded>
			<wfw:commentRss>http://brett.batie.com/software-development/update-htaccess-with-dynamic-dns-ip-address-to-prevent-password-protection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Paste Code &#8211; Live Writer Plugin To Paste HTML/Code</title>
		<link>http://brett.batie.com/software-development/live-writer-plugin-to-paste-html-code/</link>
		<comments>http://brett.batie.com/software-development/live-writer-plugin-to-paste-html-code/#comments</comments>
		<pubDate>Sat, 06 Mar 2010 20:34:11 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Paste Code]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Windows Live Writer]]></category>

		<guid isPermaLink="false">http://brett.batie.com/private/cwd/live-writer-plugin-to-paste-htmlcode/</guid>
		<description><![CDATA[I recently started using Windows Live Writer and I believe it is currently the best application out there for quickly posting to a blog. However, I found one issue where I could not easily paste HTML and other code and decided to develop a plugin to address it.
If your in a hurry here is the [...]]]></description>
			<content:encoded><![CDATA[<p>I recently started using Windows Live Writer and I believe it is currently the best application out there for quickly posting to a blog. However, I found one issue where I could not easily paste HTML and other code and decided to develop a plugin to address it.</p>
<p>If your in a hurry here is the download link:</p>
<a href=http://brett.batie.com/download/InstallPasteCode.msi><img src=http://brett.batie.com/wp-content/plugins/download-monitor/img/downloads-icon.gif style="vertical-align: middle;">DOWNLOAD: Paste Code For Windows Live Writer</a>
<p><strong>The Issue</strong></p>
<p>Below is an example of some code I would like to paste into Live Writer.</p>
<pre class="brush: html;">&lt;html&gt;
&lt;head&gt;
	&lt;title&gt;Hello World&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
	Hello World
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>When I try to paste the above code in the &quot;Edit&quot; window. It appears correctly on the screen but in reality Live Writer added content to my code. When I view the source I receive the following:</p>
<pre class="brush: html;">&amp;lt;html&amp;gt;
  &lt;br /&gt;&amp;lt;head&amp;gt;

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; &amp;lt;title&amp;gt;Hello World&amp;lt;/title&amp;gt;

  &lt;br /&gt;&amp;lt;/head&amp;gt;

  &lt;br /&gt;&amp;lt;body&amp;gt;

  &lt;br /&gt;&amp;#160;&amp;#160;&amp;#160; Hello World

  &lt;br /&gt;&amp;lt;/body&amp;gt;

  &lt;br /&gt;&amp;lt;/html&amp;gt;</pre>
<p>This is very close to how I desire to have the code formatted. However, the major problem is it inserted a bunch of &lt;br /&gt; characters. It does make sense that it inserted these &lt;br /&gt;&#8217;s since in most cases we want line returns to have breaks but this is not the case when pasting source code. </p>
<p>Next, if I paste the code in the &quot;Source&quot; window the problem is the code is taken as actual source. This means that the code will not be seen on the screen but instead will be interpreted by the browser. If I then swap back and forth between the &quot;Edit&quot; and &quot;Source&quot; windows my code gets reformatted to be the following:</p>
<pre class="brush: html;">Hello World</pre>
<p>Which is obviously not what I wanted.</p>
<p><strong>Solution: A Plugin</strong></p>
<p>To address the issues stated above I put together a plugin that will allow pasting code in either the &quot;Edit&quot; or &quot;Source&quot; windows. It will replace special characters so that the code will be viewable and will not insert extra HTML (like &lt;br /&gt;&#8217;s).</p>
<p>Below is a screenshot of the plugin in action:</p>
<p><a href="http://brett.batie.com/wp-content/uploads/LiveWriterPluginToPasteHTML_AF6F/sshot201003063.png"  rel="lightbox" rel="lightbox[roadtrip]"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="sshot-2010-03-06-[3]" border="0" alt="sshot-2010-03-06-[3]" src="http://brett.batie.com/wp-content/uploads/LiveWriterPluginToPasteHTML_AF6F/sshot201003063_thumb.png" width="296" height="320" /></a> </p>
<p>This plugin will automatically take the code that exists on the clipboard and display it in the &quot;Code Snippet&quot; section and give the ability to edit the code before pasting it.</p>
<p>It also has the &quot;Before Code Snippet&quot; and &quot;After Code Snippet&quot; text areas. These two text areas allow defining code to wrap around your code snippet. By default the two box&#8217;s will have &lt;pre&gt; and &lt;/pre&gt;. Using either a &lt;pre&gt; or a &lt;textarea&gt; is required in order to have the formatting display correctly. If the content of &quot;Before Code Snippet&quot; and &quot;After Code Snippet&quot; is changed it will be remembered the next time the plugin is used.</p>
<p>Once insert is clicked in the plugin the code will be added to your post in Windows Live Writer and will be formatted correctly.</p>
<a href=http://brett.batie.com/download/InstallPasteCode.msi><img src=http://brett.batie.com/wp-content/plugins/download-monitor/img/downloads-icon.gif style="vertical-align: middle;">DOWNLOAD: Paste Code For Windows Live Writer</a>
<p><strong>Icing On Top</strong></p>
<p>With this plugin in place we can easily paste code and not worry about the formatting. However, it is very beneficial to have the source code displayed on your blog with syntax highlighting. I do know that there are a few plugins for Windows Live Writer that will apply syntax highlighting to code. However, I do not love this for the following reasons:</p>
<ol>
<li>Will not work when writing an article from blog&#8217;s admin page. </li>
<li>Will not easily allow changing the Syntax Highlighting to a different algorithm. There are a ton of different Syntax Highlighting plugins for blogs and every once in a while I like to upgrade to the the latest and greatest. </li>
<li>Will not work if I decide I want to move away from Windows Live Writer (that will never happen, right?). </li>
</ol>
<p>For my blog I am using the <a href="http://alexgorbatchev.com/wiki/SyntaxHighlighter">syntax highlighter developed by Alex Gorbachev</a>. There is also a nice plugin that quickly installs this <a href="http://blog.burlock.org/wordpress/88-easy-google-syntax-highlighter-for-wordpress">syntax highlighting in a wordpress blog</a>. With the paste code plugin for Windows Live Writer in combination with syntax highlighting I can quickly paste code and achieve the following results:</p>
<p><a href="http://brett.batie.com/wp-content/uploads/LiveWriterPluginToPasteHTML_AF6F/sshot201003064.png"  rel="lightbox" rel="lightbox[roadtrip]"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="sshot-2010-03-06-[4]" border="0" alt="sshot-2010-03-06-[4]" src="http://brett.batie.com/wp-content/uploads/LiveWriterPluginToPasteHTML_AF6F/sshot201003064_thumb.png" width="446" height="130" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://brett.batie.com/software-development/live-writer-plugin-to-paste-html-code/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Modify a Program&#8217;s Icon</title>
		<link>http://brett.batie.com/software-development/how-to-modify-a-programs-icon/</link>
		<comments>http://brett.batie.com/software-development/how-to-modify-a-programs-icon/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 01:29:18 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://brett.batie.com/?p=179</guid>
		<description><![CDATA[It is possible to change just about any icon that comes with an application.  There are a few different applications that will help make this job easy and my favorite is resource hacker.  The reason that I can think of that someone would want to change a programs icon are the following:

Two programs have icons [...]]]></description>
			<content:encoded><![CDATA[<p>It is possible to change just about any icon that comes with an application.  There are a few different applications that will help make this job easy and my favorite is resource hacker.  The reason that I can think of that someone would want to change a programs icon are the following:</p>
<ul>
<li>Two programs have icons that look too similar</li>
<li>The program comes with an icon that does not give a good representation of what the program does</li>
<li>To have the coolest icons on the block</li>
</ul>
<div id="attachment_180" class="wp-caption alignright" style="width: 160px"><a href="http://brett.batie.com/wp-content/uploads/sshot-2009-03-09-1.png"  rel="lightbox[roadtrip]"><img class="size-thumbnail wp-image-180" title="Resource Hacker" src="http://brett.batie.com/wp-content/uploads/sshot-2009-03-09-1-150x150.png" alt="Resource Hacker Replace Icon" width="150" height="150" /></a><p class="wp-caption-text">Resource Hacker <br /> Replace Icon</p></div>
<p>The steps to replace an icon for a program are fairly simple. Just follow the below steps to modify the icons for any of your applications.   </p>
<ol>
<li>Download <a href="http://delphi.icm.edu.pl/ftp/tools/ResHack.zip">Resource Hacker</a></li>
<li><strong>Unzip</strong> the file and <strong>run</strong> ResHacker.exe</li>
<li><strong>Open the program</strong> that contains an icon you would like to change (like C:\Program Files\Brett Batie\Excel on Multiple Monitors\runExcel.exe)</li>
<li>Click <strong>Actions→Replace Icon</strong> in the Menu Bar</li>
<li>Click the &#8220;<strong>Open file with new icon&#8230;</strong>&#8221; button</li>
<li>Select the new icon (like C:\Program Files\Microsoft Office\Office12\EXCEL.exe)</li>
<li>Click the &#8220;<strong>Replace</strong>&#8221; button</li>
<li>Click<strong> File→Save</strong> in the Menu Bar</li>
<li><strong>Close</strong> Resource Hacker All Done</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://brett.batie.com/software-development/how-to-modify-a-programs-icon/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Verify a WordPress Blog with Google</title>
		<link>http://brett.batie.com/software-development/verify-wordpress-with-google/</link>
		<comments>http://brett.batie.com/software-development/verify-wordpress-with-google/#comments</comments>
		<pubDate>Tue, 22 Jul 2008 03:17:22 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://brett.batie.com/?p=68</guid>
		<description><![CDATA[In order to verify your site with google you need to go to Google&#8217;s Webmaster Tools Dashboard and add your website and then click verify. After clicking verify it will ask you to put a file on your website with a name similar to google54fbcc37db740a4d.html. In most cases this is all that needs to be done and then google [...]]]></description>
			<content:encoded><![CDATA[<p>In order to verify your site with google you need to go to <a href="https://www.google.com/webmasters/tools/dashboard" target="_blank">Google&#8217;s Webmaster Tools Dashboard</a> and add your website and then click verify. After clicking verify it will ask you to put a file on your website with a name similar to google54fbcc37db740a4d.html. In most cases this is all that needs to be done and then google can verify that you are the owner.</p>
<p>If you are using permalinks with WordPress it is not so easy to get Google to verify your site. There are two items that are causing validation to not work with WordPress. First, Google is trying to access more than just google54fbcc37db740a4d.html it is also trying to request a page that does not exist. When I tested it, Google was also asking for noexist_54fbcc37db740a4d.html. You might notice that Google just replaced the word &#8220;google&#8221; with &#8220;noexist_&#8221;. Second, WordPress is taking a request for any page (including ones that do not exist) and trying to find an appropriate page and is therefore not returning a 404 error. These two problems cause Google to respond with the following error when you try to validate your site.</p>
<blockquote><p>We&#8217;ve detected that your 404 (file not found) error page returns a status of 200 (Success) in the header.</p></blockquote>
<p> The code that causes WordPress to not return a 404 for an invalid page is the following which is in an .htaccess file.</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span>
<span style="color: #00007f;">RewriteBase</span> /
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} !-f
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} !-d
<span style="color: #00007f;">RewriteRule</span> . /index.php [L]</pre></div></div>

<p>After creating your file google54fbcc37db740a4d.html and adding it to your server you just have to modify the above .htaccess file to have it not redirect the request for noexist_54fbcc37db740a4d.html to index.php. You also need to specify a specific page or message to display when a 404 error occurs. You can do that by replacing the above code with the following code.</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">RewriteEngine</span> <span style="color: #0000ff;">On</span>
<span style="color: #00007f;">ErrorDocument</span> <span style="color: #ff0000;">404</span> <span style="color: #7f007f;">&quot;This page does not exist&quot;</span>
<span style="color: #00007f;">RewriteBase</span> /
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} !-f
<span style="color: #00007f;">RewriteCond</span> %{REQUEST_FILENAME} !-d
<span style="color: #00007f;">RewriteCond</span> %{request_uri} !^/noexist_54fbcc37db740a4d.html$ [nc]
<span style="color: #00007f;">RewriteRule</span> . /index.php [L]</pre></div></div>

<p>Make sure you replace the 54fbcc37db740a4d in the above code with the same characters of the file that google tells you to add to your website.</p>
]]></content:encoded>
			<wfw:commentRss>http://brett.batie.com/software-development/verify-wordpress-with-google/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Password Protect All but One File (htaccess)</title>
		<link>http://brett.batie.com/software-development/password-protect-all-but-one-file-htaccess/</link>
		<comments>http://brett.batie.com/software-development/password-protect-all-but-one-file-htaccess/#comments</comments>
		<pubDate>Sun, 20 Jul 2008 17:38:27 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://brett.batie.com/?p=56</guid>
		<description><![CDATA[Once in a while need to allow someone access to one file but no other files in the same directory. I often solve this problem by moving the one file to a sub directory and then adding the following to an htaccess file in that same sub directory.

allow from all
satisfy any

This normally works well but is not [...]]]></description>
			<content:encoded><![CDATA[<p>Once in a while need to allow someone access to one file but no other files in the same directory. I often solve this problem by moving the one file to a sub directory and then adding the following to an htaccess file in that same sub directory.</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">allow</span> <span style="color: #00007f;">from</span> <span style="color: #00007f;">all</span>
<span style="color: #00007f;">satisfy</span> any</pre></div></div>

<p>This normally works well but is not a perfect solution since it is not always appropriate to move the file to a different directory. So, I took the time and figured out how to password protect everything but one file. Below is the basic password protection that I had in the htaccess file that blocked everything in the directory (and sub-directories).</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;"><span style="color: #00007f;">AuthGroupFile</span> /dev/null
<span style="color: #00007f;">AuthName</span> <span style="color: #7f007f;">&quot;A Blog&quot;</span>
<span style="color: #00007f;">AuthType</span> Basic
<span style="color: #00007f;">AuthUserFile</span> /path/to/.htpasswd
<span style="color: #00007f;">require</span> valid-<span style="color: #00007f;">user</span></pre></div></div>

<p>Now in order to exclude a file I just had to add the following below the above six lines of code.</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">Files</span> <span style="color: #7f007f;">&quot;page.html&quot;</span>&gt;
  <span style="color: #00007f;">Allow</span> <span style="color: #00007f;">from</span> <span style="color: #00007f;">all</span>
  <span style="color: #00007f;">Satisfy</span> any
&lt;/<span style="color: #000000; font-weight:bold;">Files</span>&gt;</pre></div></div>

<p>Of course this can be taken one step further if you wanted to exclude multiple files from password protection.</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">FilesMatch</span> <span style="color: #7f007f;">&quot;(page1<span style="color: #000099; font-weight: bold;">\.</span>html)|(page2<span style="color: #000099; font-weight: bold;">\.</span>html)&quot;</span>&gt;
  <span style="color: #00007f;">Allow</span> <span style="color: #00007f;">from</span> <span style="color: #00007f;">all</span>
  <span style="color: #00007f;">Satisfy</span> any
&lt;/<span style="color: #000000; font-weight:bold;">FilesMatch</span>&gt;</pre></div></div>

<p>FilesMatch can take a regular expression so you don&#8217;t necessarily have to list out each file. The below code will also accomplish the same thing (as above).</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">FilesMatch</span> <span style="color: #7f007f;">&quot;page[1-2]<span style="color: #000099; font-weight: bold;">\.</span>html&quot;</span>&gt;
  <span style="color: #00007f;">Allow</span> <span style="color: #00007f;">from</span> <span style="color: #00007f;">all</span>
  <span style="color: #00007f;">Satisfy</span> any
&lt;/<span style="color: #000000; font-weight:bold;">FilesMatch</span>&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://brett.batie.com/software-development/password-protect-all-but-one-file-htaccess/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Count Lines of Code in C#</title>
		<link>http://brett.batie.com/software-development/count-lines-of-code-in-c/</link>
		<comments>http://brett.batie.com/software-development/count-lines-of-code-in-c/#comments</comments>
		<pubDate>Wed, 05 Dec 2007 02:08:03 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://brett.batie.com/software-development/count-lines-of-code-in-c/</guid>
		<description><![CDATA[When I am programming I often wonder how much code I have actually typed. Sometimes when I get in the zone, have a well thought out design and have auto-completion helping, I can generate code pretty quick. Although there are quite a few programs out there that will count the lines of code some are a [...]]]></description>
			<content:encoded><![CDATA[<p>When I am programming I often wonder how much code I have actually typed. Sometimes when I get in the zone, have a well thought out design and have auto-completion helping, I can generate code pretty quick. Although there are quite a few programs out there that will count the lines of code some are a bit more intelligent than others.</p>
<p>At the most basic level a simple <a href="http://brett.batie.com/uncategorized/count-number-of-lines-in-a-file-using-dos/" title="Lines Of Code - Dos Command">command in DOS </a>can count the lines of code in a file or directory. But, I often want to a little more than just the the number of lines in each file. I want to know things like the lines of code vs empty lines and the number of lines that contain comments. Fortunately, there is a <a target="_blank" href="http://www.codeproject.com/csharp/LineCounterAddin.asp" title="Count Lines of Code - Visual Studio Plugin">plug-in for Visual Studio</a> that will do just that. Since, I am normally using Visual Studio to write any program in C# this is a very logical place to have this tool.</p>
<p><a rel="lightbox" href="http://brett.batie.com/wp-content/uploads/c-23-count-lines-of-code.png"  rel="lightbox[roadtrip]"><img border="0" width="440" src="http://brett.batie.com/wp-content/uploads/c-23-count-lines-of-code.png" alt="C# count lines of code" height="315" /></a></p>
<p>My next mission will be to find a good line counter for Java. Anyone know of any?</p>
]]></content:encoded>
			<wfw:commentRss>http://brett.batie.com/software-development/count-lines-of-code-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extra Update Center Module &#8211; Netbeans 6 beta 2</title>
		<link>http://brett.batie.com/software-development/extra-update-center-module-netbeans-6-beta-2/</link>
		<comments>http://brett.batie.com/software-development/extra-update-center-module-netbeans-6-beta-2/#comments</comments>
		<pubDate>Fri, 26 Oct 2007 00:43:11 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://brett.batie.com/?p=23</guid>
		<description><![CDATA[In the nightly build of netbeans there is a module that can be installed called &#8220;Extra Update Center Module&#8221;. This can be made available in Netbeans 6 beta 2 by going to Tools&#8211;&#62;Plugins&#8211;&#62;Settings and clicking the &#8220;add&#8221; button. Then use the following url:

http://deadlock.netbeans.org/hudson/job/javadoc-nbms/lastSuccessfulBuild/artifact/nbbuild/nbms/updates.xml.gz

Click &#8220;ok&#8221; and you should now have access to the &#8220;Extra Update Center [...]]]></description>
			<content:encoded><![CDATA[<p>In the nightly build of netbeans there is a module that can be installed called &#8220;Extra Update Center Module&#8221;. This can be made available in Netbeans 6 beta 2 by going to Tools&#8211;&gt;Plugins&#8211;&gt;Settings and clicking the &#8220;add&#8221; button. Then use the following url:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">http://deadlock.netbeans.org/hudson/job/javadoc-nbms/lastSuccessfulBuild/artifact/nbbuild/nbms/updates.xml.gz</pre></div></div>

<p>Click &#8220;ok&#8221; and you should now have access to the &#8220;Extra Update Center Module&#8221;. Of course the plugins that are provided by this module could be unstable. That is why it is only included with the nightly builds. </p>
<p style="TEXT-ALIGN: center"><a href="http://batie.com/brett/media/autoUpdate_small2.jpg"  rel="lightbox" rel="lightbox[roadtrip]"><img alt="Extra Update Center Module" src="http://batie.com/brett/media/autoUpdate_small2.jpg" width="440" border="0" / /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://brett.batie.com/software-development/extra-update-center-module-netbeans-6-beta-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
