<?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 Batie</title> <link>http://brett.batie.com</link> <description>Thoughts of a Software Engineer.</description> <lastBuildDate>Tue, 22 Jan 2013 21:42:37 +0000</lastBuildDate> <language>en-US</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.5.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>Mysqldump Specific Table From All Databases</title><link>http://feedproxy.google.com/~r/brettbatie/~3/1knKCjNHT9k/</link> <comments>http://brett.batie.com/uncategorized/mysqldump-specific-table-from-all-databases/#comments</comments> <pubDate>Tue, 22 Jan 2013 21:39:30 +0000</pubDate> <dc:creator>Brett</dc:creator> <category><![CDATA[Uncategorized]]></category> <guid isPermaLink="false">http://brett.batie.com/?p=633</guid> <description><![CDATA[I recently had a task where I needed to export a specific table that was in a few hundred different databases. However, mysqldump does not have a way to specify that a specific table should be dumped out of every database. See the supported formats below: mysqldump [options] db_name [tbl_name ...] mysqldump [options] --databases db_name [...]]]></description> <content:encoded><![CDATA[<p></p><p>I recently had a task where I needed to export a specific table that was in a few hundred different databases. However, mysqldump does not have a way to specify that a specific table should be dumped out of every database. See the supported formats below:</p><p><code>mysqldump [options] db_name [tbl_name ...]<br
/> mysqldump [options] --databases db_name ...<br
/> mysqldump [options] --all-databases</code></p><p>I was hoping for a command like: <code>mysqldump --all-databases 'table_name'</code>.</p><p>mysqldump does have an <code>--ignore-table</code> option but in my case there were too many different tables to list and I didn&#8217;t want to go there.</p><p>My next thought was to build a quick PHP script that would loop through every database, check if the desired table exists and then mysqldump it. Before I had the chance to start on this approach I realized I could accomplish this with a one line shell command. The approach I took was the following:</p><pre class="brush: bash;">mysql -s -N -e "select TABLE_SCHEMA from information_schema.tables where TABLE_NAME='users'" | xargs -I % sh -c 'mysqldump % users | mysql -uUSERNAME -pPASSWORD -hHOST %'</pre><p>In the example above, I got a list of all databases (TABLE_SCHEMA) that contained a &#8220;users&#8221; table. I piped that output to xargs which runs mysqldump on the specific database and users table. Last I piped mysqldump to send the output to another server so that it could be imported in the same step.</p> <img src="http://feeds.feedburner.com/~r/brettbatie/~4/1knKCjNHT9k" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://brett.batie.com/uncategorized/mysqldump-specific-table-from-all-databases/feed/</wfw:commentRss> <slash:comments>1</slash:comments> <feedburner:origLink>http://brett.batie.com/uncategorized/mysqldump-specific-table-from-all-databases/</feedburner:origLink></item> <item><title>Automatically Allocate IP Address to AWS Instances</title><link>http://feedproxy.google.com/~r/brettbatie/~3/Nol88ngo20s/</link> <comments>http://brett.batie.com/software-development/automatically-allocate-ip-address-to-aws-instances/#comments</comments> <pubDate>Mon, 31 Dec 2012 19:48:27 +0000</pubDate> <dc:creator>Brett</dc:creator> <category><![CDATA[AWS]]></category> <category><![CDATA[Software Development]]></category> <guid isPermaLink="false">http://brett.batie.com/?p=616</guid> <description><![CDATA[I recently had a task where I needed to quickly start up 50 spot instances that all required an Elastic IP (EIP) address. I initially worked out the steps in the web console and determined I needed to accomplish the following: Request 50 spot instances based on an existing AMI Allocate 50 new EIPs Associate [...]]]></description> <content:encoded><![CDATA[<p></p><p>I recently had a task where I needed to quickly start up 50 spot instances that all required an Elastic IP (EIP) address. I initially worked out the steps in the web console and determined I needed to accomplish the following:</p><ol><li>Request 50 spot instances based on an existing AMI</li><li>Allocate 50 new EIPs</li><li>Associate each EIP with one of the newly running spot instances.</li></ol><p>Requesting 50 spot instances from the web console was quick and painless. However, the EIP allocation and association quickly become tiresome. As the Amazon web console only allows allocating and associating 1 EIP at a time. To repeat the following steps 50 times did not seem like a good use of time: requesting a new EIP, determining the appropriate instance ID to associate with the EIP and then assigning the EIP</p><p>Instead I decided to quickly put together a few commands to achieve the goal using the AWS API. First I issued a request for 50 instances with a command like the following</p><pre class="brush: bash;">ec2-request-spot-instances ami-1d2b34e5 --price .15 -n50 -s subnet-c1f234ae -t m2.4xlarge --kernel aki-88aa75e1</pre><p>Of course the above command will need to be modified for each specific case. The specific AMI ID, max bid price, number of instances, subnet, instance type and kernel will all need their respective values modified.</p><p>Then I waited until all of the instances were running with a command like the following:</p><pre class="brush: bash;">ec2-describe-instances --filter "instance-state-code=16" | grep 'spot' | grep -E '10\.0\.1\.[0-9]{1,3}\s+vpc' | wc -l</pre><p>The above command lists all of the running instances (instance-stat-code=16), limits it to only spot instances and then limits the output to a specific VPC that has an internal address in the 10.0.1.* range.</p><p>Once the above command displayed 50 I was ready to start allocating and associating IP addresses. I accomplished this with a combinations of commands. I needed to use <a
href="http://docs.amazonwebservices.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-AllocateAddress.html">ec2-allocate-address</a> to request a new EIP and <a
href="http://docs.amazonwebservices.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-DescribeInstances.html">ec2-describe-instances</a> to get a list of instances that need an EIP. Last, <a
href="http://docs.amazonwebservices.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-AssociateAddress.html">ec2-associate-address</a> needed to be used to associate the new EIP with a specific instance ID. The command to accomplish this looked like the following:</p><pre class="brush: bash;">for((i=0;i&lt;50;i++)); do ec2-associate-address -a `ec2-allocate-address -d vpc | cut -f5` -i `ec2-describe-instances --filter "instance-state-code=16" | grep 'spot' | grep -E 'monitoring-[a-Z]+\s+10\.0\.1' | cut -f2 | head -n1`; done</pre><p>The above runs the <a
href="http://docs.amazonwebservices.com/AWSEC2/latest/CommandLineReference/ApiReference-cmd-AssociateAddress.html">ec2-associate-address</a> command 50 times. It then runs two sub commands one which requests a new EIP address in the vpc (ec2-allocate-address -d vpc) and one which gets the next running spot instance that does not have an EIP (ec2-describe-instances &#8211;filter &#8220;instance-state-code=16&#8243;&#8230;).</p><p>Last, the new EIPs can be listed with a command like the following:</p><pre class="brush: bash;">ec2-describe-instances | grep 'spot' | cut -f17</pre><p>This worked beautifully for my goal of quickly firing up 50 spot instances and assigning an EIP address. As always, there is room for improvement. If automating something like this on a regular basis, I would suggest taking the one line command and doing more validation on the output of each command. The above assumes that everything is in a good state and that no issues occur in requesting or assigning the EIPs.</p><p>Let me know if you find this useful!</p> <img src="http://feeds.feedburner.com/~r/brettbatie/~4/Nol88ngo20s" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://brett.batie.com/software-development/automatically-allocate-ip-address-to-aws-instances/feed/</wfw:commentRss> <slash:comments>0</slash:comments> <feedburner:origLink>http://brett.batie.com/software-development/automatically-allocate-ip-address-to-aws-instances/</feedburner:origLink></item> <item><title>HydraIRC / Freenode – Auto Connect, Identify, Join</title><link>http://feedproxy.google.com/~r/brettbatie/~3/-Z8R89Gb1j4/</link> <comments>http://brett.batie.com/software-development/hydrairc-freenode-auto-connect-identify-join/#comments</comments> <pubDate>Thu, 28 Jun 2012 00:06:29 +0000</pubDate> <dc:creator>Brett</dc:creator> <category><![CDATA[Software Development]]></category> <guid isPermaLink="false">http://brett.batie.com/?p=550</guid> <description><![CDATA[I often join IRC channels where other developers hang out. I&#8217;ve found this to be very beneficial in keeping up to speed with changing technologies. I generally stick to two servers Freenode and OFTC. Freenode is by far my favorite as it seems to be the standard server for other developers to join and create [...]]]></description> <content:encoded><![CDATA[<p></p><p>I often join <a
title="IRC" href="http://en.wikipedia.org/wiki/Internet_Relay_Chat">IRC</a> channels where other developers hang out. I&#8217;ve found this to be very beneficial in keeping up to speed with changing technologies. I generally stick to two servers <a
title="freenode" href="http://freenode.net/">Freenode</a> and <a
title="OFTC" href="http://www.oftc.net/oftc/">OFTC</a>. Freenode is by far my favorite as it seems to be the standard server for other developers to join and create channels about their products.</p><p>Over the years, I&#8217;ve found this extremely beneficial. I can generally get immediate responses about bugs, feature requests and up-coming enhancements in software I&#8217;m using. Also, if I need a feature added to a piece of software I can code it up and send it straight to the developers. I do highly recommend all developers participate in IRC channels as a huge amount of quality information is being shared and it&#8217;s easy to find someone who is more specialized in a specific software development topic.</p><p>That said, I&#8217;ve used <a
title="HydraIRC" href="http://www.hydrairc.com/">HydraIRC</a> for the last year and it&#8217;s been growing on me. I was previously using <a
title="mIRC" href="http://www.mirc.com/">mIRC</a> which is also a good product.</p><h3>Automated Connection To Two Servers</h3><p>The very first task I had after installing HydraIRC was to set up an automated script to connect to my favorite servers and favorite channels. The scripting piece was quite simple and consisted of the following steps:</p><ol><li>Open HydraIRC and click<strong> Options &#8211;&gt; Prefs</strong>, then click <strong>Scripts</strong></li><li>In the Command Profiles box type the name &#8220;<strong>OnStartup</strong>&#8221; (this is case-sensitive)</li><li>In the Commands window type the commands to join the server. For me this was:</li></ol><pre class="brush:text">/server irc.freenode.net:6667
/newserver irc.oftc.net:6667</pre><p><img
class="alignnone size-large wp-image-579" title="HydraIRC Preferences On Startup Script" src="http://brett.batie.com/wp-content/uploads/2012/06/HydraIRC_Preferences_2012-06-27_16-13-42-600x416.png" alt="HydraIRC Preferences On Startup Script" width="600" height="416" /></p><p>With those two command in-place HydraIRC will automatically connect to both Freenode and OFTC when I first start the application. Sweet! As a developer doesn&#8217;t it always feel good to save a little time?</p><h3>Join Channels After Connect</h3><p>Now, we just need to create two more scripts to connect to specific channels after we join the servers. This consists of the following (similar steps):</p><ol><li>Open HydraIRC and click <strong>Options &#8211;&gt; Prefs</strong>, then click <strong>Scripts</strong></li><li>In the Command Profiles box type the name &#8220;<strong>irc.freenode.net_OnLoggedIn</strong>&#8221; (again case-sensitive) or <strong>irc.oftc.net_OnLoggedIn</strong>. Basically, the format is <strong>serverName_OnLoggedIn</strong>.</li><li>In the commands window type:</li></ol><pre class="brush: text;">/join #php
/join #java
/join #html
/join #apache
(and whatever other channels you like)</pre><h3 class="brush: text;">Identify After Connect But Before Channel Join</h3><p>With the above in place OFTC was working perfectly but Freenode was telling me:</p><blockquote><p>Cannot join channel &#8211; you need to be identified with the service</p></blockquote><p>To resolve this, the command: <strong>/msg NickServ identify </strong> needs be sent to the server (it&#8217;s like logging in).</p><p>The trouble is, doing the commands in the following order does not work:</p><pre class="brush: text;">/msg NickServ identify myPass
/join #php
/join #java</pre><p>This is because HydraIRC does not wait for the response to the <strong>identify</strong> command but instead immediately runs the next <strong>join</strong> command. This means HydraIRC tries to join the channels before the server has finished identifying my nick. Darn!</p><p>With a little more thought I did come to a solution that has worked very well. Basically, I needed to execute:</p><pre class="brush: text;">/msg NickServ identify myPass
(pause)
/join #php
/join #java</pre><p>But, wait, HydraIRC does not have a (pause). The work around was to instead use ping which I&#8217;ve seen used for pausing in other <a
href="http://stackoverflow.com/questions/735285/how-to-wait-in-a-batch-script">scripts that do not support a true pause/wait</a> (i.e. Dos Batch Script).</p><p>I modified my irc.freenode.net_OnLoggedIn profile to have the following commands and now when I fire up HydraIRC. I automatically connect to my favorite servers, log into nickserv, and join my favorite channels, all while sipping on a little coffee!</p><pre class="brush: text;">/msg nickserv identify myPass
/ping localhost
/ping localhost
/ping localhost
/ping localhost
/ping localhost
/ping localhost
/ping localhost
/ping localhost
/ping localhost
/ping localhost
/ping localhost
/ping localhost
/ping localhost
/ping localhost
/ping localhost
/ping localhost
/ping localhost
/ping localhost
/ping localhost
/ping localhost
/join #php</pre><p>I love automation!</p><p><strong>What other handy scripts do you use in your IRC client? Please do share!</strong></p><p>&nbsp;</p> <img src="http://feeds.feedburner.com/~r/brettbatie/~4/-Z8R89Gb1j4" height="1" width="1"/>]]></content:encoded> <wfw:commentRss>http://brett.batie.com/software-development/hydrairc-freenode-auto-connect-identify-join/feed/</wfw:commentRss> <slash:comments>3</slash:comments> <feedburner:origLink>http://brett.batie.com/software-development/hydrairc-freenode-auto-connect-identify-join/</feedburner:origLink></item> <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&#8217;s history. Being distributed has many advantages such as faster committing, branching, tagging, merging, etc. since it [...]]]></description> <content:encoded><![CDATA[<p></p><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&#8217;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 &lt; %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)</pre><pre class="brush: python;">        os.unlink(temp_file);
    # 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> <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>3</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></p><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&#8217;s status changes.</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></p><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
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> <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></p><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 &#8220;Urgent&#8221;)</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> <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>1</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></p><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&#8217;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;">(1978 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><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>4</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&#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 [...]]]></description> <content:encoded><![CDATA[<p></p><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> <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>4</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></p><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><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>5</slash:comments> <feedburner:origLink>http://brett.batie.com/software-development/update-htaccess-with-dynamic-dns-ip-address-to-prevent-password-protection/</feedburner:origLink></item> </channel> </rss><!-- Dynamic page generated in 0.584 seconds. --><!-- Cached page generated by WP-Super-Cache on 2013-05-19 08:45:10 -->
