<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>MTJ Hax</title>
	<atom:link href="http://mtjhax.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://mtjhax.wordpress.com</link>
	<description>Ruby on Rails, web hosting, web development. Helpful tips and occasional rants.</description>
	<lastBuildDate>Tue, 24 Jan 2012 23:46:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='mtjhax.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>MTJ Hax</title>
		<link>http://mtjhax.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://mtjhax.wordpress.com/osd.xml" title="MTJ Hax" />
	<atom:link rel='hub' href='http://mtjhax.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Ruby 1.8 strftime works differently on Linux and Windows</title>
		<link>http://mtjhax.wordpress.com/2010/12/27/ruby-1-8-strftime-works-differently-on-linux-and-windows/</link>
		<comments>http://mtjhax.wordpress.com/2010/12/27/ruby-1-8-strftime-works-differently-on-linux-and-windows/#comments</comments>
		<pubDate>Mon, 27 Dec 2010 05:52:28 +0000</pubDate>
		<dc:creator>mtjhax</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[strftime]]></category>

		<guid isPermaLink="false">http://mtjhax.wordpress.com/?p=327</guid>
		<description><![CDATA[Running Ruby 1.8 on Linux, cygwin, Mac, any POSIX environment: now = Time.now =&#62; Mon Dec 27 18:28:28 -0500 2010 now.strftime("%l") # that's a lowercase "L" =&#62; " 6" Under Windows using the exact same Ruby version and patch level: now = Time.now =&#62; Mon Dec 27 18:28:28 -0500 2010 now.strftime("%l") # that's a lowercase [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mtjhax.wordpress.com&amp;blog=9781304&amp;post=327&amp;subd=mtjhax&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Running Ruby 1.8 on Linux, cygwin, Mac, any POSIX environment:<br />
<code><br />
now = Time.now<br />
=&gt; Mon Dec 27 18:28:28 -0500 2010<br />
now.strftime("%l")  # that's a lowercase "L"<br />
=&gt; " 6"</code></p>
<p>Under Windows using the exact same Ruby version and patch level:<br />
<code><br />
now = Time.now<br />
=&gt; Mon Dec 27 18:28:28 -0500 2010<br />
now.strftime("%l")  # that's a lowercase "L"<br />
=&gt; ""</code></p>
<p>What? It turns out in Ruby 1.8 they cheated by simply calling the standard C strftime() function to implement Ruby&#8217;s strftime method. Because different compilers implement strftime() differently, compiling it under Windows results in a different set of supported % directives. Specifically, it looks like under Windows only the basic ANSI C version is implemented, but under POSIX compilers you get a mix of directives defined by ANSI and other standards like Gnu and Single Unix Specification. The &#8220;%l&#8221; directive was not even listed in the Ruby 1.8 docs &#8212; it worked by accident.</p>
<p>The good news is in Rails 1.9 they appear to have implemented their own strftime for consistency, instead of handing it off to the C compiler. If you need to fix this in the meantime, I provide the following monkey patch (which I simply place in my Rails config/initializers folder on any Windows developer machine):</p>
<p><pre class="brush: ruby;">
# monkey patch Ruby strftime methods to implement
# %l directive that is missing in Windows Ruby
#
# as a monkey patch, just use this on your Windows
# development boxes to bridge the gap, it's not
# recommended for production
#
# notes:
# - you may want to add support for other missing directives
# - check your RUBY_PLATFORM and make sure it is in the regexp below
#
if RUBY_PLATFORM =~ /mingw32|mingw64|mswin32|mswin64/

  class Time
    alias_method :original_strftime, :strftime
    def strftime(fmt)
      hour12 = &quot;%2d&quot; % ((hour + 11) % 12 + 1)
      original_strftime(fmt.gsub(/%l/, hour12))
    end
  end
 
  class Date
    alias_method :original_strftime, :strftime
    def strftime(fmt)
      hour12 = &quot;%2d&quot; % ((hour + 11) % 12 + 1)
      original_strftime(fmt.gsub(/%l/, hour12))
    end
  end

end
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mtjhax.wordpress.com/327/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mtjhax.wordpress.com/327/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mtjhax.wordpress.com/327/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mtjhax.wordpress.com/327/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mtjhax.wordpress.com/327/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mtjhax.wordpress.com/327/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mtjhax.wordpress.com/327/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mtjhax.wordpress.com/327/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mtjhax.wordpress.com/327/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mtjhax.wordpress.com/327/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mtjhax.wordpress.com/327/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mtjhax.wordpress.com/327/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mtjhax.wordpress.com/327/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mtjhax.wordpress.com/327/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mtjhax.wordpress.com&amp;blog=9781304&amp;post=327&amp;subd=mtjhax&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mtjhax.wordpress.com/2010/12/27/ruby-1-8-strftime-works-differently-on-linux-and-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ddc001baf1557b859437c18ffec7f86d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mtjhax</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby SystemTimer gem for Windows</title>
		<link>http://mtjhax.wordpress.com/2010/12/23/ruby-systemtimer-gem-for-windows/</link>
		<comments>http://mtjhax.wordpress.com/2010/12/23/ruby-systemtimer-gem-for-windows/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 02:03:42 +0000</pubDate>
		<dc:creator>mtjhax</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[devkit]]></category>
		<category><![CDATA[gem]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rubygems]]></category>
		<category><![CDATA[systemtimer]]></category>
		<category><![CDATA[system_timer]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://mtjhax.wordpress.com/?p=325</guid>
		<description><![CDATA[SystemTimer is a Gem that replaces timeout.rb and fixes some potentially serious flaws when accessing system resources (e.g., when communicating with remote APIs) in Linux/Posix environments. In a nutshell, timeout.rb uses Ruby pseudo-threads (&#8220;green threads&#8221;) that are not guaranteed to be given the same equal opportunities in the CPU as real system threads, resulting in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mtjhax.wordpress.com&amp;blog=9781304&amp;post=325&amp;subd=mtjhax&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>SystemTimer is a Gem that replaces timeout.rb and fixes some potentially serious flaws when accessing system resources (e.g., when communicating with remote APIs) in Linux/Posix environments. In a nutshell, timeout.rb uses Ruby pseudo-threads (&#8220;green threads&#8221;) that are not guaranteed to be given the same equal opportunities in the CPU as real system threads, resulting in synchronization problems. Visit <a href="http://ph7spot.com/musings/system-timer">http://ph7spot.com/musings/system-timer</a> for all the details.</p>
<p>If you end up needing to use SystemTimer on your production environment and you develop on Windows, you have a problem. SystemTimer&#8217;s documentation says that it can be installed under Windows (providing the same interface for your code but not really changing anything &#8212; it just acts as a wrapper to timeout.rb). In practice, however, trying to &#8220;gem install SystemTimer&#8221; results in errors building the native extensions even if you have the <a href="http://rubyinstaller.org/add-ons/devkit/">RubyInstaller DevKit</a> installed.</p>
<p>Solution? Simple! I don&#8217;t know who ghazel is but my hat&#8217;s off to them. They took the time to branch the SystemTimer project, patch it to install under Windows and simply provide the wrapper classes without trying to compile anything, and put it up on RubyGems.org.</p>
<p>Visit <a href="http://rubygems.org/gems/ghazel-SystemTimer">http://rubygems.org/gems/ghazel-SystemTimer</a> or just &#8220;gem install ghazel-SystemTimer&#8221; and you should be good to go on your Windows development box in about two seconds.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mtjhax.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mtjhax.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mtjhax.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mtjhax.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mtjhax.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mtjhax.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mtjhax.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mtjhax.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mtjhax.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mtjhax.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mtjhax.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mtjhax.wordpress.com/325/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mtjhax.wordpress.com/325/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mtjhax.wordpress.com/325/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mtjhax.wordpress.com&amp;blog=9781304&amp;post=325&amp;subd=mtjhax&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mtjhax.wordpress.com/2010/12/23/ruby-systemtimer-gem-for-windows/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ddc001baf1557b859437c18ffec7f86d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mtjhax</media:title>
		</media:content>
	</item>
		<item>
		<title>The Health Care Reform Math Game</title>
		<link>http://mtjhax.wordpress.com/2010/11/11/the-health-care-reform-math-game/</link>
		<comments>http://mtjhax.wordpress.com/2010/11/11/the-health-care-reform-math-game/#comments</comments>
		<pubDate>Thu, 11 Nov 2010 07:15:54 +0000</pubDate>
		<dc:creator>mtjhax</dc:creator>
				<category><![CDATA[politics]]></category>
		<category><![CDATA[rants & raves]]></category>
		<category><![CDATA[basic math for fuckwits]]></category>
		<category><![CDATA[health care]]></category>
		<category><![CDATA[health care reform]]></category>
		<category><![CDATA[obama]]></category>

		<guid isPermaLink="false">http://mtjhax.wordpress.com/?p=320</guid>
		<description><![CDATA[Normally I don&#8217;t do political stuff on my blog, but I shut down my rants &#38; raves blog because I&#8217;m too busy coding and this is too entertaining to keep to myself. Let&#8217;s play the Health Care Reform Math Game! To be more specific let&#8217;s horribly simplify the economics of health care reform in a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mtjhax.wordpress.com&amp;blog=9781304&amp;post=320&amp;subd=mtjhax&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Normally I don&#8217;t do political stuff on my blog, but I shut down my rants &amp; raves blog because I&#8217;m too busy coding and this is too entertaining to keep to myself.</p>
<p>Let&#8217;s play the Health Care Reform Math Game! To be more specific let&#8217;s horribly simplify the economics of health care reform in a way that would shock the pants off your average economist, just to see where it leads. Hey if conservatives can simplify it to one number (&#8220;health care reform will cost us a trillion dollars and bankrupt the country, oh noes!&#8221;) then I am allowed to grossly simplify it to a series of averages and swags, fair enough? Let&#8217;s play!</p>
<p>So big bad Obama spent 1 trillion on health care. Pretty bad huh? He is evil and should be in jail or sent back to Kenya where he&#8217;s really from, etc. Well, it is spread out over 10 years, so let&#8217;s call it 100 billion per year. Of course, we don&#8217;t intend to pay that all at once &#8212; it would probably become part of the deficit but just for fun let&#8217;s say we need to pay it off and not hand this monster of unholy evil to our children who will suffer the folly of our communist dictator.</p>
<p>There are about 150 million working Americans, so on average each of us would have to cover a terrifying 666 dollars per year to make this reform happen. Ohh noes! 666! That proves Obama is the devil! No, wait &#8212; that&#8217;s just an average. The rich would pay more and the poor would pay less &#8212; phew, may have dodged a bullet there. So this horrible abomination shoved down our throats that no one wanted nightmare basically amounts to $55/month for each working American to guarantee better access to health care and reduce health care costs by making sure everyone pays into the kitty instead of taking a free ride on Johnny Taxpayer&#8217;s nickel.</p>
<p>Wait a second&#8230; $55/month doesn&#8217;t sound very, well, socialist. Want to know what my health insurance costs me per month? $1,200 per month for my family. Should I be worried about $55 more to guarantee that if someone ended up with cancer the insurer wouldn&#8217;t dump us out on the street? Well, it&#8217;s the principal of the matter really &#8212; Obama and Pelosi are definitely criminal, evil, lying, socialists who should be in prison because any amount of money taken from the American people without their consent is wrong, even if it is to help the very people who whine about it like kicked dogs.</p>
<p>And hey if my math is wrong, show me your math instead of name-calling and whining! Game on!</p>
<p>(Seriously, feel free to correct me, but you can&#8217;t argue with the basic point that minimizing a complex economic issue into a single number and hyperbolizing that it will bankrupt the country is just plain wrong.)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mtjhax.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mtjhax.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mtjhax.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mtjhax.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mtjhax.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mtjhax.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mtjhax.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mtjhax.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mtjhax.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mtjhax.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mtjhax.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mtjhax.wordpress.com/320/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mtjhax.wordpress.com/320/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mtjhax.wordpress.com/320/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mtjhax.wordpress.com&amp;blog=9781304&amp;post=320&amp;subd=mtjhax&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mtjhax.wordpress.com/2010/11/11/the-health-care-reform-math-game/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ddc001baf1557b859437c18ffec7f86d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mtjhax</media:title>
		</media:content>
	</item>
		<item>
		<title>Action and reaction: event-driven AJAX updates with jQuery</title>
		<link>http://mtjhax.wordpress.com/2010/09/07/event-driven-ajax-updates-with-jquery/</link>
		<comments>http://mtjhax.wordpress.com/2010/09/07/event-driven-ajax-updates-with-jquery/#comments</comments>
		<pubDate>Tue, 07 Sep 2010 03:08:41 +0000</pubDate>
		<dc:creator>mtjhax</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[bind]]></category>
		<category><![CDATA[delegate]]></category>
		<category><![CDATA[event]]></category>
		<category><![CDATA[live]]></category>

		<guid isPermaLink="false">http://mtjhax.wordpress.com/?p=286</guid>
		<description><![CDATA[As I increasingly use AJAX to let users perform actions in a page without navigating away, I find myself constantly having to solve the problem of updating page content that depends on these actions. For example, a user logs in with a popup bubble, then parts of the page that depend on login state must [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mtjhax.wordpress.com&amp;blog=9781304&amp;post=286&amp;subd=mtjhax&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><img src="http://mtjhax.files.wordpress.com/2010/09/newtons_cradle.jpg?w=480" alt="Newton&#039;s Cradle" title="Newton&#039;s Cradle"   class="alignleft size-full wp-image-307" />As I increasingly use AJAX to let users perform actions in a page without navigating away, I find myself constantly having to solve the problem of updating page content that depends on these actions. For example, a user logs in with a popup bubble, then parts of the page that depend on login state must be updated. This is a relatively trivial example and there are many approaches to handling this sort of update.</p>
<p>A straightforward method that is commonly used is to avoid AJAX in these cases&#8211;submit the login form and redirect back to refresh the entire page. While using AJAX sparingly is a worthwhile goal, avoiding it entirely doesn&#8217;t always result in the most engaging user experience. Another approach is to hard-code everything that needs to be updated after an action is complete:</p>
<p><pre class="brush: jscript;">
// submit my login form with jQuery .ajax()
$.ajax({ url: login_url, data: login_data, complete: function() {
  // update page contents that depend on login state
  $('#mainmenu').load('mainmenu');
  $('#login_form').fadeOut('slow', function() {$(this).remove()});
  $('.welcome_text').show();
});
</pre></p>
<p>Fine for one or two actions, but this turns into a spaghetti mess pretty quickly in more complicated situations. A better solution is to have some way of registering update callbacks, e.g.:</p>
<p><pre class="brush: jscript;">
$('#mainmenu').updateOnEvents('login', function() {
  $(this).load('mainmenu');
});

$('#login_form').updateOnEvents('login', function() {
  $(this).fadeOut('slow', function() {$(this).remove()});
});

$('.welcome_text').updateOnEvents('login', function(){
  $(this).show();
});

$.ajax({ url: login_url, data: login_data, complete: function() {
  // globally trigger the event 'login' somehow
});
</pre></p>
<p>So the question becomes, how do you globally trigger the event so any element at any level can register a handler? After considering a number of designs involving .live() or .delegate() (so the handler setups would affect both existing elements and new elements added later) I realized that good old .bind() would do the trick.</p>
<p>Solutions involving .live() and .delegate() are tricky because when you use something like <code>$('.foo').live()</code> or <code>$(document).delegate('.foo')</code>, you need to use <code>$('.foo').trigger()</code> for the event to be handled. Calling something higher-level like <code>$(document).trigger()</code> does not invoke the handlers. The trick is to roll your simple .live()-style function similar to the following:</p>
<p><pre class="brush: jscript;">
$.fn.updateOnEvents = function(events, callback) {
  $(document).bind(
    events,
    { selector: $(this).selector, context: $(this).context },
    function(event, trigger_data) {
      $(event.data.selector, event.data.context).each(function(){
        if (typeof callback == 'function') {
          extra_data = callback(event, trigger_data);
        }
      });
    }
  );
};

// example usage
$(document).ready(function() {
  $('.welcome_text').updateOnEvents('login logout', function(event, data){
    $(this).text(data.message).show();
  });

  $(document).trigger('login', { message: &quot;Welcome back!&quot; });
  $(document).trigger('logout', { message: &quot;See you next time.&quot; });
});
</pre></p>
<p>The trick is that when we call <code>$('.foo').updateOnEvent()</code>, the selector string &#8216;.foo&#8217; is saved (and the context, if specified) and are passed to the handler function in event.data. The handler uses the selector and invokes the callback function for each matching element with .each(), so the value of $(this) in your callback is the element itself instead of $(document). Since the selector is evaluated at the time of the callback, any recently-added elements that match are included in the update.</p>
<p>The parameter trigger_data is whatever extra data you pass with the .trigger() call and your callback can take advantage of that data.</p>
<p>Commonly-used patterns can be expressed as a shortcut in the code. For example, in this variant if the callback parameter is a string instead of a function, the code treats the string as an AJAX URL and assumes you want to update the selected elements with .load():</p>
<p><pre class="brush: jscript;">
$.fn.updateOnEvents = function(events, callback) {
  $(document).bind(
    events,
    { selector: $(this).selector, context: $(this).context },
    function(event, trigger_data) {
      if (typeof callback == 'function') {
        $(event.data.selector, event.data.context).each(function(){
          extra_data = callback(event, trigger_data);
        });
      } else if (typeof callback == 'string') {
        $(event.data.selector, event.data.context).load(callback, trigger_data);
        });
      }
    }
  );
};

// slightly absurd example of using AJAX to retrieve a welcome message
$(document).ready(function() {
  $('.welcome_text').updateOnEvents('login logout', '/ajax/welcome_msg');
  $(document).trigger('login', { type: &quot;login&quot; });
  $(document).trigger('logout', { type: &quot;logout&quot; });
});
</pre></p>
<p>In yet another variant where I always want to update the element with AJAX via .load(), instead of passing a callback function to perform the updates, I passed a callback function that returns the parameters for the .load() call &#8212; in this way, the .trigger() function doesn&#8217;t need to know anything about the parameters needed by the update callbacks:</p>
<p><pre class="brush: jscript;">
$.fn.updateOnEvents = function(events, ajax_url, params_callback) {
  $(document).bind(
    events,
    { selector: $(this).selector, context: $(this).context, url: ajax_url },
    function(event) {
      var data = extra_data;
      $(event.data.selector, event.data.context).each(function(){
        // get AJAX request parameters from callback function
        if (typeof params_callback == 'function') {
          data = params_callback(event);
        }
        // convert params to string so .load() always uses GET method
        if (typeof data == 'object') {
          var new_params = &quot;&quot;;
          for (var key in data) {
            if (new_params.length &gt; 0) new_params += &quot;&amp;&quot;;
            new_params += key + &quot;=&quot; + data[key];
          }
          data = new_params;
        }
        // update the element with AJAX
        $(this).load(e.data.ajax_url, data);
      });
    }
  );
};

// another slightly ludicrous usage example
$(document).ready(function() {
  $('.welcome_text').updateOnEvents('login logout', '/ajax/welcome_msg', function(event){
    if (event.type == 'login')
      return { type: &quot;login&quot; };
    else
      return { type: &quot;logout&quot; };
  });
});
</pre></p>
<p>I have to profess that I am not a jQuery god (yet). I am certain that there are improvements that could be made to this function in terms of performance and simplicity, maybe a potential error or two, or a completely better way to approach the problem. I welcome your suggestions, comments, and criticism!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mtjhax.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mtjhax.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mtjhax.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mtjhax.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mtjhax.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mtjhax.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mtjhax.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mtjhax.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mtjhax.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mtjhax.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mtjhax.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mtjhax.wordpress.com/286/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mtjhax.wordpress.com/286/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mtjhax.wordpress.com/286/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mtjhax.wordpress.com&amp;blog=9781304&amp;post=286&amp;subd=mtjhax&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mtjhax.wordpress.com/2010/09/07/event-driven-ajax-updates-with-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ddc001baf1557b859437c18ffec7f86d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mtjhax</media:title>
		</media:content>

		<media:content url="http://mtjhax.files.wordpress.com/2010/09/newtons_cradle.jpg" medium="image">
			<media:title type="html">Newton&#039;s Cradle</media:title>
		</media:content>
	</item>
		<item>
		<title>jQuery fadeIn / fadeOut problem in IE</title>
		<link>http://mtjhax.wordpress.com/2010/05/07/jquery-fadein-fadeout-problem-in-ie/</link>
		<comments>http://mtjhax.wordpress.com/2010/05/07/jquery-fadein-fadeout-problem-in-ie/#comments</comments>
		<pubDate>Fri, 07 May 2010 00:40:02 +0000</pubDate>
		<dc:creator>mtjhax</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[fade]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[problem]]></category>

		<guid isPermaLink="false">http://mtjhax.wordpress.com/?p=282</guid>
		<description><![CDATA[Say you have a series of DIVs displayed side-by-side with the CSS style display:inline, and you want to use jQuery fadeIn and fadeOut to make the appear and disappear. This will not work under IE8, and I assume other versions of IE. To fix it, give your elements style="display:inline-block" instead. Some people have reported that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mtjhax.wordpress.com&amp;blog=9781304&amp;post=282&amp;subd=mtjhax&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Say you have a series of DIVs displayed side-by-side with the CSS style <code>display:inline</code>, and you want to use jQuery fadeIn and fadeOut to make the appear and disappear. This will not work under IE8, and I assume other versions of IE. To fix it, give your elements <code>style="display:inline-block"</code> instead.</p>
<p>Some people have reported that using absolute and relative positioning of elements causes jQuery animation problems in IE, but I have yet to see positioning cause any problems. I very commonly use a position:relative DIV, then position:absolute elements within the DIV (probably rely on it too much, never claimed to be a CSS designer!)</p>
<p>UPDATE:</p>
<p>I ran into a similar problem under IE8 where a DIV could be hidden and displayed with jQuery .hide() and .show(), and .fadeOut() and .slideUp() would work, but .fadeIn() and .slideDown() would not work at all. The HTML looked something like this:<br />
<code><br />
&lt;div id="page_help"&gt;<br />
&lt;div id="help_toggle"&gt;Click here to hide help&lt;/div&gt;<br />
&lt;div</code><code> id="help_text"</code><code>&gt;This is some help text&lt;/div&gt;<br />
&lt;/div&gt;</code></p>
<p>I had a CSS definition for the help_toggle class setting it to display:inline-block and the fadeIn/slideDown problems started appearing in IE8.  When I set it to display:block the problem went away. Bizarrely, if I inserted an HTML comment between the help_toggle and help_text DIVs, the problem also went away! E.g.:</p>
<p><code>&lt;div id="page_help"&gt;<br />
&lt;div id="help_toggle"&gt;Click here to hide help&lt;/div&gt;<br />
&lt;!-- bizarrely enough, this fixes the jquery fadein problem --&gt;<br />
&lt;div</code><code> id="help_text"</code><code>&gt;This is some help text&lt;/div&gt;<br />
&lt;/div&gt;</code></p>
<p>This is baffling. The only moral to the story I can figure out is that jQuery animations do not appreciate block and inline elements being siblings, and sometimes setting inline-block as the display style is not sufficient to get things working again.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mtjhax.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mtjhax.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mtjhax.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mtjhax.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mtjhax.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mtjhax.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mtjhax.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mtjhax.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mtjhax.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mtjhax.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mtjhax.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mtjhax.wordpress.com/282/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mtjhax.wordpress.com/282/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mtjhax.wordpress.com/282/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mtjhax.wordpress.com&amp;blog=9781304&amp;post=282&amp;subd=mtjhax&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mtjhax.wordpress.com/2010/05/07/jquery-fadein-fadeout-problem-in-ie/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ddc001baf1557b859437c18ffec7f86d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mtjhax</media:title>
		</media:content>
	</item>
		<item>
		<title>Rails named_scope gotchas</title>
		<link>http://mtjhax.wordpress.com/2010/04/29/rails-named_scope-gotchas/</link>
		<comments>http://mtjhax.wordpress.com/2010/04/29/rails-named_scope-gotchas/#comments</comments>
		<pubDate>Thu, 29 Apr 2010 20:06:28 +0000</pubDate>
		<dc:creator>mtjhax</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[named_scope]]></category>

		<guid isPermaLink="false">http://mtjhax.wordpress.com/?p=258</guid>
		<description><![CDATA[There are two terrible gotchas in Rails named_scopes. These two have bitten many a named_scope newbie on the rear (including myself, except that my unit tests caught the problems before they went anywhere but my desktop, w00t for TDD!) #1. Use length instead of size with the results returned by named_scopes. Under certain conditions, particularly [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mtjhax.wordpress.com&amp;blog=9781304&amp;post=258&amp;subd=mtjhax&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There are two terrible gotchas in Rails named_scopes. These two have bitten many a named_scope newbie on the rear (including myself, except that my unit tests caught the problems before they went anywhere but my desktop, w00t for TDD!)</p>
<p><strong>#1. Use length instead of size with the results returned by named_scopes.</strong></p>
<p>Under certain conditions, particularly when using :limit in a named_scope, size and length will return different values. Example:</p>
<p><pre class="brush: ruby;">
class Book &lt; ActiveRecord::Base
  named_scope :top, lambda { |limit| {
    :limit =&gt; limit,
    :order =&gt; 'total_sales DESC'
    }}
end
# imagine we have 10 books with various values for total_sales...
&gt;&gt; Book.top(5).length
=&gt; 5
&gt;&gt; Book.top(5).size
=&gt; 10
# for some reason this only affects named_scopes:
&gt;&gt; Book.find(:all, :limit =&gt; 5).length
=&gt; 5
&gt;&gt; Book.find(:all, :limit =&gt; 5).size
=&gt; 5
# Go figure!
</pre></p>
<p><strong>#2. named_scopes and AR calculations don&#8217;t mix</strong></p>
<p>Named scopes are a joy to use, especially when you chain them. It&#8217;s completely addictive being able to use constructs like:</p>
<p><pre class="brush: ruby;">
topten = Book.fiction.category('vampire').top(10)
</pre><br />
(Hypothetical example, I do <em>not</em> read vampire novels&#8230;).</p>
<p>The arrays returned by named_scope are ActiveRecord arrays and support calculations such as .count and .maximum, so it&#8217;s tempting to want to try something like:<br />
<pre class="brush: ruby;">
max_fiction_price = Book.top(10).maximum(:price)
</pre><br />
Beware! You may not get the results you are looking for &#8212; in my experience, these will not work consistently. The problem is that ActiveRecord generates a query something like the following:<br />
<code><br />
SELECT MAX(price) from books ORDER BY price DESC LIMIT 10;<br />
</code><br />
As far as I can tell in researching it, this is not really valid SQL (at least not according to MySQL). LIMIT happens after everything else&#8211;similar to HAVING&#8211;and only filters the number of output rows that are displayed. Since the MAX() function tells SQL to aggregate the results into a single column, the ORDER and LIMIT clauses are meaningless.</p>
<p>Sometimes this type of statement works for me. I have tried it on SQLite3 and several different versions of MySQL for Linux and Windows. The database sometimes seems to understand that I want to order by price, take the top 10, then calculate the max price. It is entirely possible that in tests where the result appears to be correct, it is actually because the records were randomly ordered in a way that produced the correct result, but purely by chance.</p>
<p>Of course, Rails 3.0 is on the way and there may end up being changes in these behaviors since AR is being rebuilt from the ground up. Whatever the case, avoid mixing conditions and limits, and make sure your unit and functional tests are written to validate the number of results your named_scopes return.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mtjhax.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mtjhax.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mtjhax.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mtjhax.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mtjhax.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mtjhax.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mtjhax.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mtjhax.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mtjhax.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mtjhax.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mtjhax.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mtjhax.wordpress.com/258/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mtjhax.wordpress.com/258/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mtjhax.wordpress.com/258/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mtjhax.wordpress.com&amp;blog=9781304&amp;post=258&amp;subd=mtjhax&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mtjhax.wordpress.com/2010/04/29/rails-named_scope-gotchas/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ddc001baf1557b859437c18ffec7f86d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mtjhax</media:title>
		</media:content>
	</item>
		<item>
		<title>My web site looks better in IE than Firefox</title>
		<link>http://mtjhax.wordpress.com/2010/03/04/my-web-site-looks-better-in-ie-than-firefox/</link>
		<comments>http://mtjhax.wordpress.com/2010/03/04/my-web-site-looks-better-in-ie-than-firefox/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 20:21:09 +0000</pubDate>
		<dc:creator>mtjhax</dc:creator>
				<category><![CDATA[software]]></category>
		<category><![CDATA[anti-aliasing]]></category>
		<category><![CDATA[browser]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[internet]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[scaling]]></category>

		<guid isPermaLink="false">http://mtjhax.wordpress.com/?p=235</guid>
		<description><![CDATA[I noticed something unexpected today. A web site I&#8217;m working on looks better in IE 8 than it does in Firefox 3.6. It&#8217;s not because I did a bad job and the layout is significantly different on the two different browsers&#8211;they are almost identical down to the pixel. It&#8217;s the subtle things like how text, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mtjhax.wordpress.com&amp;blog=9781304&amp;post=235&amp;subd=mtjhax&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I noticed something unexpected today. A web site I&#8217;m working on looks better in IE 8 than it does in Firefox 3.6. It&#8217;s not because I did a bad job and the layout is significantly different on the two different browsers&#8211;they are almost identical down to the pixel. It&#8217;s the subtle things like how text, graphics, and default controls are rendered. Sadly, I can&#8217;t just direct you to the site to check it out for yourself because most of it is a private demo, but the following are some tiny screenshots taken out of context to illustrate my point.</p>
<p><strong>Text Rendering</strong></p>
<p>This obviously comes down to personal preference, but in general I think the anti-aliased fonts used by IE make for a more professional-looking site with less effort, using default fonts. Ironically I prefer un-smoothed fonts on my desktop, maybe because I&#8217;m an old-school DOS/Windows 3 guy. I have read that enabling font-smoothing in Windows will cause Firefox to use the anti-aliased fonts (along with everything else on your system) but regardless of how I change that system setting, the Firefox text does not seem to be smoother and the IE text is the same. I think IE must have its own font rendering engine aside from Windows ClearType. Example:</p>
<p><div id="attachment_237" class="wp-caption alignnone" style="width: 362px"><a href="http://mtjhax.files.wordpress.com/2010/03/compare-ff-text.gif"><img src="http://mtjhax.files.wordpress.com/2010/03/compare-ff-text.gif?w=480" alt="Screen snapshot of text rendered by Firefox" title="Firefox Text"   class="size-full wp-image-237" /></a><p class="wp-caption-text">Firefox text</p></div><br />
<div id="attachment_236" class="wp-caption alignnone" style="width: 362px"><a href="http://mtjhax.files.wordpress.com/2010/03/compare-ie-text.gif"><img src="http://mtjhax.files.wordpress.com/2010/03/compare-ie-text.gif?w=480" alt="Screen snapshot of text rendered by Internet Explorer" title="Internet Explorer Text"   class="size-full wp-image-236" /></a><p class="wp-caption-text">Internet Explorer text</p></div></p>
<p><strong>Default Controls</strong></p>
<p>When using default controls like buttons, the anti-aliased text sometimes gives the buttons a more polished look. Obviously, most web sites these day use custom control with their own graphics to achieve that too-kewl post-Web 2.0 look, but when you&#8217;re tacking together a quick site it&#8217;s nice to rely on good old default controls, at least to get started:</p>
<div id="attachment_238" class="wp-caption alignnone" style="width: 196px"><a href="http://mtjhax.files.wordpress.com/2010/03/compare-ff-btn.gif"><img src="http://mtjhax.files.wordpress.com/2010/03/compare-ff-btn.gif?w=480" alt="Screen snapshot of Firefox default buttons" title="Firefox buttons"   class="size-full wp-image-238" /></a><p class="wp-caption-text">Firefox buttons</p></div>
<div id="attachment_239" class="wp-caption alignnone" style="width: 196px"><a href="http://mtjhax.files.wordpress.com/2010/03/compare-ie-btn.gif"><img src="http://mtjhax.files.wordpress.com/2010/03/compare-ie-btn.gif?w=480" alt="Screen snapshot of Internet Explorer buttons" title="Internet Explorer buttons"   class="size-full wp-image-239" /></a><p class="wp-caption-text">Internet Explorer buttons</p></div>
<p><strong>Image Scaling Quality</strong></p>
<p>The application I am working on allows the user to zoom images. Since the user is very likely to look at the 100% zoom view, we just send the full-size image and use Javascript to resize, letting the browser do the scaling work. While the images look exactly alike at full zoom, I have noticed that in some photos&#8211;mostly dark and grainy ones&#8211;IE&#8217;s graphics scaling is much smoother than Firefox. In the following example image, which is being scaled to 20% of original size by the browser, it almost looks like Firefox converted it to a dithered GIF:</p>
<div id="attachment_241" class="wp-caption alignnone" style="width: 185px"><a href="http://mtjhax.files.wordpress.com/2010/03/compare-ff-img.jpg"><img src="http://mtjhax.files.wordpress.com/2010/03/compare-ff-img.jpg?w=480" alt="Screen snapshot of an image scaled to 20% normal size by Firefox" title="Firefox scaled image"   class="size-full wp-image-241" /></a><p class="wp-caption-text">Firefox scaled image</p></div>
<div id="attachment_240" class="wp-caption alignnone" style="width: 185px"><a href="http://mtjhax.files.wordpress.com/2010/03/compare-ie-img.jpg"><img src="http://mtjhax.files.wordpress.com/2010/03/compare-ie-img.jpg?w=480" alt="Screen snapshot of an image scaled to 20% normal size by Internet Explorer" title="Internet Explorer scaled image"   class="size-full wp-image-240" /></a><p class="wp-caption-text">Internet Explorer scaled image</p></div>
<p>I&#8217;m not likely to change to IE because of these minor features, but it&#8217;s nice to see that there&#8217;s at least one or two good reasons that Microsoft&#8217;s beast is slower at rendering pages than the competition. In case you are curious how Google Chrome stacks up, in a nutshell its text and controls look more like Firefox, and its image scaling must use the same engine as IE because they appear identical. Speed-wise it&#8217;s no contest. Chrome loads and renders the fastest in my unscientific tests, but partly that&#8217;s because there&#8217;s so little going on&#8211;I don&#8217;t have AdBlock and my four other add-ons running in the background under Chrome. Subject for another post.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mtjhax.wordpress.com/235/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mtjhax.wordpress.com/235/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mtjhax.wordpress.com/235/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mtjhax.wordpress.com/235/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mtjhax.wordpress.com/235/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mtjhax.wordpress.com/235/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mtjhax.wordpress.com/235/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mtjhax.wordpress.com/235/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mtjhax.wordpress.com/235/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mtjhax.wordpress.com/235/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mtjhax.wordpress.com/235/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mtjhax.wordpress.com/235/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mtjhax.wordpress.com/235/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mtjhax.wordpress.com/235/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mtjhax.wordpress.com&amp;blog=9781304&amp;post=235&amp;subd=mtjhax&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mtjhax.wordpress.com/2010/03/04/my-web-site-looks-better-in-ie-than-firefox/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ddc001baf1557b859437c18ffec7f86d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mtjhax</media:title>
		</media:content>

		<media:content url="http://mtjhax.files.wordpress.com/2010/03/compare-ff-text.gif" medium="image">
			<media:title type="html">Firefox Text</media:title>
		</media:content>

		<media:content url="http://mtjhax.files.wordpress.com/2010/03/compare-ie-text.gif" medium="image">
			<media:title type="html">Internet Explorer Text</media:title>
		</media:content>

		<media:content url="http://mtjhax.files.wordpress.com/2010/03/compare-ff-btn.gif" medium="image">
			<media:title type="html">Firefox buttons</media:title>
		</media:content>

		<media:content url="http://mtjhax.files.wordpress.com/2010/03/compare-ie-btn.gif" medium="image">
			<media:title type="html">Internet Explorer buttons</media:title>
		</media:content>

		<media:content url="http://mtjhax.files.wordpress.com/2010/03/compare-ff-img.jpg" medium="image">
			<media:title type="html">Firefox scaled image</media:title>
		</media:content>

		<media:content url="http://mtjhax.files.wordpress.com/2010/03/compare-ie-img.jpg" medium="image">
			<media:title type="html">Internet Explorer scaled image</media:title>
		</media:content>
	</item>
		<item>
		<title>Is soft-delete fail?</title>
		<link>http://mtjhax.wordpress.com/2010/03/01/is-soft-delete-fail/</link>
		<comments>http://mtjhax.wordpress.com/2010/03/01/is-soft-delete-fail/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 19:53:32 +0000</pubDate>
		<dc:creator>mtjhax</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[soft delete]]></category>

		<guid isPermaLink="false">http://mtjhax.wordpress.com/?p=229</guid>
		<description><![CDATA[It appears that the Rails community has hit the brakes hard on soft deletion. Is the entire concept of soft-delete fail?<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mtjhax.wordpress.com&amp;blog=9781304&amp;post=229&amp;subd=mtjhax&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.willenns.com/"><img alt="Brakeman by artist Will Enns, willenns.com" src="http://t0.gstatic.com/images?q=tbn:CfWE_3d6H3XkBM:http://www.digitalartokanagan.com/Enns/brakeman5x7.jpg" title="Brakeman by artist Will Enns, willenns.com" class="alignleft" width="93" height="130" /></a><br />
It appears that the Rails community has hit the brakes hard on soft-delete (marking database records as &#8216;deleted&#8217; instead of actually deleting them). Is the entire concept of soft-delete fail? Long before the Rails community embraced soft-delete, there were discussions of its various pros and cons.</p>
<p>I&#8217;m a big believer in the concept of never permanently deleting data. It&#8217;s a pretty easy bandwagon to jump on&#8211;why risk losing data when you can safely tuck it away somewhere or simply mark it deleted, then update all of your database queries to ignore the &#8220;deleted&#8221; rows? As a believer, I&#8217;ve worked quite a bit with soft deletion in both web and stand-alone apps, and it has always been an ongoing maintenance headache. Everyone in the organization who touches the data ends up needing to be aware of the soft-deletion scheme to avoid causing problems&#8211;programmers, DBAs, even support staff. Even if you move deleted records into a separate table, you are still likely to end up with a system where one forgetful programmer can cause headaches for everyone.</p>
<p>For a while it looked like Rails to the rescue, first with technoweenie&#8217;s (Rick Olson) <a href="http://github.com/technoweenie/acts_as_paranoid">acts_as_paranoid</a> which started as an experiment back in 2005, and more recently semanticart&#8217;s (Jeff Chupp) <a href="http://blog.semanticart.com/2009/03/22/using-default-scope-to-recreate-acts-as-paranoid.html">is_paranoid</a>, which cleverly exploited the new ActiveRecord <a href="http://ryandaigle.com/articles/2008/11/18/what-s-new-in-edge-rails-default-scoping">default_scope feature</a> to improve on the concept. Over the years, there has been some criticism of acts_as_paranoid&#8217;s problems and limitations but devotees have worked around them. More recently, some plugins and gems have popped up with alternative schemes such as <a href="http://github.com/ajh/acts_as_soft_deletable">moving deleted records to an archive table</a> instead of marking them as deleted. In the last few months, however, Rails community support for soft deletion seems to be having a meltdown. Jeff of semanticart publicly stated that he is <a href="http://blog.semanticart.com/2009/10/13/killing-is-paranoid.html">killing is_paranoid</a> and rumored that technoweenie is no longer using acts_as_paranoid. A quick search of the net finds a number of very recent articles slamming soft-delete in general (for example, see Luke Francl&#8217;s <a href="http://delicious.com/lukefrancl/softdelete">list of softdelete Bookmarks</a>) and there are an increasing number of Rails add-ons dedicated to the concept of moving deleted records to an archive table. </p>
<p>Ultimately, the argument for killing is_paranoid boiled down to how making soft-delete transparent added one too many layers of Rails magic, shielding the programmer from important data considerations that should have been kept explicit. Soft-delete doesn&#8217;t get off the hook that easily though&#8211;it still presented problems even when wrapped in Rails magic. For example, you can get into trouble if you use unique indexes in your database. Imagine a row is soft-deleted, then you try to create a new row with the same attributes that were supposed to be unique. Also, as Rails has rapidly evolved new and interesting methods of associating and finding data, the soft-delete add-ons required constant updating.</p>
<p>Personally, I&#8217;m starting to think the best answer is to remove all consideration of soft-delete / archive-delete from your apps and handle this externally. There are quite a few tools out there for backing up data in real-time as it is created, using SQL triggers so deleted rows are automatically journaled or moved into an archive, etc. There are also some pretty compelling articles asking an important meta-question, <a href="http://www.udidahan.com/2009/09/01/dont-delete-just-dont/">why are we deleting data at all</a>?</p>
<p>For further reading with some interesting suggestions for alternatives, I recommend <a href="http://railspikes.com/2010/2/26/acts-as-archive">Luke Francl&#8217;s post</a> on Rail Spikes.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mtjhax.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mtjhax.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mtjhax.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mtjhax.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mtjhax.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mtjhax.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mtjhax.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mtjhax.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mtjhax.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mtjhax.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mtjhax.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mtjhax.wordpress.com/229/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mtjhax.wordpress.com/229/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mtjhax.wordpress.com/229/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mtjhax.wordpress.com&amp;blog=9781304&amp;post=229&amp;subd=mtjhax&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mtjhax.wordpress.com/2010/03/01/is-soft-delete-fail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ddc001baf1557b859437c18ffec7f86d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mtjhax</media:title>
		</media:content>

		<media:content url="http://t0.gstatic.com/images?q=tbn:CfWE_3d6H3XkBM:http://www.digitalartokanagan.com/Enns/brakeman5x7.jpg" medium="image">
			<media:title type="html">Brakeman by artist Will Enns, willenns.com</media:title>
		</media:content>
	</item>
		<item>
		<title>If you use Rails, take a few minutes to learn Ruby</title>
		<link>http://mtjhax.wordpress.com/2010/02/09/if-you-use-rails-take-a-few-minutes-to-learn-ruby/</link>
		<comments>http://mtjhax.wordpress.com/2010/02/09/if-you-use-rails-take-a-few-minutes-to-learn-ruby/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 23:34:50 +0000</pubDate>
		<dc:creator>mtjhax</dc:creator>
				<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://mtjhax.wordpress.com/?p=223</guid>
		<description><![CDATA[I&#8217;m sure I&#8217;m not the first person to code three or four complete Ruby on Rails projects before bothering to learn the finer points of Ruby, but after looking at some old code I&#8217;ve gotta say I wish I had spent a day just reading Pickaxe or Why&#8217;s (poignant) Guide before I jumped in with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mtjhax.wordpress.com&amp;blog=9781304&amp;post=223&amp;subd=mtjhax&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m sure I&#8217;m not the first person to code three or four complete Ruby on Rails projects before bothering to learn the finer points of Ruby, but after looking at some old code I&#8217;ve gotta say I wish I had spent a day just reading <a href="http://www.ruby-doc.org/docs/ProgrammingRuby/">Pickaxe</a> or <a href="http://mislav.uniqpath.com/poignant-guide/">Why&#8217;s (poignant) Guide</a> before I jumped in with both feet.</p>
<p>There are dozens of examples of my former Ruby stupidity in virtually any module on my hard disk. They mostly fall into the category of &#8220;doing things the C++ way instead of learning the Ruby way&#8221;. For example:</p>
<p><pre class="brush: ruby;">
  if !my_param.nil? &amp;&amp; my_param.is_a?(Integer) &amp;&amp; my_param &gt;= 0 &amp;&amp; my_param &lt; 10
    # do stuff
  end
</pre></p>
<p>Tsk tsk. Terrible mess. Imagine an entire module full of that. The following is just so much better:</p>
<p><pre class="brush: ruby;">
  if (0..9).include?(my_param)
    # do stuff
  end
</pre></p>
<p>This one method properly deals with nil and non-integer values. Nice!</p>
<p>Of course, I don&#8217;t blame C++ for my cluttered code &#8212; one could easily create their own syntactic sugar in C++ for common tasks like parameter-checking. The point is that Ruby has all these cute tricks already, and you should be making your life easier by using them!</p>
<p>If you happen by this post, I invite you to share your own favorite Ruby tricks.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mtjhax.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mtjhax.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mtjhax.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mtjhax.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mtjhax.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mtjhax.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mtjhax.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mtjhax.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mtjhax.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mtjhax.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mtjhax.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mtjhax.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mtjhax.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mtjhax.wordpress.com/223/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mtjhax.wordpress.com&amp;blog=9781304&amp;post=223&amp;subd=mtjhax&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mtjhax.wordpress.com/2010/02/09/if-you-use-rails-take-a-few-minutes-to-learn-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ddc001baf1557b859437c18ffec7f86d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mtjhax</media:title>
		</media:content>
	</item>
		<item>
		<title>Nginx gzip config and image problems in IE</title>
		<link>http://mtjhax.wordpress.com/2010/02/02/nginx-gzip-config-and-image-problems-in-ie/</link>
		<comments>http://mtjhax.wordpress.com/2010/02/02/nginx-gzip-config-and-image-problems-in-ie/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 22:00:23 +0000</pubDate>
		<dc:creator>mtjhax</dc:creator>
				<category><![CDATA[web hosting]]></category>
		<category><![CDATA[bmp]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[jpg]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[save]]></category>

		<guid isPermaLink="false">http://mtjhax.wordpress.com/?p=218</guid>
		<description><![CDATA[I am running a web site under Nginx and noticed that when you right-click images on that site using IE, even if they are obviously JPEGs you can only save them as bitmaps (.BMP). If you get properties on the image the type comes up as unknown and the last modified date is missing. I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mtjhax.wordpress.com&amp;blog=9781304&amp;post=218&amp;subd=mtjhax&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I am running a web site under Nginx and noticed that when you right-click images on that site using IE, even if they are obviously JPEGs you can only save them as bitmaps (.BMP). If you get properties on the image the type comes up as unknown and the last modified date is missing. I tracked this down to my Nginx gzip configuration, specifically the option <code>gzip_vary on;</code>.</p>
<p>I won&#8217;t discuss what the gzip_vary option is supposed to do, partly because I don&#8217;t know and partly because I don&#8217;t care &#8212; it&#8217;s supposed to help tell browsers that gzip compression is available on the server or somesuch. After a little trial and error I realized that if I disabled this option, IE started treating my images normally. Apparently, if IE sees a HTTP response header that it doesn&#8217;t understand or is in the wrong place, it pitches a hissy fit and skips some of your headers. WTF.</p>
<p>I am using Nginx version 0.7.61. After reading the release notes of Nginx it appears this may have been a bug that is now fixed. One release mentioned that the gzip_vary header was being sent at inappropriate times. I can&#8217;t update that server right now because it&#8217;s on the critical path for a project at the moment and needs to be stable, but I will repost if updating Nginx solves the issue.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mtjhax.wordpress.com/218/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mtjhax.wordpress.com/218/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mtjhax.wordpress.com/218/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mtjhax.wordpress.com/218/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/mtjhax.wordpress.com/218/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/mtjhax.wordpress.com/218/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/mtjhax.wordpress.com/218/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/mtjhax.wordpress.com/218/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mtjhax.wordpress.com/218/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mtjhax.wordpress.com/218/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mtjhax.wordpress.com/218/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mtjhax.wordpress.com/218/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mtjhax.wordpress.com/218/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mtjhax.wordpress.com/218/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mtjhax.wordpress.com&amp;blog=9781304&amp;post=218&amp;subd=mtjhax&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://mtjhax.wordpress.com/2010/02/02/nginx-gzip-config-and-image-problems-in-ie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/ddc001baf1557b859437c18ffec7f86d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mtjhax</media:title>
		</media:content>
	</item>
	</channel>
</rss>
