<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>Brett's Software Development Blog</title>
	
	<link>http://brett.batie.com</link>
	<description>Thoughts of a Software Engineer.</description>
	<lastBuildDate>Tue, 04 Jan 2011 19:04:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/brettbatie" /><feedburner:info uri="brettbatie" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>brettbatie</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><feedburner:feedFlare href="http://add.my.yahoo.com/rss?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbrettbatie" src="http://us.i1.yimg.com/us.yimg.com/i/us/my/addtomyyahoo4.gif">Subscribe with My Yahoo!</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsgator.com/ngs/subscriber/subext.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbrettbatie" src="http://www.newsgator.com/images/ngsub1.gif">Subscribe with NewsGator</feedburner:feedFlare><feedburner:feedFlare href="http://feeds.my.aol.com/add.jsp?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbrettbatie" src="http://o.aolcdn.com/favorites.my.aol.com/webmaster/ffclient/webroot/locale/en-US/images/myAOLButtonSmall.gif">Subscribe with My AOL</feedburner:feedFlare><feedburner:feedFlare href="http://www.bloglines.com/sub/http://feeds.feedburner.com/brettbatie" src="http://www.bloglines.com/images/sub_modern11.gif">Subscribe with Bloglines</feedburner:feedFlare><feedburner:feedFlare href="http://www.netvibes.com/subscribe.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbrettbatie" src="http://www.netvibes.com/img/add2netvibes.gif">Subscribe with Netvibes</feedburner:feedFlare><feedburner:feedFlare href="http://fusion.google.com/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fbrettbatie" src="http://buttons.googlesyndication.com/fusion/add.gif">Subscribe with Google</feedburner:feedFlare><feedburner:feedFlare href="http://www.pageflakes.com/subscribe.aspx?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbrettbatie" src="http://www.pageflakes.com/ImageFile.ashx?instanceId=Static_4&amp;fileName=ATP_blu_91x17.gif">Subscribe with Pageflakes</feedburner:feedFlare><feedburner:feedFlare href="http://www.plusmo.com/add?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbrettbatie" src="http://plusmo.com/res/graphics/fbplusmo.gif">Subscribe with Plusmo</feedburner:feedFlare><feedburner:feedFlare href="http://www.thefreedictionary.com/_/hp/AddRSS.aspx?http%3A%2F%2Ffeeds.feedburner.com%2Fbrettbatie" src="http://img.tfd.com/hp/addToTheFreeDictionary.gif">Subscribe with The Free Dictionary</feedburner:feedFlare><feedburner:feedFlare href="http://www.bitty.com/manual/?contenttype=rssfeed&amp;contentvalue=http%3A%2F%2Ffeeds.feedburner.com%2Fbrettbatie" src="http://www.bitty.com/img/bittychicklet_91x17.gif">Subscribe with Bitty Browser</feedburner:feedFlare><feedburner:feedFlare href="http://www.newsalloy.com/?rss=http%3A%2F%2Ffeeds.feedburner.com%2Fbrettbatie" src="http://www.newsalloy.com/subrss3.gif">Subscribe with NewsAlloy</feedburner:feedFlare><feedburner:feedFlare href="http://www.live.com/?add=http%3A%2F%2Ffeeds.feedburner.com%2Fbrettbatie" src="http://tkfiles.storage.msn.com/x1piYkpqHC_35nIp1gLE68-wvzLZO8iXl_JMledmJQXP-XTBOLfmQv4zhj4MhcWEJh_GtoBIiAl1Mjh-ndp9k47If7hTaFno0mxW9_i3p_5qQw">Subscribe with Live.com</feedburner:feedFlare><feedburner:feedFlare href="http://mix.excite.eu/add?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fbrettbatie" src="http://image.excite.co.uk/mix/addtomix.gif">Subscribe with Excite MIX</feedburner:feedFlare><feedburner:feedFlare href="http://www.yourminis.com/subscribe.aspx?u=http%3A%2F%2Ffeeds.feedburner.com%2Fbrettbatie" src="http://www.yourminis.com/images/addtoyourminisbadge.gif">Subscribe with Yourminis.com</feedburner:feedFlare><feedburner:feedFlare href="http://download.attensa.com/app/get_attensa.html?feedurl=http%3A%2F%2Ffeeds.feedburner.com%2Fbrettbatie" src="http://www.attensa.com/blogs/attensa/WindowsLiveWriter/BadgeredintoBadges_10C02/attensa_feed_button5.gif">Subscribe with Attensa for Outlook</feedburner:feedFlare><feedburner:feedFlare href="http://www.webwag.com/wwgthis.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbrettbatie" src="http://www.webwag.com/images/wwgthis.gif">Subscribe with Webwag</feedburner:feedFlare><feedburner:feedFlare href="http://hub.netomat.net/account/account.autoSubscribe.jspa?urls=http%3A%2F%2Ffeeds.feedburner.com%2Fbrettbatie" src="http://www.netomat.net/blogger/images/icon_netomat_feedbutton.gif">Subscribe with netomat Hub</feedburner:feedFlare><feedburner:feedFlare href="http://www.podcastready.com/oneclick_bookmark.php?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbrettbatie" src="http://www.podcastready.com/images/podcastready_button.gif">Subscribe with Podcast Ready</feedburner:feedFlare><feedburner:feedFlare href="http://www.flurry.com/pushRssFeed.do?r=fb&amp;url=http%3A%2F%2Ffeeds.feedburner.com%2Fbrettbatie" src="http://www.flurry.com/images/flurry_rss_logo2.gif">Subscribe with Flurry</feedburner:feedFlare><feedburner:feedFlare href="http://www.wikio.com/subscribe?url=http%3A%2F%2Ffeeds.feedburner.com%2Fbrettbatie" src="http://www.wikio.com/shared/img/add2wikio.gif">Subscribe with Wikio</feedburner:feedFlare><feedburner:feedFlare href="http://www.dailyrotation.com/index.php?feed=http%3A%2F%2Ffeeds.feedburner.com%2Fbrettbatie" src="http://www.dailyrotation.com/rss-dr2.gif">Subscribe with Daily Rotation</feedburner:feedFlare><item>
		<title>Mercurial Hook for Syntax Checking (PHP)</title>
		<link>http://feedproxy.google.com/~r/brettbatie/~3/0VMAjpnHGmQ/</link>
		<comments>http://brett.batie.com/software-development/mercurial-hook-for-syntax-checking-php/#comments</comments>
		<pubDate>Fri, 08 Oct 2010 17:29:59 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[Mercurial]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[SCM]]></category>
		<category><![CDATA[Source Control]]></category>
		<category><![CDATA[Syntax]]></category>

		<guid isPermaLink="false">http://brett.batie.com/?p=526</guid>
		<description><![CDATA[For those unfamiliar with Mercurial, it is an awesome Source Control Management (SCM) tool. One of my favorite features of Mercurial is that the repositories are distributed which allows each machine to have a full copy of the project&#039;s history. Being distributed has many advantages such as faster committing, branching, tagging, merging, etc. since it [...]]]></description>
			<content:encoded><![CDATA[<p>For those unfamiliar with <a href="http://mercurial.selenic.com/">Mercurial,</a> it is an awesome <a href="http://en.wikipedia.org/wiki/Revision_control">Source Control Management (SCM)</a> tool. One of my favorite features of Mercurial is that the repositories are distributed which allows each machine to have a full copy of the project&#039;s history. Being distributed has many advantages such as faster committing, branching, tagging, merging, etc. since it is all done locally. Of course this setup also creates a backup of the repository each time an engineer clones a repository. There are a lot of benefits to using Mercurial, but that is not the focus of this post.</p>
<p>In this article, I am going to discuss how to setup a Mercurial hook to handle checking the syntax of files. Specifically, the hook will be setup to check the syntax of PHP files. This is beneficial as it will prevent users from adding files to Mercurial that are invalid and will keep the repository clean. Better yet, when dealing with a repository for a live website, it will prevent invalid files from ever being added to the live site.</p>
<h4>The Pretxnchangegroup Event</h4>
<p>Mercurial hooks are programs that Mercurial will execute during specific events. Ideally, a hook such as checking syntax would happen just before a commit is being made (the <a href="http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html#sec:hook:precommit">precommit</a> event). Since Mercurial is distributed, this would require each client to install and setup the hook. This may work for some, but it does require more work and can cause issues if the hook is not setup correctly on each machine.</p>
<p>There is a better solution for environments that have a central repository for everyone to push their changes to. Basically, the hook can be setup on the <a href="http://hgbook.red-bean.com/read/handling-repository-events-with-hooks.html#sec:hook:pretxnchangegroup">pretxnchangegroup</a> event. This event is executed just before a changeset (group of commits) is added to a remote repository (during a push).</p>
<p>To setup a hook on the pretxnchangegroup event, the syntax checking will need to build a list of every file that was changed for each changeset and then check the syntax on the latest version of each file. If there is a syntax error, the hook can exit with the appropriate status code to prevent the changesets from being added to the central repository.</p>
<p>When using the pretxnchangegroup event, each machine will be able to commit changes with files that have syntax errors. However, when trying to push the files to the central server, the changesets will be rejected until the syntax errors have been fixed.</p>
<h4>In Process vs. External Hooks</h4>
<p>With Mercurial, there are two types of hooks: an in-process and an external hook. An in-process hook is a Python module that is loaded at the time the Mercurial starts. An external hook can use any programming language that is supported by the OS.</p>
<p>These are advantages to using both an in-process and an external hook. An external hook is most beneficial when the code is already written in another language or the developers are more familiar with a language other than Python. An in-process hook has some nice advantages as it allows the developer access to the internals of Mercurial. It also gives the ability to display a message to the user when making a change in the repository.</p>
<h4>External Hook Using a Shell Script</h4>
<p>In order to show how Mercurial hooks work, I have developed both an external and in-process hook to check the syntax of PHP files. Below is the source code for an external hook. This hook is a bash script that I named php_syntax.sh.</p>
<pre class="brush: bash;">#!/usr/local/bin/bash
echo "STARTING PHP SYNTAX CHECK..."
# create a random temp file
temp_file=`/usr/bin/mktemp -t php_syntax_files`

# get all modified files and remove duplicate's
#note: use file_mods,file_adds instead
hg log -r $HG_NODE:tip --template "{files}\n" | sort | uniq &gt; $temp_file

# Walk through each line
#for line in "$temp_file"; do
for line in $(&lt; $temp_file); do
	# Make sure it is a php file
	if [ `echo $line |  grep -Ei ".+\.(php)|(php4)|(php5)$"` ]
	then
		# create a random temp file
		php_file=`/usr/bin/mktemp -t php_syntax_check`

		# save the contents of this file (latest commit) to the temp file
		hg cat -r tip $line &gt; $php_file

		# check the syntax
		php_syntax_output=`/usr/local/bin/php -l -d display_errors=1 -d error_reporting=4 -d html_errors=0 &lt; $php_file`;

		# remove the temp file
		rm -f $php_file;

		test_syntax=`echo $php_syntax_output | grep "Parse error"`
		if [ "$test_syntax" ];then
			exit 1;
		fi
	fi
done

rm -f "$temp_file"</pre>
<p>The above code will check the latest version of each file that is being changed when pushing to the server. It will only check files that have an extension of PHP, PHP4 or PHP5. The content of each file that is being pushed to the server is then stored in a temporary file and passed to PHP to check the syntax. If the syntax check fails, the program returns a 1 for failure which causes the entire push to fail so that no changes are pushed to the server. If there are no syntax errors, the hook exits normally and continues to push the files to the server.</p>
<p>In order to install the above hook in Mercurial, simply add the following 2 lines to the <a href="http://www.selenic.com/mercurial/hgrc.5.html">.hgrc</a> and/or the hgweb.config file.</p>
<pre class="brush: text;">[hooks]
pretxnchangegroup.syntax_check = /usr/home/mercurial/php_syntax.sh</pre>
<p>Of course the path in the above line needs to be updated to where the bash script was saved. The bash script will most likely need to be updated to contain the correct paths as well.</p>
<p>With all of the above in place the following message will be displayed to the user when trying to push a file that has a syntax error:</p>
<pre class="brush: text;">running hook pretxnchangegroup.syntax_check: /usr/home/code.softwareprojects.com/php_syntax.sh
transaction abort!
rollback completed
abort: pretxnchangegroup.syntax_check hook exited with status 127
warning: commit.autopush hook exited with status 1</pre>
<h4>In-Process Hook Using Python</h4>
<p>The major flaw with using the above shell script is it does not allow us to display a nice informative error to the user when their push fails due to a syntax error. This is one advantage of using a Python in-process hook instead. I have written very similar logic in Python which can be seen below:</p>
<pre class="brush: python;">import subprocess,os,re
import os.path
from mercurial import ui
from random import randrange
from time import time
def check(ui, repo, hooktype, node, **kwargs):
    #initialize variables
    error = ""
    fileSet = set()
    # Loop through each changeset being added to the repository
    for change_id in xrange(repo[node].rev(), len(repo)):
        # Loop through each file for the current changeset
        for currentFile in repo[change_id].files():
            # Only Check PHP Files
            if re.match('.*\.(php)|(php4)|(php5)',currentFile):
                # Build a unique list of each file that has changed
                fileSet.add(currentFile)
    # Loop through each file that has changed
    for currentFile in fileSet:
        # Grab the latest version of the current file in the changeset
        ctx = repo['tip']
        # Do not check the file if it is being deleted
        if currentFile not in ctx:
            continue;
        # Generate a unique temporary file name using random number and timestamp
        temp_file = '/tmp/php_syntax_check.%s%s' % (randrange(0,100000),int(time()))
        # Open the temp file for writing
        f = open(temp_file,'w')
        # Get the file context
        fctx = ctx[currentFile]
        # Save the contents of the current file to the temp file
        f.write(fctx.data())
        # Close the temp file
        f.close()
        # Check the syntax of the current/temp file
        proc = subprocess.Popen('/usr/local/bin/php-cgi -l -d display_errors=1 -d error_reporting=4 -d html_errors=0 < %s' % temp_file, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        # Retrieve the output of the syntax check
        out,err = proc.communicate()
        # Check for syntax errors and save them
        if 'Parse error' in out:
            error += "%s%s\n" % (out,currentFile)
    # Check if an error occured in any of the files that were changed
    if error != "":
        # Display a message to the user about each file that contained a syntax error
        ui.warn("******************************************************" +
            error +
            "******************************************************\n")
        # Reject the changesets
        return 1
    # Accept the changesets
    return 0</pre>
<p>This code is very similar in functionality to the shell script. It first builds a list of all of the files being pushed that have a PHP, PHP4 or PHP5 extension. Then it obtains the contents of each file that is being pushed and stores each file in a random temporary file. It checks the syntax of each file and then cancels the push if there is one or more files with invalid syntax.</p>
<p>Since this is an in-process hook, it is able to display a nice message to the user about why the push was not allowed. This hook is also set up to check every single file and display a message about every file that has a syntax error. This allows the hook to display a message to the user such as the following:</p>
<pre class="brush: text;">******************************************************
Parse error: syntax error, unexpected T_ECHO in - on line 3
Errors parsing -
afile_test.php

Parse error: syntax error, unexpected '@' in - on line 15
Errors parsing -
anotherfile_test.php
******************************************************</pre>
<p>In order to setup this hook with Mercurial, save the above Python code in a file that is on the <a href="http://docs.python.org/tutorial/modules.html#the-module-search-path">PYTHONPATH</a>. Then add the following two lines of code to the .hgrc and/or the hgweb.config file.</p>
<pre class="brush: text;">[hooks]
pretxnchangegroup.syntax_check = python:php_syntax.check</pre>
<p>It is important to point out that the text on the right half of the equals sign tells Mercurial what to load. In this example, it says use Python, look for a file named php_syntax.py and call the function check.</p>
<p>Also, Mercurial will need to be restarted after setting up the above hook or after each time the hook is modified. This is because the in-process hook is loaded when Mercurial/Python is first started.</p>
<h4>Conclusion</h4>
<p>Mercurial is a great SCM tool and can be very powerful when combined with either in-process or external hooks. In-process hooks provide much more control and are the preferred method in most cases. The examples above are just an introduction to Mercurial hooks and they can easily be modified for specific environments or checking the syntax of other languages.</p>
<p>Please leave a comment if you have found this code useful or share your experiences with Merucial and hooks.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/GRnpvqC4kod085w7aqjH5LDMpgg/0/da"><img src="http://feedads.g.doubleclick.net/~a/GRnpvqC4kod085w7aqjH5LDMpgg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/GRnpvqC4kod085w7aqjH5LDMpgg/1/da"><img src="http://feedads.g.doubleclick.net/~a/GRnpvqC4kod085w7aqjH5LDMpgg/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/brettbatie/~4/0VMAjpnHGmQ" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://brett.batie.com/software-development/mercurial-hook-for-syntax-checking-php/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://brett.batie.com/software-development/mercurial-hook-for-syntax-checking-php/</feedburner:origLink></item>
		<item>
		<title>Java Live Messenger (MSN) Robot</title>
		<link>http://feedproxy.google.com/~r/brettbatie/~3/3gyul-kYru8/</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 [...]]]></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("yourLogin@msn.com"), "yourPassword");
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()+" is currently "+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()+" is currently "+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&#039;s status changes.</p>

<p><a href="http://feedads.g.doubleclick.net/~a/cIyD2sbV6PF81MEGAi1bfqsZ4Sc/0/da"><img src="http://feedads.g.doubleclick.net/~a/cIyD2sbV6PF81MEGAi1bfqsZ4Sc/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/cIyD2sbV6PF81MEGAi1bfqsZ4Sc/1/da"><img src="http://feedads.g.doubleclick.net/~a/cIyD2sbV6PF81MEGAi1bfqsZ4Sc/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/brettbatie/~4/3gyul-kYru8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://brett.batie.com/software-development/java-live-messenger-msn-robot/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://brett.batie.com/software-development/java-live-messenger-msn-robot/</feedburner:origLink></item>
		<item>
		<title>UltraMon Breaks After Remote Desktop Connection (RDP)</title>
		<link>http://feedproxy.google.com/~r/brettbatie/~3/NrbmP8xlkcs/</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 [...]]]></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&#039;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 rel="lightbox" href="http://brett.batie.com/wp-content/uploads/sshot201004055.png"><img style="display: inline; margin-left: 0px; margin-right: 0px; border: 0px initial initial;" title="sshot-2010-04-05-[5]" src="http://brett.batie.com/wp-content/uploads/sshot201004055_thumb.png" border="0" alt="sshot-2010-04-05-[5]" width="121" height="130" align="right" /></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>

<p><a href="http://feedads.g.doubleclick.net/~a/QLYHZoFQEC9IxY0ngmXKwNZW0a8/0/da"><img src="http://feedads.g.doubleclick.net/~a/QLYHZoFQEC9IxY0ngmXKwNZW0a8/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/QLYHZoFQEC9IxY0ngmXKwNZW0a8/1/da"><img src="http://feedads.g.doubleclick.net/~a/QLYHZoFQEC9IxY0ngmXKwNZW0a8/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/brettbatie/~4/NrbmP8xlkcs" height="1" width="1"/>]]></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>
		<feedburner:origLink>http://brett.batie.com/software-development/ultramon-breaks-after-remote-desktop-connection-rdp/</feedburner:origLink></item>
		<item>
		<title>How to Setup BlackBerry (bb) with a Different Ringtone for each Email / Contact</title>
		<link>http://feedproxy.google.com/~r/brettbatie/~3/ITy1sc3rU0Q/</link>
		<comments>http://brett.batie.com/technology/how-to-setup-blackberry-bb-with-a-different-ringtone-for-each-email-contact/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 01:48:00 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://brett.batie.com/technology/how-to-setup-blackberry-bb-with-a-different-ringtone-for-each-email-contact/</guid>
		<description><![CDATA[The BlackBerry has the ability to setup ringtones for each application and also use different ringtones for each contact / email. These features are great for giving full control over notifications for email, phone call, SMS, MMS, IM, etc. With this article I will explain how to setup both application level notifications, contact/email level notifications [...]]]></description>
			<content:encoded><![CDATA[<p>The BlackBerry has the ability to setup ringtones for each application and also use different ringtones for each contact / email. These features are great for giving full control over notifications for email, phone call, SMS, MMS, IM, etc. With this article I will explain how to setup both application level notifications, contact/email level notifications and then how to setup profile switching at a given time of day.</p>
<h4>Application Level Notifications</h4>
<p>In order to setup the sounds that an application uses to notify of new events just go to <strong>Profiles</strong> on your BlackBerry. Scroll down to the bottom of this list and click <a rel="lightbox" href="http://brett.batie.com/wp-content/uploads/Capture12_35_25.jpg"><img style="margin-top: 10px; margin-right: 0px; margin-bottom: 5px; margin-left: 5px; display: inline; border: 0px initial initial;" title="Capture12_35_25" src="http://brett.batie.com/wp-content/uploads/Capture12_35_25_thumb.jpg" border="0" alt="Capture12_35_25" align="right" /></a><strong>Advanced</strong>. Now you will see a list of your profiles (screenshot on right). Scroll to the profile you would like to edit and click the <strong>BlackBerry button, </strong>located on the left of the trackball. A list of all of the installed applications is shown including the different email accounts. <strong>Select a specific application</strong> or email account, click the <strong>BlackBerry button </strong>and <strong>select edit</strong>. This will pull up a page that gives different options for how the application is allowed to notify when new events occur, this can be seen in the screenshot below. Modify these settings to have your preferred ringtones, vibrations, LED flashing, etc. Then repeat these steps for other applications and other profiles.</p>
<p><a rel="lightbox" href="http://brett.batie.com/wp-content/uploads/Capture12_38_54.jpg"><img style="display: block; margin-left: auto; margin-right: auto; border: 0px initial initial;" title="Capture12_38_54" src="http://brett.batie.com/wp-content/uploads/Capture12_38_54_thumb.jpg" border="0" alt="Capture12_38_54" /></a></p>
<h4>Contact / Email Level Notifications</h4>
<p>There are a few different ways to setup notifications for contacts and emails. I have found the easiest option is to use <strong>exceptions</strong>.</p>
<p>Exceptions allow a custom ring tone to be used for a specific contact or a group of contacts. The exception will work with all profiles except the <strong>Off</strong> profile. The exception can also be muted by the currently selected profile if that is desired.</p>
<p>Using exceptions works perfect for the scenario where someone should always be able to reach you like the wife/husband or boss (which could be the same person). This also works well for specific people (or email addresses) that should be able to reach you while using a specific profile. This might be something like work related emails that are important during business hours but not in the middle of the night.</p>
<p>The following steps can be used to setup an exception:</p>
<ol>
<li>Go to <strong>Profiles</strong> and select <strong>Advanced</strong></li>
<li>Click the <strong>BlackBerry button </strong>(left of the scroll wheel) and select <strong>New Exception</strong>.</li>
<li>Type in a name for the exception (maybe something like &#034;Urgent&#034;)</li>
<li>In the <strong>From:</strong> field click the scroll wheel and select a contact. Repeat this step to add more than one contact to the exception.</li>
<li>In the <strong>Use Profile:</strong> field select the desired profile that this contact or group of contacts will always use. For the contacts that should always be able to reach you the <strong>Loud</strong> profile is a good option. For contacts that should only be able to reach you while using a specific profile select <strong>Active Profile</strong>. With this option if the active profile is one where the application is muted the ringtone will not play. If the profile is one where the application is not muted the ringtone will play.</li>
<li>Select the custom phone tune.</li>
<li>Click the <strong>BlackBerry button</strong> and select <strong>save</strong></li>
</ol>
<p>There is also another option that will give control over emails by setting up specific email addresses as <strong>level 1</strong> emails. Each profile has a specific ringtone,vibration and LED flashing for Level 1 emails.</p>
<p>Emails can be set as level one by applying filters at the following site:</p>
<p><a title="https://bis.na.blackberry.com/html" href="https://bis.na.blackberry.com/html">https://bis.na.blackberry.com/html</a></p>
<p>It is unfortunate that this is not a little more integrated into the blackberry but as long as you know your login/password you can do the following:</p>
<ol>
<li>Login and select the Filter Option on the right hand side of the screen for a specific email address.</li>
<li>Click <strong>Add a Filter</strong></li>
<li>Give the filter a name</li>
<li>Select when to <strong>apply the filter</strong>. This can be based on the From email address, subject, to email address, CC email address, new mail or high priority mail.</li>
<li>Fill in <strong>Contains</strong> value that applies to the filter option selected in step 4.</li>
<li>Select<strong> filter messages to device </strong>check <strong>Level 1 notification </strong>and click <strong>Add Filter</strong></li>
</ol>
<p>Now when an email message comes that meets the requirement of the newly added filter the <strong>Level 1 </strong>notification settings will be used.</p>
<p><strong> </strong></p>
<h4>Automatic Profile Switching</h4>
<p>By default there is not currently a way to automatically switch profiles at a specific time of the day. Having a feature like this is very beneficial if there is any regularity to your schedule (like meetings, classes, sleeping, etc).</p>
<p><a rel="lightbox" href="http://brett.batie.com/wp-content/uploads/25780.png"><img style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 5px; display: inline; border: 0px initial initial;" title="25780" src="http://brett.batie.com/wp-content/uploads/HowtoSetupBlackberrybbwithDifferentRingt_985C/25780_thumb.png" border="0" alt="25780" align="right" /></a>Even though a scheduled profile option is not built into the BlackBerry by default there is a third party app that does give us this feature. The app is called <strong><a title="ProfilerPRO" href="http://appworld.blackberry.com/webstore/content/4048">ProfilerPro</a> </strong>(cost $3.99). I just installed this on my blackberry for the first time but it appears to work perfectly for profile switching.</p>
<p>Hopefully all of the steps above will help gain control over the mass amount of media that is thrown at us every day. Are there any other tips or tricks that you use to keep your blackberry optimized?</p>

<p><a href="http://feedads.g.doubleclick.net/~a/JlpyIzCJhrn7YP9Rq84DuHSngSg/0/da"><img src="http://feedads.g.doubleclick.net/~a/JlpyIzCJhrn7YP9Rq84DuHSngSg/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/JlpyIzCJhrn7YP9Rq84DuHSngSg/1/da"><img src="http://feedads.g.doubleclick.net/~a/JlpyIzCJhrn7YP9Rq84DuHSngSg/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/brettbatie/~4/ITy1sc3rU0Q" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://brett.batie.com/technology/how-to-setup-blackberry-bb-with-a-different-ringtone-for-each-email-contact/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://brett.batie.com/technology/how-to-setup-blackberry-bb-with-a-different-ringtone-for-each-email-contact/</feedburner:origLink></item>
		<item>
		<title>Putty with Tango Look &amp; Feel (using regedit script)</title>
		<link>http://feedproxy.google.com/~r/brettbatie/~3/X6SX6fzu6Yk/</link>
		<comments>http://brett.batie.com/scripting/putty-with-tango-look-feel-using-regedit-script/#comments</comments>
		<pubDate>Tue, 23 Mar 2010 23:20:16 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://brett.batie.com/dosshell/putty-with-tango-look-feel-using-regedit-script/</guid>
		<description><![CDATA[I ran into a powershell script that Tomas Restrepo created to set putty up with a better color scheme. The color theme he used was based on Tango. This inspired me to make a few updates to my default configuration for putty. I used the powershell script to update my color theme and then updated [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into a <a href="http://brett.batie.com/dosshell/intro-to-windows-power-shell/">powershell</a> script that <a href="http://winterdom.com/me">Tomas Restrepo</a> created to set putty up with a better color scheme. The color theme he used was based on <a href="http://tango.freedesktop.org/Tango_Icon_Theme_Guidelines">Tango</a>.</p>
<p>This inspired me to make a few updates to my default configuration for putty. I used the powershell script to update my color theme and then updated the configuration so that my home and end keys would work correctly (I&#039;ve been putting up with that one for too long).</p>
<p>If anyone would like to use the same settings as me they can just download the following registry file and double click. </p>
<a href=http://brett.batie.com/download/myPutty.reg><img src=http://brett.batie.com/wp-content/plugins/download-monitor/img/downloads-icon.gif width="45" height="45" style="vertical-align: middle;">DOWNLOAD: Registry Script to Update Putty Configuration</a> <span style="font-size: x-small;">(1382 Downloads)</span>
<p>The source code for the above file is the following:</p>
<pre class="brush: text;">Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\Default%20Settings]
&quot;Present&quot;=dword:00000001
&quot;HostName&quot;=&quot;&quot;
&quot;LogFileName&quot;=&quot;putty.log&quot;
&quot;LogType&quot;=dword:00000000
&quot;LogFileClash&quot;=dword:ffffffff
&quot;LogFlush&quot;=dword:00000001
&quot;SSHLogOmitPasswords&quot;=dword:00000001
&quot;SSHLogOmitData&quot;=dword:00000000
&quot;Protocol&quot;=&quot;ssh&quot;
&quot;PortNumber&quot;=dword:00000016
&quot;CloseOnExit&quot;=dword:00000001
&quot;WarnOnClose&quot;=dword:00000001
&quot;PingInterval&quot;=dword:00000000
&quot;PingIntervalSecs&quot;=dword:0000000f
&quot;TCPNoDelay&quot;=dword:00000001
&quot;TCPKeepalives&quot;=dword:00000000
&quot;TerminalType&quot;=&quot;linux&quot;
&quot;TerminalSpeed&quot;=&quot;38400,38400&quot;
&quot;TerminalModes&quot;=&quot;INTR=A,QUIT=A,ERASE=A,KILL=A,EOF=A,EOL=A,EOL2=A,START=A,STOP=A,SUSP=A,DSUSP=A,REPRINT=A,WERASE=A,LNEXT=A,FLUSH=A,SWTCH=A,STATUS=A,DISCARD=A,IGNPAR=A,PARMRK=A,INPCK=A,ISTRIP=A,INLCR=A,IGNCR=A,ICRNL=A,IUCLC=A,IXON=A,IXANY=A,IXOFF=A,IMAXBEL=A,ISIG=A,ICANON=A,XCASE=A,ECHO=A,ECHOE=A,ECHOK=A,ECHONL=A,NOFLSH=A,TOSTOP=A,IEXTEN=A,ECHOCTL=A,ECHOKE=A,PENDIN=A,OPOST=A,OLCUC=A,ONLCR=A,OCRNL=A,ONOCR=A,ONLRET=A,CS7=A,CS8=A,PARENB=A,PARODD=A,&quot;
&quot;AddressFamily&quot;=dword:00000000
&quot;ProxyExcludeList&quot;=&quot;&quot;
&quot;ProxyDNS&quot;=dword:00000001
&quot;ProxyLocalhost&quot;=dword:00000000
&quot;ProxyMethod&quot;=dword:00000000
&quot;ProxyHost&quot;=&quot;proxy&quot;
&quot;ProxyPort&quot;=dword:00000050
&quot;ProxyUsername&quot;=&quot;&quot;
&quot;ProxyPassword&quot;=&quot;&quot;
&quot;ProxyTelnetCommand&quot;=&quot;connect %host %port\\n&quot;
&quot;Environment&quot;=&quot;&quot;
&quot;UserName&quot;=&quot;&quot;
&quot;LocalUserName&quot;=&quot;&quot;
&quot;NoPTY&quot;=dword:00000000
&quot;Compression&quot;=dword:00000000
&quot;TryAgent&quot;=dword:00000001
&quot;AgentFwd&quot;=dword:00000000
&quot;ChangeUsername&quot;=dword:00000000
&quot;Cipher&quot;=&quot;aes,blowfish,3des,WARN,arcfour,des&quot;
&quot;KEX&quot;=&quot;dh-gex-sha1,dh-group14-sha1,dh-group1-sha1,WARN&quot;
&quot;RekeyTime&quot;=dword:0000003c
&quot;RekeyBytes&quot;=&quot;1G&quot;
&quot;SshNoAuth&quot;=dword:00000000
&quot;AuthTIS&quot;=dword:00000000
&quot;AuthKI&quot;=dword:00000001
&quot;SshNoShell&quot;=dword:00000000
&quot;SshProt&quot;=dword:00000002
&quot;SSH2DES&quot;=dword:00000000
&quot;PublicKeyFile&quot;=&quot;&quot;
&quot;RemoteCommand&quot;=&quot;&quot;
&quot;RFCEnviron&quot;=dword:00000000
&quot;PassiveTelnet&quot;=dword:00000000
&quot;BackspaceIsDelete&quot;=dword:00000001
&quot;RXVTHomeEnd&quot;=dword:00000000
&quot;LinuxFunctionKeys&quot;=dword:00000000
&quot;NoApplicationKeys&quot;=dword:00000000
&quot;NoApplicationCursors&quot;=dword:00000000
&quot;NoMouseReporting&quot;=dword:00000000
&quot;NoRemoteResize&quot;=dword:00000000
&quot;NoAltScreen&quot;=dword:00000000
&quot;NoRemoteWinTitle&quot;=dword:00000000
&quot;RemoteQTitleAction&quot;=dword:00000001
&quot;NoDBackspace&quot;=dword:00000000
&quot;NoRemoteCharset&quot;=dword:00000000
&quot;ApplicationCursorKeys&quot;=dword:00000000
&quot;ApplicationKeypad&quot;=dword:00000000
&quot;NetHackKeypad&quot;=dword:00000000
&quot;AltF4&quot;=dword:00000001
&quot;AltSpace&quot;=dword:00000000
&quot;AltOnly&quot;=dword:00000000
&quot;ComposeKey&quot;=dword:00000000
&quot;CtrlAltKeys&quot;=dword:00000001
&quot;TelnetKey&quot;=dword:00000000
&quot;TelnetRet&quot;=dword:00000001
&quot;LocalEcho&quot;=dword:00000002
&quot;LocalEdit&quot;=dword:00000002
&quot;Answerback&quot;=&quot;PuTTY&quot;
&quot;AlwaysOnTop&quot;=dword:00000000
&quot;FullScreenOnAltEnter&quot;=dword:00000000
&quot;HideMousePtr&quot;=dword:00000000
&quot;SunkenEdge&quot;=dword:00000000
&quot;WindowBorder&quot;=dword:00000001
&quot;CurType&quot;=dword:00000000
&quot;BlinkCur&quot;=dword:00000000
&quot;Beep&quot;=dword:00000001
&quot;BeepInd&quot;=dword:00000000
&quot;BellWaveFile&quot;=&quot;&quot;
&quot;BellOverload&quot;=dword:00000001
&quot;BellOverloadN&quot;=dword:00000005
&quot;BellOverloadT&quot;=dword:000007d0
&quot;BellOverloadS&quot;=dword:00001388
&quot;ScrollbackLines&quot;=dword:00002328
&quot;DECOriginMode&quot;=dword:00000000
&quot;AutoWrapMode&quot;=dword:00000001
&quot;LFImpliesCR&quot;=dword:00000000
&quot;DisableArabicShaping&quot;=dword:00000000
&quot;DisableBidi&quot;=dword:00000000
&quot;WinNameAlways&quot;=dword:00000001
&quot;WinTitle&quot;=&quot;&quot;
&quot;TermWidth&quot;=dword:00000050
&quot;TermHeight&quot;=dword:00000018
&quot;Font&quot;=&quot;Courier New&quot;
&quot;FontIsBold&quot;=dword:00000000
&quot;FontCharSet&quot;=dword:00000000
&quot;FontHeight&quot;=dword:0000000a
&quot;FontQuality&quot;=dword:00000000
&quot;FontVTMode&quot;=dword:00000004
&quot;UseSystemColours&quot;=dword:00000000
&quot;TryPalette&quot;=dword:00000000
&quot;ANSIColour&quot;=dword:00000001
&quot;Xterm256Colour&quot;=dword:00000001
&quot;BoldAsColour&quot;=dword:00000001
&quot;Colour0&quot;=&quot;187,187,187&quot;
&quot;Colour1&quot;=&quot;255,255,255&quot;
&quot;Colour2&quot;=&quot;8,8,8&quot;
&quot;Colour3&quot;=&quot;85,85,85&quot;
&quot;Colour4&quot;=&quot;0,0,0&quot;
&quot;Colour5&quot;=&quot;0,255,0&quot;
&quot;Colour6&quot;=&quot;46,52,54&quot;
&quot;Colour7&quot;=&quot;85,87,83&quot;
&quot;Colour8&quot;=&quot;204,0,0&quot;
&quot;Colour9&quot;=&quot;239,41,41&quot;
&quot;Colour10&quot;=&quot;78,154,6&quot;
&quot;Colour11&quot;=&quot;138,226,52&quot;
&quot;Colour12&quot;=&quot;196,160,0&quot;
&quot;Colour13&quot;=&quot;252,233,79&quot;
&quot;Colour14&quot;=&quot;52,101,164&quot;
&quot;Colour15&quot;=&quot;114,159,207&quot;
&quot;Colour16&quot;=&quot;117,80,123&quot;
&quot;Colour17&quot;=&quot;173,127,168&quot;
&quot;Colour18&quot;=&quot;6,152,154&quot;
&quot;Colour19&quot;=&quot;52,226,226&quot;
&quot;Colour20&quot;=&quot;211,215,207&quot;
&quot;Colour21&quot;=&quot;238,238,236&quot;
&quot;RawCNP&quot;=dword:00000000
&quot;PasteRTF&quot;=dword:00000000
&quot;MouseIsXterm&quot;=dword:00000000
&quot;RectSelect&quot;=dword:00000000
&quot;MouseOverride&quot;=dword:00000001
&quot;Wordness0&quot;=&quot;0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0&quot;
&quot;Wordness32&quot;=&quot;0,1,2,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1&quot;
&quot;Wordness64&quot;=&quot;1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,2&quot;
&quot;Wordness96&quot;=&quot;1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1&quot;
&quot;Wordness128&quot;=&quot;1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1&quot;
&quot;Wordness160&quot;=&quot;1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1&quot;
&quot;Wordness192&quot;=&quot;2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2&quot;
&quot;Wordness224&quot;=&quot;2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,2,2,2,2,2,2,2,2&quot;
&quot;LineCodePage&quot;=&quot;&quot;
&quot;CJKAmbigWide&quot;=dword:00000000
&quot;UTF8Override&quot;=dword:00000001
&quot;Printer&quot;=&quot;&quot;
&quot;CapsLockCyr&quot;=dword:00000000
&quot;ScrollBar&quot;=dword:00000001
&quot;ScrollBarFullScreen&quot;=dword:00000000
&quot;ScrollOnKey&quot;=dword:00000000
&quot;ScrollOnDisp&quot;=dword:00000001
&quot;EraseToScrollback&quot;=dword:00000001
&quot;LockSize&quot;=dword:00000000
&quot;BCE&quot;=dword:00000001
&quot;BlinkText&quot;=dword:00000000
&quot;X11Forward&quot;=dword:00000000
&quot;X11Display&quot;=&quot;&quot;
&quot;X11AuthType&quot;=dword:00000001
&quot;LocalPortAcceptAll&quot;=dword:00000000
&quot;RemotePortAcceptAll&quot;=dword:00000000
&quot;PortForwardings&quot;=&quot;&quot;
&quot;BugIgnore1&quot;=dword:00000000
&quot;BugPlainPW1&quot;=dword:00000000
&quot;BugRSA1&quot;=dword:00000000
&quot;BugHMAC2&quot;=dword:00000000
&quot;BugDeriveKey2&quot;=dword:00000000
&quot;BugRSAPad2&quot;=dword:00000000
&quot;BugPKSessID2&quot;=dword:00000000
&quot;BugRekey2&quot;=dword:00000000
&quot;StampUtmp&quot;=dword:00000001
&quot;LoginShell&quot;=dword:00000001
&quot;ScrollbarOnLeft&quot;=dword:00000000
&quot;BoldFont&quot;=&quot;&quot;
&quot;BoldFontIsBold&quot;=dword:0018f8e4
&quot;BoldFontCharSet&quot;=dword:016ef0a9
&quot;BoldFontHeight&quot;=dword:7719041d
&quot;WideFont&quot;=&quot;&quot;
&quot;WideFontIsBold&quot;=dword:0018cc20
&quot;WideFontCharSet&quot;=dword:0018f8e4
&quot;WideFontHeight&quot;=dword:0018cb1c
&quot;WideBoldFont&quot;=&quot;&quot;
&quot;WideBoldFontIsBold&quot;=dword:000003f8
&quot;WideBoldFontCharSet&quot;=dword:0018cc20
&quot;WideBoldFontHeight&quot;=dword:01000032
&quot;ShadowBold&quot;=dword:00000000
&quot;ShadowBoldOffset&quot;=dword:00000001
&quot;SerialLine&quot;=&quot;COM1&quot;
&quot;SerialSpeed&quot;=dword:00002580
&quot;SerialDataBits&quot;=dword:00000008
&quot;SerialStopHalfbits&quot;=dword:00000002
&quot;SerialParity&quot;=dword:00000000
&quot;SerialFlowControl&quot;=dword:00000001</pre>

<p><a href="http://feedads.g.doubleclick.net/~a/NN8YTYpNz_mBPl9w7657t06uCno/0/da"><img src="http://feedads.g.doubleclick.net/~a/NN8YTYpNz_mBPl9w7657t06uCno/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/NN8YTYpNz_mBPl9w7657t06uCno/1/da"><img src="http://feedads.g.doubleclick.net/~a/NN8YTYpNz_mBPl9w7657t06uCno/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/brettbatie/~4/X6SX6fzu6Yk" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://brett.batie.com/scripting/putty-with-tango-look-feel-using-regedit-script/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<feedburner:origLink>http://brett.batie.com/scripting/putty-with-tango-look-feel-using-regedit-script/</feedburner:origLink></item>
		<item>
		<title>Format Credit Card with X's and Dashes using PHP (credit card masking)</title>
		<link>http://feedproxy.google.com/~r/brettbatie/~3/KQ53eLGGo0A/</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&#039;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 [...]]]></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&#039;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>

<p><a href="http://feedads.g.doubleclick.net/~a/k-eQXdc0A4RmK8jUt1YFr7_uyRQ/0/da"><img src="http://feedads.g.doubleclick.net/~a/k-eQXdc0A4RmK8jUt1YFr7_uyRQ/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/k-eQXdc0A4RmK8jUt1YFr7_uyRQ/1/da"><img src="http://feedads.g.doubleclick.net/~a/k-eQXdc0A4RmK8jUt1YFr7_uyRQ/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/brettbatie/~4/KQ53eLGGo0A" height="1" width="1"/>]]></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>3</slash:comments>
		<feedburner:origLink>http://brett.batie.com/software-development/post-about-format-credit-card-with-xs-and-dashes-using-php/</feedburner:origLink></item>
		<item>
		<title>Update .htaccess with Dynamic DNS IP Address to Prevent Password Protection</title>
		<link>http://feedproxy.google.com/~r/brettbatie/~3/nHuFOOkjpIs/</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 [...]]]></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 &#034;Allow from&#034;. 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 &#034;# Allow from person.getmyip.com&#034; 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>

<p><a href="http://feedads.g.doubleclick.net/~a/2i_pjD9TeWiCeF7L6gVH4Jdm_yE/0/da"><img src="http://feedads.g.doubleclick.net/~a/2i_pjD9TeWiCeF7L6gVH4Jdm_yE/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/2i_pjD9TeWiCeF7L6gVH4Jdm_yE/1/da"><img src="http://feedads.g.doubleclick.net/~a/2i_pjD9TeWiCeF7L6gVH4Jdm_yE/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/brettbatie/~4/nHuFOOkjpIs" height="1" width="1"/>]]></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>1</slash:comments>
		<feedburner:origLink>http://brett.batie.com/software-development/update-htaccess-with-dynamic-dns-ip-address-to-prevent-password-protection/</feedburner:origLink></item>
		<item>
		<title>Paste Code – Live Writer Plugin To Paste HTML/Code</title>
		<link>http://feedproxy.google.com/~r/brettbatie/~3/KuPIuDNEMiY/</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 [...]]]></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 width="45" height="45" style="vertical-align: middle;">DOWNLOAD: Paste Code For Windows Live Writer</a> <span style="font-size: x-small;">(813 Downloads)</span>
<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 &#034;Edit&#034; 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;&#039;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 &#034;Source&#034; 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 &#034;Edit&#034; and &#034;Source&#034; 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 &#034;Edit&#034; or &#034;Source&#034; windows. It will replace special characters so that the code will be viewable and will not insert extra HTML (like &lt;br /&gt;&#039;s).</p>
<p>Below is a screenshot of the plugin in action:</p>
<p><a rel="lightbox" href="http://brett.batie.com/wp-content/uploads/sshot201003063.png"><img style="display: inline; border: 0px initial initial;" title="sshot-2010-03-06-[3]" src="http://brett.batie.com/wp-content/uploads/sshot201003063_thumb.png" border="0" alt="sshot-2010-03-06-[3]" width="296" height="320" /></a></p>
<p>This plugin will automatically take the code that exists on the clipboard and display it in the &#034;Code Snippet&#034; section and give the ability to edit the code before pasting it.</p>
<p>It also has the &#034;Before Code Snippet&#034; and &#034;After Code Snippet&#034; text areas. These two text areas allow defining code to wrap around your code snippet. By default the two box&#039;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 &#034;Before Code Snippet&#034; and &#034;After Code Snippet&#034; 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 width="45" height="45" style="vertical-align: middle;">DOWNLOAD: Paste Code For Windows Live Writer</a> <span style="font-size: x-small;">(813 Downloads)</span>
<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&#039;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 rel="lightbox" href="http://brett.batie.com/wp-content/uploads/sshot201003064.png"><img style="display: inline; border: 0px initial initial;" title="sshot-2010-03-06-[4]" src="http://brett.batie.com/wp-content/uploads/sshot201003064_thumb.png" border="0" alt="sshot-2010-03-06-[4]" /></a></p>

<p><a href="http://feedads.g.doubleclick.net/~a/41XLVOXxOLir1KowhffF5eTbYig/0/da"><img src="http://feedads.g.doubleclick.net/~a/41XLVOXxOLir1KowhffF5eTbYig/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/41XLVOXxOLir1KowhffF5eTbYig/1/da"><img src="http://feedads.g.doubleclick.net/~a/41XLVOXxOLir1KowhffF5eTbYig/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/brettbatie/~4/KuPIuDNEMiY" height="1" width="1"/>]]></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>
		<feedburner:origLink>http://brett.batie.com/software-development/live-writer-plugin-to-paste-html-code/</feedburner:origLink></item>
		<item>
		<title>How to: Watch Netflix in Chrome</title>
		<link>http://feedproxy.google.com/~r/brettbatie/~3/eTPZmlYvPDM/</link>
		<comments>http://brett.batie.com/website_development/how-to-watch-netflix-in-chrome/#comments</comments>
		<pubDate>Fri, 13 Mar 2009 19:03:25 +0000</pubDate>
		<dc:creator>Brett</dc:creator>
				<category><![CDATA[Website Development]]></category>

		<guid isPermaLink="false">http://brett.batie.com/?p=197</guid>
		<description><![CDATA[I just recently started playing with Chrome and after a bit of investigation I think I am going to make the switch from my current browser Maxthon. One problem I noticed when using Chrome was I could no longer watch instant movies in Netflix. Now, I could do what they recommend and use Internet Explorer [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_198" class="wp-caption alignright" style="width: 160px"><a href="http://brett.batie.com/wp-content/uploads/sshot-2009-03-13-4.png"><img class="size-thumbnail wp-image-198" title="Netflix in Chrome" src="http://brett.batie.com/wp-content/uploads/sshot-2009-03-13-4-150x150.png" alt="Screenshot of netflix loading in Chrome" width="150" height="150" /></a><p class="wp-caption-text">Screenshot of Netflix loading in Chrome</p></div>
<p>I just recently started playing with <a href="http://www.google.com/chrome">Chrome</a> and after a bit of investigation I think I am going to make the switch from my current browser <a href="http://www.maxthon.com">Maxthon</a>. One problem I noticed when using Chrome was I could no longer watch instant movies in <a href="http://www.netflix.com">Netflix</a>. Now, I could do what they recommend and use Internet Explorer (or Maxthon) to view a movie but I&#039;m stubborn and wanted to view it in Chrome so I found a way.</p>
<p>When Netflix loads a video it is using Microsoft Silverlight which is something that Chrome supports and gave me my first clue that there is no reason why Chrome shouldn&#039;t be able to view a Netflix video. The solution was actually rather simple, tell Netflix that I&#039;m not actually using Chrome but using Safari on the Mac. In order to do this you just have to add the following parameter when starting Chrome.</p>
<pre class="brush:text"> --user-agent="Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_3; en-us) AppleWebKit/525.19 (KHTML, like Gecko) Version/3.2.1 Safari/525.19"</pre>
<div id="attachment_201" class="wp-caption alignright" style="width: 160px"><a href="http://brett.batie.com/wp-content/uploads/sshot-2009-03-13-2.png"><img class="size-thumbnail wp-image-201" title="Google Chrome Properties" src="http://brett.batie.com/wp-content/uploads/sshot-2009-03-13-2-150x150.png" alt="Add Parameter to Google Chrome Startup" width="150" height="150" /></a><p class="wp-caption-text">Add Parameter to Google Chrome Startup</p></div>
<p>To add this parameter right click the Google Chrome shortcut and go down to <strong>Properties</strong>. Then after chrome.exe in the <strong>Target:</strong> box paste the above text (make sure you include a space after chrome.exe).</p>
<p>I also tried changing the user agent to make Chrome appear like it is Internet Explorer. After applying that change Netflix gave me a activeX not supported error (image below). Since the problem was solved with the Safari user-agent text above I wasn&#039;t too worried about it.</p>
<div id="attachment_200" class="wp-caption alignleft" style="width: 160px"><a href="http://brett.batie.com/wp-content/uploads/sshot-2009-03-13-1.png"><img class="size-thumbnail wp-image-200 " title="ActiveX is disabled" src="http://brett.batie.com/wp-content/uploads/sshot-2009-03-13-1-150x150.png" alt="ActiveX is disabled" width="150" height="150" /></a><p class="wp-caption-text">ActiveX is disabled</p></div>

<p><a href="http://feedads.g.doubleclick.net/~a/x8gJyNkiAjk6DAZY4biFdIDwLOY/0/da"><img src="http://feedads.g.doubleclick.net/~a/x8gJyNkiAjk6DAZY4biFdIDwLOY/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/x8gJyNkiAjk6DAZY4biFdIDwLOY/1/da"><img src="http://feedads.g.doubleclick.net/~a/x8gJyNkiAjk6DAZY4biFdIDwLOY/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/brettbatie/~4/eTPZmlYvPDM" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://brett.batie.com/website_development/how-to-watch-netflix-in-chrome/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		<feedburner:origLink>http://brett.batie.com/website_development/how-to-watch-netflix-in-chrome/</feedburner:origLink></item>
		<item>
		<title>How to Modify a Program's Icon</title>
		<link>http://feedproxy.google.com/~r/brettbatie/~3/YrNsCaCRm4E/</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"><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 &#034;<strong>Open file with new icon&#8230;</strong>&#034; button</li>
<li>Select the new icon (like C:\Program Files\Microsoft Office\Office12\EXCEL.exe)</li>
<li>Click the &#034;<strong>Replace</strong>&#034; button</li>
<li>Click<strong> File→Save</strong> in the Menu Bar</li>
<li><strong>Close</strong> Resource Hacker All Done</li>
</ol>

<p><a href="http://feedads.g.doubleclick.net/~a/49zb4D5StVh-p25wdefU8KR87s4/0/da"><img src="http://feedads.g.doubleclick.net/~a/49zb4D5StVh-p25wdefU8KR87s4/0/di" border="0" ismap="true"></img></a><br/>
<a href="http://feedads.g.doubleclick.net/~a/49zb4D5StVh-p25wdefU8KR87s4/1/da"><img src="http://feedads.g.doubleclick.net/~a/49zb4D5StVh-p25wdefU8KR87s4/1/di" border="0" ismap="true"></img></a></p><img src="http://feeds.feedburner.com/~r/brettbatie/~4/YrNsCaCRm4E" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://brett.batie.com/software-development/how-to-modify-a-programs-icon/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://brett.batie.com/software-development/how-to-modify-a-programs-icon/</feedburner:origLink></item>
	</channel>
</rss>

