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

<channel>
	<title>Think Dietz</title>
	<atom:link href="http://thinkdietz.com/feed" rel="self" type="application/rss+xml" />
	<link>http://thinkdietz.com</link>
	<description>thinking about code</description>
	<lastBuildDate>Wed, 22 Feb 2012 22:47:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>jQuery Hybrid Droplist Text Input</title>
		<link>http://thinkdietz.com/jquery-hybrid-droplist-text-input.html</link>
		<comments>http://thinkdietz.com/jquery-hybrid-droplist-text-input.html#comments</comments>
		<pubDate>Wed, 22 Feb 2012 22:47:52 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://thinkdietz.com/?p=277</guid>
		<description><![CDATA[I recently needed a form input that acted like a select input with a droplist of items, but it also had to allow the customer to type in a custom... <a class="read-more" href="http://thinkdietz.com/jquery-hybrid-droplist-text-input.html">Read the Rest &#8594;</a>]]></description>
			<content:encoded><![CDATA[<p>I recently needed a form input that acted like a select input with a droplist of items, but it also had to allow the customer to type in a custom value. The customer wanted an input with and autocomplete droplist that didn&#8217;t force the user to use one of the autocomplete items.</p>
<p>In the jQuery docs there&#8217;s a jQuery UI Autocomplete Combobox Plugin. Since we use jQuery and the UI, I started with this code and did a simple update around where the autocomplete input is blanked out for &#8220;invalid&#8221; inputs:</p>
<pre><code>if ( !valid &#038;&#038; select.data(&quot;prevent_input&quot;) )</code></pre>
<p>The &#8220;prevent_input&#8221; setting will prevent the user from providing their own values if set to true (works like a standard select). Or it will allow user provided values if set to false (works like a standard input).</p>
<p>Configuring the input with jQuery data lets us set a default value like this:</p>
<pre><code>&lt;select id=&quot;your_select_id&quot; data-prevent_input=&quot;true&quot;/&gt;
...
$('#your_select_id').combobox();</code></pre>
<p>Note that the default behavior is to allow user provided values, but could be easily set to work the other way around.</p>
<p>Using jQuery.data() lets us change the behavior if your application needs to dynamically update this functionality:</p>
<pre><code>jQuery('#your_select_id').data(&quot;prevent_input&quot;, false);</code></pre>
<p>Here&#8217;s the plugin:</p>
<pre><code>
/**
 * jQuery UI Autocomplete Combobox Plugin
 *
 * Customized to allow users to type in arbitrary values
 *
 * @author dand
 * @since 10/21/2011
 */
(function( $ ) {
	$.widget( &quot;ui.combobox&quot;, {
		_create: function() {
			var self = this,
				select = this.element.hide(),
				selected = select.children( &quot;:selected&quot; ),
				value = selected.val() ? selected.text() : &quot;&quot;;
			var input = this.input = $( &#39;&lt;input id=&quot;&#39; + select.attr(&#39;id&#39;).replace(/_options/,&#39;&#39;) + &#39;&quot;&gt;&#39; )
				.insertAfter( select )
				.val( value )
				.autocomplete({
					delay: 0,
					minLength: 0,
					source: function( request, response ) {
						var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), &quot;i&quot; );
						response( select.children( &quot;option&quot; ).map(function() {
							var text = $( this ).text();
							if ( this.value &amp;&amp; ( !request.term || matcher.test(text) ) )
								return {
									label: text.replace(
										new RegExp(
											&quot;(?![^&amp;;]+;)(?!&lt;[^&lt;&gt;]*)(&quot; +
											$.ui.autocomplete.escapeRegex(request.term) +
											&quot;)(?![^&lt;&gt;]*&gt;)(?![^&amp;;]+;)&quot;, &quot;gi&quot;
										), &quot;&lt;strong&gt;$1&lt;/strong&gt;&quot; ),
									value: text,
									option: this
								};
						}) );
					},
					select: function( event, ui ) {
						ui.item.option.selected = true;
						self._trigger( &quot;selected&quot;, event, {
							item: ui.item.option
						});

					},
					change: function( event, ui ) {
						if ( !ui.item ) {
							var matcher = new RegExp( &quot;^&quot; + $.ui.autocomplete.escapeRegex( $(this).val() ) + &quot;$&quot;, &quot;i&quot; ),
								valid = false;
							select.children( &quot;option&quot; ).each(function() {
								if ( $( this ).text().match( matcher ) ) {
									this.selected = valid = true;
									return false;
								}
							});

							if ( !valid &amp;&amp; select.data(&quot;prevent_input&quot;) ) {
								// remove invalid value, as it didn&#39;t match anything
								$( this ).val( &quot;&quot; );
								select.val( &quot;&quot; );
								input.data( &quot;autocomplete&quot; ).term = &quot;&quot;;
								return false;
							}
						}
					}
				})
				.addClass( &quot;ui-widget ui-widget-content ui-corner-left&quot; );

			input.data( &quot;autocomplete&quot; )._renderItem = function( ul, item ) {
				return $( &quot;&lt;li&gt;&lt;/li&gt;&quot; )
					.data( &quot;item.autocomplete&quot;, item )
					.append( &quot;&lt;a&gt;&quot; + item.label + &quot;&lt;/a&gt;&quot; )
					.appendTo( ul );
			};

			this.button = $( &quot;&lt;button type=&#39;button&#39;&gt;&amp;nbsp;&lt;/button&gt;&quot; )
				.attr( &quot;tabIndex&quot;, -1 )
				.attr( &quot;title&quot;, &quot;Show All Items&quot; )
				.insertAfter( input )
				.button({
					icons: {
						primary: &quot;ui-icon-triangle-1-s&quot;
					},
					text: false
				})
				.removeClass( &quot;ui-corner-all&quot; )
				.addClass( &quot;ui-corner-right ui-button-icon&quot; )
				.click(function() {
					// close if already visible
					if ( input.autocomplete( &quot;widget&quot; ).is( &quot;:visible&quot; ) ) {
						input.autocomplete( &quot;close&quot; );
						return;
					}

					// work around a bug (likely same cause as #5265)
					$( this ).blur();

					// pass empty string as value to search for, displaying all results
					input.autocomplete( &quot;search&quot;, &quot;&quot; );
					input.focus();
				});
		},

		destroy: function() {
			this.input.remove();
			this.button.remove();
			this.element.show();
			$.Widget.prototype.destroy.call( this );
		}
	});
})( jQuery );
</code></pre>
<p>Our customer loved the solution because it was both what they wanted AND cheap since it was fast to develop. Hope you enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkdietz.com/jquery-hybrid-droplist-text-input.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>UPS Error 111286</title>
		<link>http://thinkdietz.com/ups-error-111286.html</link>
		<comments>http://thinkdietz.com/ups-error-111286.html#comments</comments>
		<pubDate>Thu, 19 Jan 2012 14:09:03 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://thinkdietz.com/?p=269</guid>
		<description><![CDATA[I had an odd issue with UPS shipment methods the other day. A customer complained that their Canadian address was not returning UPS shipment pricing. It&#8217;s important to note that... <a class="read-more" href="http://thinkdietz.com/ups-error-111286.html">Read the Rest &#8594;</a>]]></description>
			<content:encoded><![CDATA[<p>I had an odd issue with UPS shipment methods the other day.  A customer complained that their Canadian address was not returning UPS shipment pricing.  It&#8217;s important to note that on this particular (old) website, Canadian addresses are hand typed by the user into standard text inputs. Oops!</p>
<p>Don&#8217;t let users have the opportunity to enter garbage data.  If you do, they will.  It&#8217;s just one of those laws of the universe.  Thermodynamics?</p>
<p>Here&#8217;s the error:</p>
<pre><code>UPS: 111286: {Provided State} is not a valid state for the specified shipment.</code></pre>
<p>The state the user provided was:</p>
<pre><code>On</code></pre>
<p>Why didn&#8217;t that work?  The state codes are case sensitive, and must be exact.  Changing the customer&#8217;s address to use the following solved the problem:</p>
<pre><code>ON</code></pre>
<p>Note: I&#8217;ve seen other people with this problem on the web.  They complained about values like &#8220;Ontario&#8221; not being valid. Don&#8217;t let the user provide bad inputs, give them a select list of valid state codes.</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkdietz.com/ups-error-111286.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using GIT and p4merge on Mac OSX</title>
		<link>http://thinkdietz.com/using-git-and-p4merge-on-mac-osx.html</link>
		<comments>http://thinkdietz.com/using-git-and-p4merge-on-mac-osx.html#comments</comments>
		<pubDate>Wed, 03 Aug 2011 05:13:42 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://thinkdietz.com/?p=217</guid>
		<description><![CDATA[I found an article on setting up my .gitconfig file to launch p4merge as my custom merge tool: Using p4merge as a custom Git merge tool on Mac OS X... <a class="read-more" href="http://thinkdietz.com/using-git-and-p4merge-on-mac-osx.html">Read the Rest &#8594;</a>]]></description>
			<content:encoded><![CDATA[<p>I found an article on setting up my .gitconfig file to launch p4merge as my custom merge tool:<br />
<a href="http://deeperdesign.wordpress.com/2011/05/27/using-p4merge-as-a-custom-git-merge-tool-on-mac-os-x/">Using p4merge as a custom Git merge tool on Mac OS X</a></p>
<p>The problem was I would get the following errors when there were spaces in my merge file paths. For a path like <strong>/path/to the/file.rb</strong> I would get something like:</p>
<pre><code>
Incorrect parameters:
Too many files: You may enter a maximum of 4 files.
'/path/to' is (or points to) an invalid file.
'the/file.rb' is (or points to) an invalid file.
...
</code></pre>
<p>Here&#8217;s the easy solution that fixed this problem on my system:</p>
<pre><code>
[merge]
    keepBackup = false
	tool = custom
[mergetool "custom"]
	cmd = /Applications/p4merge.app/Contents/Resources/launchp4merge "\"$PWD/$BASE\"" "\"$PWD/$REMOTE\"" "\"$PWD/$LOCAL\"" "\"$PWD/$MERGED\""
	keepTemporaries = false
	trustExitCode = false
	keepBackup = false
</code></pre>
<p>Notice the extra (escaped) quote marks around the parameters.  This could also be handled with a shell script, but I didn&#8217;t want an extra moving part to make the magic happen. Life is already complicated&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkdietz.com/using-git-and-p4merge-on-mac-osx.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sitting Is Killing You</title>
		<link>http://thinkdietz.com/sitting-is-killing-you.html</link>
		<comments>http://thinkdietz.com/sitting-is-killing-you.html#comments</comments>
		<pubDate>Mon, 01 Aug 2011 14:58:22 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Life]]></category>

		<guid isPermaLink="false">http://thinkdietz.com/?p=203</guid>
		<description><![CDATA[Via: Medical Billing And Coding And me at my standing desk:]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.medicalbillingandcoding.org/sitting-kills"><img src="http://images.medicalbillingandcoding.org.s3.amazonaws.com/sitting-is-killing-you.jpg" alt="Sitting is Killing You" width="500"  border="0" /></a><br />Via: <a href="http://www.medicalbillingandcoding.org">Medical Billing And Coding</a></p>
<p>And me at my standing desk:<br/><br />
<a href="http://thinkdietz.com/wp-content/uploads/standing_desk_n.jpg"><img src="http://thinkdietz.com/wp-content/uploads/standing_desk_n.jpg" alt="" title="standing_desk_n" width="720" height="540" class="aligncenter size-full wp-image-205" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://thinkdietz.com/sitting-is-killing-you.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Duff&#8217;s Device</title>
		<link>http://thinkdietz.com/javascript-algorithms.html</link>
		<comments>http://thinkdietz.com/javascript-algorithms.html#comments</comments>
		<pubDate>Thu, 24 Feb 2011 00:52:27 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://thinkdietz.com/?p=92</guid>
		<description><![CDATA[I&#8217;m currently enjoying reading about algorithms that have been implemented in javascript. Here&#8217;s one called Duff&#8217;s Device that speeds up the execution of large loops by reducing the number of... <a class="read-more" href="http://thinkdietz.com/javascript-algorithms.html">Read the Rest &#8594;</a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently enjoying reading about algorithms that have been implemented in javascript.  Here&#8217;s one called Duff&#8217;s Device that speeds up the execution of large loops by reducing the number of iterations over the loop:</p>
<pre>
<code>
// Begin actual Duff's Device
// JS Implementation by Jeff Greenberg 2/2001

var n = iterations / 8;
var caseTest = iterations % 8;    

do {

    switch (caseTest){
    case 0:              [Do Something to tesVal here];
    case 7:              [Do Something to tesVal here];
    case 6:              [Do Something to tesVal here];
    case 5:              [Do Something to tesVal here];
    case 4:              [Do Something to tesVal here];
    case 3:              [Do Something to tesVal here];
    case 2:              [Do Something to tesVal here];
    case 1:              [Do Something to tesVal here];

    }
    caseTest=0;

}

while (--n > 0);
</code>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://thinkdietz.com/javascript-algorithms.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamic CC Month and Year Drop List</title>
		<link>http://thinkdietz.com/dynamic-cc-month-and-year-drop-list.html</link>
		<comments>http://thinkdietz.com/dynamic-cc-month-and-year-drop-list.html#comments</comments>
		<pubDate>Fri, 22 Oct 2010 00:49:02 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://thinkdietz.com/?p=78</guid>
		<description><![CDATA[I did a quick little Google search for a dynamic month and year droplist for credit card expiration dates. I tried two or three searches in Google and couldn&#8217;t find... <a class="read-more" href="http://thinkdietz.com/dynamic-cc-month-and-year-drop-list.html">Read the Rest &#8594;</a>]]></description>
			<content:encoded><![CDATA[<p>I did a quick little Google search for a dynamic month and year droplist for credit card expiration dates.  I tried two or three searches in Google and couldn&#8217;t find anything for PHP.  So I rolled my own:</p>
<pre>
<code>
//Inside my view
&lt;select id=&quot;exp_month&quot; name=&quot;exp_month&quot;&gt;
	&lt;?php MonthList() ?&gt;
&lt;/select&gt;

&lt;select id=&quot;exp_year&quot; name=&quot;exp_year&quot;&gt;
	&lt;?php YearList() ?&gt;
&lt;/select&gt;

//In your model/controller or some other place you like to keep random stuff like this
/**
 * Populate the credit card expiration month drop down
 */
function MonthList(){
	for($i=0; $i&lt;=11; $i++){
		$time = mktime(0, 0, 0, 1+$i, 1, 2000);
		$sMonthOptions .= &#39;&lt;option value=&quot;&#39; . date(&#39;m&#39;, $time) . &#39;&quot;&gt;&#39; . date(&#39;M&#39;, $time) . &#39;&lt;/option&gt;&#39;;
	}
	echo $sMonthOptions;
}

/**
 * Populate the credit card expiration year drop down (go out 12 years)
 */
function YearList(){
	for($i=0; $i&lt;=11; $i++){
		$nextyear = date(&quot;Y&quot;, mktime(0, 0, 0, 1, 1, date(&quot;Y&quot;)+$i));
	    $sYearOptions .= &#39;&lt;option value=&quot;&#39; . $nextyear . &#39;&quot;&gt;&#39; . $nextyear . &#39;&lt;/option&gt;&#39;;
	}
	echo $sYearOptions;
}
</code>
</pre>
<p>Disclaimer: I have no idea if 12 years is &#8220;enough&#8221;, nor if this is the most &#8220;efficient&#8221; way of doing this.  I also think a static html droplist of the months would be better&#8230; I don&#8217;t think we&#8217;re adding new months any time soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkdietz.com/dynamic-cc-month-and-year-drop-list.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Webistrano &#8211; Install&#8230; everything</title>
		<link>http://thinkdietz.com/webistrano-install-everything.html</link>
		<comments>http://thinkdietz.com/webistrano-install-everything.html#comments</comments>
		<pubDate>Sun, 19 Sep 2010 21:09:09 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://thinkdietz.com/?p=64</guid>
		<description><![CDATA[Need webistrano installed on CentOS? Well do I have the step-by-step, leave nothing out, directions for you! Skip the sections you don&#8217;t need, but this includes: installing Ruby, MySQL, Rack... <a class="read-more" href="http://thinkdietz.com/webistrano-install-everything.html">Read the Rest &#8594;</a>]]></description>
			<content:encoded><![CDATA[<p>Need webistrano installed on CentOS?  Well do I have the step-by-step, leave nothing out, directions for you!  Skip the sections you don&#8217;t need, but this includes: installing Ruby, MySQL, Rack 1.01, MySQL ruby gem, Webistrano w/ remote database.  That&#8217;s right! All the little details, even how to connect to that fathomdb database.</p>
<p>1) Ruby (and Rails)<br />
[okay... this is coming...]</p>
<p>3) &#8220;Fix&#8221; Rake</p>
<pre><code>
$ gem uninstall rack
$ gem install rack -v 1.0.1
</pre>
<p></code></p>
<p>2) MySQL<br />
(you need this even for a remote database, as it provides the necessary headers so we can install the drivers in step #4)</p>
<pre><code>
$ sudo yum remove mysql-server
$ sudo yum install mysql mysql-devel gcc
</pre>
<p></code></p>
<p>4) MySQL Gem</p>
<pre><code>
# 32 bit machine
$ sudo gem install mysql -- \
> --with-mysql-include=/usr/bin/mysql \
> --with-mysql-lib=/usr/lib/mysql

# or 64 bit like they are on SliceHost
$ sudo gem install mysql -- \
> --with-mysql-include=/usr/bin/mysql \
> --with-mysql-lib=/usr/lib64/mysq
</pre>
<p></code></p>
<p>5) Create databases (I like <a href="http://www.sequelpro.com">Sequel Pro</a>)</p>
<pre><code>
webistrano_development
webistrano_test
webistrano_production
</pre>
<p></code></p>
<p>5) Configure Webistrano - database.yml</p>
<pre><code>
...
development:
  adapter: mysql
  database: webistrano_development
  username: [user here]
  password: [password here]
  host: [dbase subdomain].mysql.fathomdb.com
  port: [port number]
...
</pre>
<p></code></p>
<p>6) Install Webistrano!!!</p>
<pre><code>
$ cd [webistrano dir]
$ rake db:migrate
</pre>
<p></code></p>
<p>7) Open port for Webistrano (or use webmin)<br />
Open-</p>
<pre><code>
/etc/sysconfig/iptables
</pre>
<p></code></p>
<p>Append rule-</p>
<pre><code>
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3000 -j ACCEPT
</pre>
<p></code></p>
<p>Restart the service</p>
<pre><code>
$ service iptables restart
</pre>
<p></code></p>
<p>Make sure iptables is allowing port 3000 connections:</p>
<pre><code>
$ iptables -L -n
</pre>
<p></code></p>
<p>8) DEPLOY SOMETHING!</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkdietz.com/webistrano-install-everything.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coupling – As in Software</title>
		<link>http://thinkdietz.com/coupling-%e2%80%93-as-in-software.html</link>
		<comments>http://thinkdietz.com/coupling-%e2%80%93-as-in-software.html#comments</comments>
		<pubDate>Mon, 02 Aug 2010 02:03:17 +0000</pubDate>
		<dc:creator>dan</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://thinkdietz.com/?p=33</guid>
		<description><![CDATA[One of my favorite things to rant about when at work is &#8220;tight coupling&#8221;. If you&#8217;re into software design or development, hopefully you&#8217;ll appreciate this little review of coupling: HIGH... <a class="read-more" href="http://thinkdietz.com/coupling-%e2%80%93-as-in-software.html">Read the Rest &#8594;</a>]]></description>
			<content:encoded><![CDATA[<p>One of my favorite things to rant about when at work is &#8220;tight coupling&#8221;.  If you&#8217;re into software design or development, hopefully you&#8217;ll appreciate this little review of coupling:</p>
<p>HIGH COUPLING</p>
<blockquote>
<ol>
<li>Content coupling (high): One module modifies or relies on the internal workings of another module</li>
<li>Common coupling: two modules share the same global data (e.g. a global variable). Changing the shared resource implies changing all the modules using it.</li>
<li>External coupling: two modules share an externally imposed data format, communication protocol, or device interface.</li>
<li>Control coupling: one module controlling the logic of another, by passing it information on what to do (e.g. passing a what-to-do flag).</li>
<li>Stamp coupling (Data-structured coupling): when modules share a composite data structure and use only a part of it, possibly a different part (e.g. passing a whole record to a function which only needs one field of it).</li>
<li>Data coupling: when modules share data through, for example, parameters. Each datum is an elementary piece, and these are the only data which are shared (e.g. passing an integer to a function which computes a square root).</li>
<li>Message coupling (low): Modules are not dependent on each other, instead they use a public interface to exchange parameter-less messages (or events, see <a href="http://en.wikipedia.org/wiki/Message_passing">Message passing</a>).</li>
<li>No coupling: Modules do not communicate at all with one another.</li>
</ol>
</blockquote>
<p>LOW COUPLING</p>
<p>So the next time you tightly couple something you will at least know you&#8217;re doing it (and be ready for when your software explodes). </p>
<p>Coupling list reproduced from Wikipedia&#8217;s <a href="http://en.wikipedia.org/wiki/Coupling_(computer_science)">coupling</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://thinkdietz.com/coupling-%e2%80%93-as-in-software.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

