<?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>DontTrustThisGuy.com &#187; code</title>
	<atom:link href="http://donttrustthisguy.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://donttrustthisguy.com</link>
	<description>Why not take my word for it?</description>
	<lastBuildDate>Tue, 09 Mar 2010 09:14:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The Art and Zen of Writing CSS</title>
		<link>http://donttrustthisguy.com/2010/03/07/the-art-and-zen-of-writing-css/</link>
		<comments>http://donttrustthisguy.com/2010/03/07/the-art-and-zen-of-writing-css/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 12:52:22 +0000</pubDate>
		<dc:creator>Jim Jeffers</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[philosophy]]></category>
		<category><![CDATA[productivity]]></category>

		<guid isPermaLink="false">http://donttrustthisguy.com/?p=391</guid>
		<description><![CDATA[I&#8217;ve been writing pure html/css layouts for well over eight years now. While I&#8217;ve found best practices in the form of convention and documentation to be useful. They don&#8217;t prevent some of my CSS nightmares from reoccurring. They merely make them less painful. My solution is to follow guiding principles in the way I write [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been writing pure html/css layouts for well over eight years now. While I&#8217;ve found best practices in the form of convention and documentation to be useful. They don&#8217;t prevent some of my CSS nightmares from reoccurring. They merely make them less painful. My solution is to follow guiding principles in the way I write stylesheets. These principles form a foundation for writing stylesheets that will be easier to work in as the project grows.</p>
<p><span id="more-391"></span></p>
<h3>Lesson One: Only be Specific When You Need to Be.</h3>
<p>There is a hesitation to fully utilize the cascade. Many people who have worked in CSS for a long time tend to utilize very powerful pseudo-selectors to target specific elements. This is all well and good but it also creates a dangerous habit. <strong>We become uncomfortable writing rules that are not highly specific.</strong></p>
<p>This has been a hard lesson learned many times over. My preference has always been to be accurate. I&#8217;d write CSS rules that were really detailed and specific. But this is bad. Specific rules paint you into a corner and make reuse very difficult. <strong>Instead, use the most general rule you can to get the job done and only write rules that are more specific when the situation presents itself.</strong> See the example below:</p>
<p><script src="http://gist.github.com/324170.js?file=be_generic.css"></script></p>
<p>Now it&#8217;s true that the second rule would apply to every paragraph tag on the site. But at first this is fine. Imagine how simple it is to add more specific rules later. As projects grow and styles become inherently more complex by necessity, the situations where we need to become more specific will naturally present themselves. If we are generic from the start we can take advantage of the cascade and overwrite rules with more specific rules when we need to.</p>
<p>To see how bad it can get take a look at these two examples (the third set of rules is an example of adding additional style info with a more specific selector):</p>
<p><script src="http://gist.github.com/324170.js?file=nightmare.css"></script></p>
<p>This seems like a fundamental lesson in CSS. We can write styles that apply to many objects and the more specific rules will take precedence. Most people who write CSS know this. What&#8217;s not usually brought up is the fact that it&#8217;s much safer to avoid the complexity created by writing more specific CSS. There are two laws I would propose in regards to specificity in CSS:</p>
<ul>
<li>The complexity of your stylesheet is directly correlated to how specific your selectors are.</li>
<li>Refactoring CSS selectors to be less specific is exponentially more difficult than simply adding specific rules as situations arise.</li>
</ul>
<h3>Lesson Two: You Must Start Somewhere.</h3>
<p>Whether you work alone or on a team you need to have a starting point in your stylesheet. A starting point is a generic set of rules that defines how we expect our environment to behave. This is generally important when working in CSS but infinitely more important when working on a CSS document with multiple contributors. Everyone needs to be on the same page and having a baseline foundation for our stylesheet is the best trick we have in our arsenal for achieving exactly this.</p>
<p>My starting point is <a href="http://meyerweb.com/eric/tools/css/reset/index.html">Eric Meyer&#8217;s Reset CSS</a>. Unfortunately for your own productivity, it seems that using a reset stylesheet is a controversial subject. Some experienced with CSS consider these tools to be <a href="http://snook.ca/archives/html_and_css/no_css_reset/">unnecessary</a> or <a href="http://meiert.com/en/blog/20080419/reset-style-sheets-are-bad/">just plain bad</a>. But the truth is that we all use them in one form or another. The real problem with reset stylesheets is that they were named &#8220;reset&#8221;. They are not resets but rather they serve as our baselines, our foundations, our intentions for how we want our environment to behave.</p>
<p>The reality is if we don&#8217;t use CSS resets we implement them in a much more difficult manner. We repeat ourselves where we have to throughout the document in order to achieve a standard desired behavior. The best example are margins. Every web browser platform has it&#8217;s own default styles for margins on different elements. There is no way in hell any of us can memorize the variations of these defaults in our minds let alone compensate for them without taking a serious productivity hit.</p>
<p>If you don&#8217;t define your starting point then you inherent every browser&#8217;s own pre-defined starting point. This leads to a much more hostile environment for our work to be deployed. We&#8217;re giving up control of our environment. It&#8217;s much less predictable. It&#8217;s actually very very scary.</p>
<p>That&#8217;s not to say reset CSS files are the holy grail to writing good CSS. Far from it. They can be a pain if you don&#8217;t tailor them. For example, many people don&#8217;t like certain settings used in some reset CSS files. A common example is that the &#8217;strong&#8217; element is no longer bold. But that&#8217;s because the reset is distributed as a pure example. It&#8217;s up to you and your team to change this reset file for your own purposes. If you want strong to be bold adjust the reset. Ultimately, you will develop your own reset.css (though really I think we should call it base.css) over time. The key lessons here are:</p>
<ul>
<li>Base stylesheets grant CSS authors control over their environment.</li>
<li>Base styles are key to creating a shared set of assumptions or expectations amongst multiple contributors.</li>
<li>Base styles do not guarantee cross browser compatibility but rather buy us and our team members predictable outcomes.</li>
</ul>
<h3>Lesson Three: Rely on Specificity Over Order.</h3>
<p>A basic principle in CSS is that if you write two equally specific rules the latter takes precedence. In other words, order matters in your CSS. But this is dangerous. Order only matters if you let it matter &#8211; by writing rules with selectors of equal specificity.</p>
<p>As stylesheets grow in size they become more cumbersome to manage. To remain productive in our files we break them down into sections. Or we separate our rules into entirely separate files.</p>
<p>A reliance on the order our code makes it very brittle or fragile. When we need to incorporate a strategy for organizing our code we can easily disrupt the original order the rules appeared in. This is significant because as I stated earlier it&#8217;s more manageable to write selectors that are less specific and more general. That does not mean you should incorporate the principle of order as a technique for maintaining a stylesheet with generic rules. If you have two rules of equal specificity that conflict with each other then you need to make one of them more specific in the interest of writing a stylesheet that is flexible enough to be reorganized in a structural framework.</p>
<p>Additionally, most of the occurrences in our stylesheets that provide situations where we have rules which overrule each other due to their order of appearance tend to deal with duplicate selectors. These cases are ideal scenarios where our CSS could potentially be refactored.</p>
<p>The key take aways from this point are:</p>
<ul>
<li>Stylesheets that have a strong reliance on order of appearance are inherently more brittle and more susceptible to problems when we attempt to restructure or reorganize our documents.</li>
<li>Rules that are overwritten due to their order of appearance typically  could or should be refactored.</li>
</ul>
<h3>Lesson Four: Be Clear and Expressive.</h3>
<p>You need to be clear on what you expect. You need to be clear on how things should be done and handled in your document. How do you do that in CSS? Simply with commenting. We can provide ample amounts of documentation in our CSS files simply by commenting. We can use comments to:</p>
<ul>
<li>Define best practices.</li>
<li>Denote organizational sections.</li>
<li>Provide references for resources.</li>
</ul>
<p>There are two problems here. The first is that not enough people utilize comments in their stylesheets. The second is that many authors don&#8217;t see the need to. Yes the latter is probably the reason for the former.</p>
<p>Let&#8217;s look into why we might not think commenting or documenting our expectations and best practices in the document may be worthwhile. The first reason is that comments make our CSS file larger in file size. Yes &#8211; this is certainly true but we can easily use YUI compressor or write <a href="http://github.com/jimjeffers/CSS-Reader">simple scripts to automate the process of minifying and removing comments</a> from our production code.</p>
<p>The second reason might be that you&#8217;re the only author touching the stylesheet. This is incredibly short sighted. Always always (always!) plan on someone else touching your stylesheet at some point in time. Chances are you are not the only one who will be working on the project for eternity. In other words &#8211; count on the fact that someone else will eventually be writing code in your stylesheet as well. You may as well make it clear to them as to how they should do it to maintain a consistent stylesheet. Otherwise you may find yourself cleaning up a big mess later when you&#8217;re called back to work on a broken site!</p>
<p>Being expressive is easier said than done though. How do you go about declaring how you expect things to be done? I personally embed my best practices in a short set of directions complete with an example in a comment at the top of all of my stylesheet files. The snippet looks like this:</p>
<p><script src="http://gist.github.com/324170.js?file=best_practices.css"></script></p>
<p>The point here is you can utilize comments to make things very clear in a simple elegant fashion. Just document your CSS as you should be documenting all of your code. Textmate users can benefit from a <a href="http://donttrustthisguy.com/2008/01/05/css-commenting-with-textmate/">CSS commenting bundle</a> I put together a few years ago to quickly document and section apart their stylesheets. What you need to remember regarding expressiveness in your CSS is the following:</p>
<ul>
<li>Utilize comments to define how CSS should be formatted and written for other authors.</li>
<li>Always count on the fact that someone other than you will probably work in this document at some point in time.</li>
<li>Utilize comments to organize your code into sections. Comments can effectively become a navigation system within your CSS document.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://donttrustthisguy.com/2010/03/07/the-art-and-zen-of-writing-css/feed/</wfw:commentRss>
		<slash:comments>43</slash:comments>
		</item>
		<item>
		<title>Getting Started With Encouraged Commentary</title>
		<link>http://donttrustthisguy.com/2009/01/10/encouraged-commentary-getting-started/</link>
		<comments>http://donttrustthisguy.com/2009/01/10/encouraged-commentary-getting-started/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 20:59:06 +0000</pubDate>
		<dc:creator>Jim Jeffers</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[documentation]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jQuery]]></category>

		<guid isPermaLink="false">http://donttrustthisguy.com/?p=315</guid>
		<description><![CDATA[Since interest in this idea has taken off so much I revised the encouraged commentary script so that it would be more flexible for public use. You can toggle on or off pretty much and of the main features.
I&#8217;ve explained in depth how to get it setup on your blog/website. Encouraged commentary will work in [...]]]></description>
			<content:encoded><![CDATA[<p>Since interest in this idea has taken off so much I revised the encouraged commentary script so that it would be more flexible for public use. You can toggle on or off pretty much and of the main features.</p>
<p>I&#8217;ve explained in depth how to get it setup on your blog/website. Encouraged commentary will work in wordpress, textpattern, moveable type, typo, mephisto, drupal, expression engine, etc.. There is no plugin required. You just have to make some minor changes to the HTML markup in your theme or template files. To get started:</p>
<ul>
<li><a href="http://github.com/jimjeffers/encouraged-commentary/tree/master">Grab the source code from github.</a></li>
<li><a href="http://wiki.github.com/jimjeffers/encouraged-commentary">View the Wiki for detailed directions.</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://donttrustthisguy.com/2009/01/10/encouraged-commentary-getting-started/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Easy Flash Debugging on OSX.</title>
		<link>http://donttrustthisguy.com/2008/08/22/easy-flash-debugging-on-osx/</link>
		<comments>http://donttrustthisguy.com/2008/08/22/easy-flash-debugging-on-osx/#comments</comments>
		<pubDate>Sat, 23 Aug 2008 03:31:44 +0000</pubDate>
		<dc:creator>Jim Jeffers</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[techniques]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://donttrustthisguy.com/2008/08/23/easy-flash-debugging-on-osx/</guid>
		<description><![CDATA[I recently took on some contract development for another AS3 project and because I wasn&#8217;t particularly happy with the way I debugged my flash work in the past I decided to come up with a better solution.  Not many traditional flash coders realize that they can view the output from their trace statements on [...]]]></description>
			<content:encoded><![CDATA[<p>I recently took on some contract development for another AS3 project and because I wasn&#8217;t particularly happy with the way I debugged my flash work in the past I decided to come up with a better solution.  Not many traditional flash coders realize that they can view the output from their trace statements on a live compiled SWF.  The way you do that is fairly straightforward.
</p>
<p><span id="more-143"></span></p>
<ul>
<li><a href="http://www.adobe.com/support/flashplayer/downloads.html">Download the Flash Player Debugger version.</a></li>
<li>Create an alias in your profile to tail the flashlog.</li>
</ul>
<h3>Creating an Alias Command</h3>
<p>Once you install the debug player, any movie you open in your browser will output it&#8217;s trace commands to a flashlog.txt file.  This is normally located in the Library directory for your user.  So we&#8217;re going to make an alias to open it quickly in terminal.  If you&#8217;re not familiar with <a href="http://en.wikipedia.org/wiki/Alias_(Unix_shell)">alias commands</a> think of them as shortcuts in terminal.</p>
<p>Let&#8217;s get straight to the meat of it.  First we have to find our flashlog.  By default the flashlog is stored here:<br />
<code>/Users/<strong>[your system username]</strong>/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt'</code></p>
<p>If for whatever reason you aren&#8217;t getting a flashlog you may need to look into taking some <a href="http://blog.flexexamples.com/2007/08/26/debugging-flex-applications-with-mmcfg-and-flashlogtxt/">simple modifications to your mm.cfg file</a>.&#8217; Otherwise you should be ready to make your alias command.</p>
<p>We want to put our alias command in our shell profile so that the shortcut will be available for us automatically when we open up terminal.  To do this launch a new terminal window and type:<br /><code>nano ~/.bash_profile</code></p>
<p>Nano works like a regular text editor, so simply paste the alias command below any existing statements in the document, be sure to replace <strong>your system username</strong> with your actual user name:<br />
<code>alias fl='tail -F /Users/<strong>[your system username]</strong>/Library/Preferences/Macromedia/Flash\ Player/Logs/flashlog.txt'</code></p>
<p>Now that you&#8217;ve done that hit <strong>ctrl-o</strong> to save the changes you&#8217;ve just made to the file and <strong>ctrl-x</strong> to exit nano. Now close the terminal window and open a new terminal.  Type &#8216;fl&#8217; and press enter.  You can now see the live output as any instance of the player writes output to the flashlog. If you want to stop viewing output just hit ctrl-c while you&#8217;re in the terminal window to close the stream.</p>
]]></content:encoded>
			<wfw:commentRss>http://donttrustthisguy.com/2008/08/22/easy-flash-debugging-on-osx/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>I&#8217;m Working on a Product.</title>
		<link>http://donttrustthisguy.com/2008/06/25/im-working-on-a-product/</link>
		<comments>http://donttrustthisguy.com/2008/06/25/im-working-on-a-product/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 00:04:07 +0000</pubDate>
		<dc:creator>Jim Jeffers</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[business]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[thoughts]]></category>

		<guid isPermaLink="false">http://donttrustthisguy.com/2008/06/26/im-working-on-a-product/</guid>
		<description><![CDATA[Earlier this month I started working on a product.  It&#8217;s nothing new.  It&#8217;s pretty basic.  It&#8217;s going to be really cheap.  But I think it will be pretty cool.  I&#8217;ll post screencasts once I finish more of the javascript.  Until then, announcing this is just a tease and motivating [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier this month I started working on a product.  It&#8217;s nothing new.  It&#8217;s pretty basic.  It&#8217;s going to be really cheap.  But I think it will be pretty cool.  I&#8217;ll post screencasts once I finish more of the javascript.  Until then, announcing this is just a tease and motivating factor.  I&#8217;ve said it; now I need to go forward and finish the first version.</p>
]]></content:encoded>
			<wfw:commentRss>http://donttrustthisguy.com/2008/06/25/im-working-on-a-product/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Using Presenters in Rails</title>
		<link>http://donttrustthisguy.com/2008/05/29/using-presenters-in-rails-3/</link>
		<comments>http://donttrustthisguy.com/2008/05/29/using-presenters-in-rails-3/#comments</comments>
		<pubDate>Thu, 29 May 2008 18:31:00 +0000</pubDate>
		<dc:creator>Jim Jeffers</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[presenters]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://donttrustthisguy.com/2008/05/29/using-presenters-in-rails-3/</guid>
		<description><![CDATA[Sitting thrugh my first tutorials session at RailsConf we&#8217;ve come across an interesting discussion about the philosophy of using the &#8216;Presenter Pattern&#8217; to refactor code in your applications controller.

What the presenter initially did was build out a traditional presenter class to extend the model and provide two methods to find possible status and priority objects [...]]]></description>
			<content:encoded><![CDATA[<p>Sitting thrugh my first tutorials session at RailsConf we&#8217;ve come across an interesting discussion about the philosophy of using the <a href="http://blog.jayfields.com/2007/03/rails-presenter-pattern.html">&#8216;Presenter Pattern&#8217;</a> to refactor code in your applications controller.</p>
<p><span id="more-140"></span></p>
<p>What the presenter initially did was build out a traditional presenter class to extend the model and provide two methods to find possible status and priority objects from the database.  This requires the author to delegate class methods from the model that the Presenter class could use.  It also requires us to wrap any instance variable of the child object in the presenter class before we pass it to the view.</p>
<pre name="code" class="ruby">
class StoryPresenter

  def initialize(story)
    @story = story
  end

  delegate  :id, :class, :errors, :to_param, :new_record?,
            :to => :@story

  def possible_statuses
    @statuses = Status.find(:all).map{ |s| [s.name, s.id] }.unshift []
  end

  def possible_priorities
    @priorities = Priority.find(:all).map{ |e| [e.name, e.id] }.unshift []
  end

  def method_missing(name, *args)
    @story.send name, *args
  end

end
</pre>
<p>And then the implementation in the controller looks something like this:</p>
<pre name="code" class="ruby">
def create
  story = @project.stories.build(params[:story])
  respond_to do |format|
    format.js do
      @story = StoryPresenter.new story
      render :action => "stories/new" unless story.save
    end
  end
end
</pre>
<p>A member in the audience suggested that instead of treating the presenter as a traditional presenter object we simply write it as a module.  Then we no longer would have to delegate the methods from the model and instead of wrapping any instance variable of the child class we could just extend it.  The argument for this is clear.  It&#8217;s less code, and it&#8217;s more flexible.</p>
<pre name="code" class="ruby">
module StoryPresenter

  def possible_statuses
    @statuses = Status.find(:all).map{ |s| [s.name, s.id] }.unshift []
  end

  def possible_priorities
    @priorities = Priority.find(:all).map{ |e| [e.name, e.id] }.unshift []
  end

end
</pre>
<p>And then the implementation in the controller looks something like this:</p>
<pre name="code" class="ruby">
def create
  @story = @project.stories.build(params[:story])
  respond_to do |format|
    format.js do
      @story.extend StoryPresenter
      render :action => "stories/new" unless @story.save
    end
  end
end
</pre>
<p>However, the arguments against using a presenter as a mixin are more philosophical.  If we&#8217;re using the presenter pattern we should encapsulate only what we need the view to use explicitly to prevent logic leaking into the view or the controller by other authors.  By treating the Presenter object as a class and explicitly delegating the model methods we do just that.  To utilize further methods of the model we would need to return to the presenter object and extend it there as opposed to just sliding extraneous logic into our controller or view.</p>
]]></content:encoded>
			<wfw:commentRss>http://donttrustthisguy.com/2008/05/29/using-presenters-in-rails-3/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Blogging is not Technology.</title>
		<link>http://donttrustthisguy.com/2008/05/11/blogging-is-not-technology/</link>
		<comments>http://donttrustthisguy.com/2008/05/11/blogging-is-not-technology/#comments</comments>
		<pubDate>Mon, 12 May 2008 06:45:57 +0000</pubDate>
		<dc:creator>Jim Jeffers</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[philosophy]]></category>
		<category><![CDATA[semantics]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://donttrustthisguy.com/2008/05/11/blogging-is-not-technology/</guid>
		<description><![CDATA[Last week I was invited to speak at a local NetSquared meeting out in Tempe.  Presenting on the topic of blogging forced me to take a step back to look at what I&#8217;ve been doing over the past seven years.  I realized all of the technological connotations associated to blogging are irrelevant.  [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I was invited to speak at a local <a href="http://netsquared.meetup.com/12/">NetSquared meeting</a> out in Tempe.  Presenting on the topic of blogging forced me to take a step back to look at what I&#8217;ve been doing over the past seven years.  I realized all of the technological connotations associated to blogging are irrelevant.  Blogging is not about the web, rss feeds, or technology.  That is just a means to an end.  Blogging is about people, it&#8217;s about voices, blogging is all about you. Blogging is a medium for distributing both fact and opinion.  It&#8217;s about discussion and connecting people in a relevant context.  The technology just helps run the show.</p>
<p><span id="more-137"></span></p>
<p>In my presentation I briefly explained the concept of syndication via RSS and Atom &#8211; then touched on a high level overview of what a CMS system is used for.  This was mainly to acknowledge the fact that not that many people are keen on the how or why of RSS.  After demystifying the essential technologies involved, I focused on what blogging is really about.  You can check out my slides below or <a href="http://donttrustthisguy.com/slides/jjeffers-050708-blogging.html">view it in fullscreen</a>.</p>
<p><object width='590' height='450'><param name='movie' value='/slides/slide_viewer.swf?slideshow=/slides/blogging_presentation.swf'><embed src='/slides/slide_viewer.swf?slideshow=/slides/blogging_presentation.swf' width='590' height='450'></embed></param></object></p>
<ul>
<li>Disclaimer: You can click through them to proceed, but you can&#8217;t step back. This is due to a shortcoming in Keynote&#8217;s export to flash functionality. I wrote a viewer tool to load the .swf file created by keynote to preload it, but I could not interact with the movie itself as it&#8217;s an older format of SWF.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://donttrustthisguy.com/2008/05/11/blogging-is-not-technology/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Less Markup Is Better Markup.</title>
		<link>http://donttrustthisguy.com/2008/04/12/less-markup-is-better-markup/</link>
		<comments>http://donttrustthisguy.com/2008/04/12/less-markup-is-better-markup/#comments</comments>
		<pubDate>Sun, 13 Apr 2008 06:30:57 +0000</pubDate>
		<dc:creator>Jim Jeffers</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[philosophy]]></category>
		<category><![CDATA[semantics]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://donttrustthisguy.com/2008/04/13/less-markup-is-better-markup/</guid>
		<description><![CDATA[There is a lot of ambiguity when it comes to writing semantic markup in HTML: to what extent should we markup data?  How semantically detailed do we need to be?  While there is no specific rule of thumb, I will say that the less the better.  When writing markup, be as clean [...]]]></description>
			<content:encoded><![CDATA[<p>There is a lot of ambiguity when it comes to writing semantic markup in HTML: to what extent should we markup data?  How semantically detailed do we need to be?  While there is no specific rule of thumb, I will say that the less the better.  When writing markup, be as clean as possible without losing meaning.  Much like how <a href="http://www.amazon.com/Elements-Style-William-Strunk/dp/0205313426/ref=pd_bbs_2?ie=UTF8&#038;s=books&#038;qid=1208116574&#038;sr=8-2">The Elements of Style</a> emphasizes brevity in writing &#8211; a sentence should use as few words as possible without losing it&#8217;s meaning &#8211; an html document should use as little markup as possible without breaking the context of it&#8217;s content.</p>
<p><span id="more-136"></span></p>
<h3>Use the Minimum Necessary to Communicate Meaning</h3>
<p>Unfortunately, life is not so simple for the HTML author.  Technology binds us to complications that create an environment that is less precise, less absolute, than merely writing a sentence.  But if you can put the pressures we face from design implementation and browser support aside to focus on the basic semantic meaning; you will find that the aforementioned complexity is quite easy to deal with by incorporating small tweaks to your HTML.  Here are two primary points in regards to the over complexity of HTML when thinking in terms of <a href="http://donttrustthisguy.com/2008/04/04/write-html-that-means-something/">implementation as opposed to meaning</a>.</p>
<ul>
<li>Writing HTML based purely on semantic meaning results in much clearer and flexible HTML that is easier to style and maintain.</li>
<li>Complications during implementation are best tackled by adding superfluous markup to correct a problem as it arises rather than preemptively.</li>
</ul>
<h3>Only Add Superfluous Markup After Challenges Arise</h3>
<p>Here is an example.  Let&#8217;s say we have a body of content containing two unsorted lists with four items a piece.  Now let&#8217;s say we want the unsorted lists in this body of content be styled differently from the general rules we have already applied.  If we wanted the absolute most flexibility, we could have preemptively given each list item (&lt;li&gt;) it&#8217;s own class.  That would be a total of eight elements with additional markup.  We could reduce this to only two elements by simply applying a class to the unsorted lists (&lt;ul&gt;) and leaving the list items bare.  Or, provided the body of content is encapsulated in it&#8217;s own HTML element to semantically describe the associations between the content elements, we could give the containing object a class or ID.  Let&#8217;s say this body of content is the secondary content on the page.  We could give the encapsulating div a class, <strong>thus reducing the amount of marked up elements from eight to one.</strong></p>
<h3>Only Use Containing Elements to Construct Associations</h3>
<p>It&#8217;s far to easy and common to find html documents that have nearly every individual element wrapped in it&#8217;s own division (&lt;div&gt;) but this is a terrible breakdown in semantics.  These excessive containers create meaningless layers of information that add no semantic value to the document.  Elements certainly need to be packaged into other containing elements but only when they need to be associated to each other.</p>
<ul>
<li>There should never be a time when a lone element is enclosed in it&#8217;s own containing element.</li>
<li>If an element is alone in a container &#8211; it should be strong enough to stand on it&#8217;s own and the containing element should be eliminated.</li>
</ul>
<p>Take this blog as an example.  This post contains many headings, paragraphs, and unsorted lists.  It makes sense to enclose the content of this entry into it&#8217;s own division to symbolize that all of these various elements are part of a larger body of content.  A single heading, paragraph, or bullet point in this post could not stand on it&#8217;s own to communicate the message of this article.  Think about that when trying to make sense of when you should or should not apply a containing element.  In other words, when writing a long novel you would not put every single sentence on it&#8217;s own page.  Wrapping every single paragraph, image, and list of  your content into a &lt;div&gt; is not so different.</p>
]]></content:encoded>
			<wfw:commentRss>http://donttrustthisguy.com/2008/04/12/less-markup-is-better-markup/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Write HTML That Means Something</title>
		<link>http://donttrustthisguy.com/2008/04/04/write-html-that-means-something/</link>
		<comments>http://donttrustthisguy.com/2008/04/04/write-html-that-means-something/#comments</comments>
		<pubDate>Sat, 05 Apr 2008 13:52:48 +0000</pubDate>
		<dc:creator>Jim Jeffers</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://donttrustthisguy.com/2008/04/06/write-html-that-means-something-3/</guid>
		<description><![CDATA[HTML is often overlooked in development projects.  Rendering errors and other visual debacles tend to shift a developer&#8217;s focus away from HTML&#8217;s actual purpose: semantics.  It&#8217;s been said before but I feel we still need to emphasize the fact that HTML has nothing to do with the visual presentation of the layout we [...]]]></description>
			<content:encoded><![CDATA[<p>HTML is often overlooked in development projects.  Rendering errors and other visual debacles tend to shift a developer&#8217;s focus away from HTML&#8217;s actual purpose: semantics.  It&#8217;s been said <a href="http://www.transcendingcss.com/">before</a> but I feel we still need to emphasize the fact that HTML has nothing to do with the visual presentation of the layout we are attempting to create whether it be for the web or any other medium.</p>
<p><span id="more-133"></span></p>
<h3>Don&#8217;t Think Like a Designer</h3>
<p>Table based layouts are the greatest hack of all time.  When CSS was young and poorly implemented complex layouts could only be achieved by putting all of our HTML into table elements, and layers of nested table elements to follow.  But this totally contradicted the point of HTML.  The goal of HTML is to provide a clear, well described document.  If you have a list of sections that you&#8217;re reader might be interested in browsing to then those links should be described as just that, a list.  A transcribed dialogue communicated by different people should use a definition list tag. Most importantly, if we have a form with fields we need labels.  What better element to use than a label tag?</p>
<p>All of this sounds remarkably straightforward but if you&#8217;re not thinking like a definer and instead are thinking like a designer then you&#8217;ve gotten you&#8217;re approach to HTML all wrong.  Dead wrong.  Worry about the design later.  Right now the focus is entirely on the content.  How is this content best segmented?  How is it best described?</p>
<h3>Preview Your Work as Basic HTML</h3>
<p>When writing HTML don&#8217;t get tempted to start writing any of the CSS yet. Especially any inline-styles.  There are few times you should say never, but use of inline-styles is something <strong>you should never do</strong>.  As you write your HTML preview it in your browser as only HTML.  No CSS.  Just HTML.  This will help you visualize how your document is viewed naturally by machines and is a true testament to the portability of your document.  Without CSS you&#8217;re document should be well laid out and presented as if it were an outline or a basic one column word doc.  Line lengths, columns, other layout crap &#8211; worry about all of that presentation later.  Just keep your focus on making that plain text document as clear and legible as possible.  Here are some tips for previewing pages:</p>
<ul>
<li>If you have an existing site use firefox and get <a href="http://www.getfirebug.com/">firebug</a> or the <a href="https://addons.mozilla.org/en-US/firefox/addon/60">web developer toolbar</a> to disable your stylesheets.</li>
<li>Run the <a href="http://validator.w3.org/">W3C validator</a> on your page and be sure to check the &#8216;Show Outline&#8217; option to ensure the hierarchy of your content makes sense.</li>
</ul>
<h3>Names Things What They Are &#8211; Not What They Look Like</h3>
<p>Let me introduce you to your new hypothetical friend Joe. We call him Joe because that&#8217;s Joe.  His name isn&#8217;t Brown-haired-middle-aged-guy.  What if Joe died his hair green?  Would his name still make sense?  People don&#8217;t often legally change their names, but they do change their appearance quite often.  So does your HTML, yet a lot of us still use that poor approach to naming items in our HTML markup.  Make sure you name your content for what it is &#8211; not where it goes, or how it looks.  If you have a sidebar don&#8217;t name that div with an ID of &#8217;sidebar&#8217;!  That data might be presented visually as a sidebar but that&#8217;s not what the div actually is.  What&#8217;s inside of that div?  A list of related messages?  Maybe that div shouldn&#8217;t be a div at all.  Maybe it should be an unsorted or ordered list with an id of &#8216;related-messages&#8217;.</p>
<h3>Break the Connection &#8211; Make the Separation in Your Mind</h3>
<p>The key thing to walk away with here is to break your thinking that HTML is the markup that makes your site design.  That is all done entirely external from the HTML in your CSS code.  When you&#8217;re assigning class names, ID&#8217;s, or choosing what HTML element to use to describe something just remember.  This should be about what it means, not what it looks like.</p>
]]></content:encoded>
			<wfw:commentRss>http://donttrustthisguy.com/2008/04/04/write-html-that-means-something/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Utilizing Regular Expressions in AS3</title>
		<link>http://donttrustthisguy.com/2008/02/29/utilizing-regular-expressions-in-as3/</link>
		<comments>http://donttrustthisguy.com/2008/02/29/utilizing-regular-expressions-in-as3/#comments</comments>
		<pubDate>Fri, 29 Feb 2008 16:04:58 +0000</pubDate>
		<dc:creator>Jim Jeffers</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[regular expressions]]></category>

		<guid isPermaLink="false">http://donttrustthisguy.com/2008/03/02/utilizing-regular-expressionsregex-in-as3/</guid>
		<description><![CDATA[Regular Expressions are a powerful tool that you can utilize in many different programming languages.  After throwing together the little twitter widget at the top of this page &#8211; I was informed by Brian Shaler of a major bug that causing it to crash.  So while reworking the code to fix it I [...]]]></description>
			<content:encoded><![CDATA[<p>Regular Expressions are a powerful tool that you can utilize in many different programming languages.  After throwing together the little <a href="http://twitter.com">twitter</a> widget at the top of this page &#8211; I was informed by <a href="http://brianshaler.com/blog/">Brian Shaler</a> of a major bug that causing it to crash.  So while reworking the code to fix it I figured I&#8217;d add some much needed functionality as well.  You see, just grabbing the feed from twitter does not generate html links for you.  You have to parse your feed and wrap any &#8216;@username&#8217; responses, or &#8216;http://addresses&#8217; into actual hyperlinks yourself.  Here&#8217;s how I did it.</p>
<p><span id="more-120"></span></p>
<h3>Finding the @usernames and HTTP Addresses</h3>
<p>So this is where we actually utilize RegExp.  In Flash RegEx works very similar to other programming languages.  You simply define a new variable as a with :RegExp class and then assign it a pattern.  I used two separate patterns, one matches users, the other matches the http addresses.  I won&#8217;t go into detail on explaining the RegEx patterns itself here as that is an entirely different topic.  What I&#8217;m focusing on here is how to implement them in flash.  But just for the heck of it, incase you want to take tese and make them better here are the two regular expression patterns I wrote:</p>
<ul>
<li><strong>&#8216;@usernames&#8217;:</strong> <code>/(\s@+\w*(\s|,|!|\.|\n))/</code></li>
<li><strong>&#8216;http://&#8230;&#8217;:</strong> <code>/[^"|^>](http:\/\/+[\S]*)/</code></li>
</ul>
<p>So here is the actual code I use in the widget above.  The only difference is the &#8216;cur&#8217; variable on the first line passes the current title from the twitter RSS feed instead of the dummy string I&#8217;ve hardcoded:</p>
<pre name="code" class="javascript">
private function dropRSS():void {
	var cur:String = "Hey @sunnythaper, @shalerjump, @jamesarcher! Check this out: http://tinyurl.com/377owu"
	if (cur.substr(0,1) == "@") { 			// Skip response messages as they do not always provide enough context to be stand alone statements.
		_current++;
		dropRSS();
	} else {
		cur = cur+" "; // Append a space at the end so RegEx catches trailing expressions

		var twitterUser:RegExp = /(\s@+\w*(\s|,|!|\.|\n))/;		// "
		var url:RegExp = /[^"|^>](http:\/\/+[\S]*)/;

		while(twitterUser.exec&nbsp;(cur) != null) {
			cur = cur.replace(twitterUser, pointToUser);
		}

		while(url.exec&nbsp;(cur) != null) {
			cur = cur.replace(url, setUrl);
		}

		twit.htmlText = cur;
		TweenLite.from(twit, 2, {ease:Elastic.easeOut, y:"-10", alpha: 0});
		_current++;
	}
}
</pre>
<p>What&#8217;s important to take note of is two things: <strong>1)</strong> I need to loop and execute the pattern onto the string until it no longer finds any matches <strong>2)</strong> I&#8217;m passing a function as the second parameter in the replace method as opposed to an alternate string.</p>
<ul>
<li>This has worked great but fundamentally I think there is a more efficient way of doing this without looping and executing the RegEx so many times.</li>
<li>If you know a better way let me know and I&#8217;ll update this post.</li>
</ul>
<h3>Implementing Changed on Your Matches</h3>
<p>As I said, I&#8217;m passing a function to actual handle the replacement as opposed to just passing a replacement string.  This is because I need to run some processes on the matches to build urls based off of them. Flash lets you reference the matches in the functions as arguments. Here is the code.</p>
<pre name="code" class="java">
	private function pointToUser():String {
		return " &lt;a href=\"http://twitter.com/"+arguments[1].substr(2,arguments[1].length-3)+"\"&gt;"+arguments[1].substr(1,arguments[1].length-2)+"&lt;/a&gt;"+arguments[1].substr(arguments[1].length-1,1);
	}

	private function setUrl():String {
		return " &lt;a href=\""+arguments[1]+"\"&gt;"+arguments[1]+"&lt;/a&gt;";
	}
</pre>
<p>Of course, if the RegEx pattern generated two or three differently matched terms you could reference them as well via arguments[2], arguments[3] etc..  Here you can do whatever you want.  I chose to disect the one argument I was working with through a series of substring routines to trim out unwanted characters in certain parts and then re-insert them outside of the html.</p>
<h3>Adobe LiveDoc References:</h3>
<ul>
<li><a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/String.html#replace()">Adobe Live Docs: Replace Method</a></li>
<li><a href="http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/RegExp.html">Adobe LiveDocs: RegExp Object</a></li>
<li><a href="http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&#038;file=00000112.html">Adobe LiveDocs: Regular Expression Syntax</a></li>
<li><a href="http://homepage.mac.com/roger_jolly/software/index.html#regexhibit">RegExhibit &#8211; RegEx Tool for OSX</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://donttrustthisguy.com/2008/02/29/utilizing-regular-expressions-in-as3/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>Simple AJAX Links With Prototype.js</title>
		<link>http://donttrustthisguy.com/2008/01/07/simple-ajax-links-with-prototypejs/</link>
		<comments>http://donttrustthisguy.com/2008/01/07/simple-ajax-links-with-prototypejs/#comments</comments>
		<pubDate>Tue, 08 Jan 2008 01:25:53 +0000</pubDate>
		<dc:creator>Jim Jeffers</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[prototype]]></category>

		<guid isPermaLink="false">http://donttrustthisguy.com/2008/01/08/simple-ajax-links-with-prototypejs/</guid>
		<description><![CDATA[Getting my head wrapped around Prototype.js has been a difficult process. But today I was faced with the simple challenge of creating links that could load external files into divs embedded onto the page.  Nothing fancy but useful nonetheless.  Here&#8217;s how I did it:


	var DynamicExtensions = {
	    dynamicize: function(element){
	  [...]]]></description>
			<content:encoded><![CDATA[<p>Getting my head wrapped around <a href="http://www.prototypejs.com">Prototype.js</a> has been a difficult process. But today I was faced with the simple challenge of creating links that could load external files into divs embedded onto the page.  Nothing fancy but useful nonetheless.  Here&#8217;s how I did it:</p>
<p><span id="more-103"></span></p>
<pre name="code" class="ruby">
	var DynamicExtensions = {
	    dynamicize: function(element){
	        element.dHref = element.href;
			element.dTarget = element.target;
			element.href = "#"+element.target;
			element.target = "";
			element.dynamic = dynamicallyLoad.bindAsEventListener(element);
			Event.observe(element, 'click', element.dynamic);
			return element;
	    }
	}

	Element.addMethods(DynamicExtensions);

	function dynamicallyLoad(e) {
		element = Event.element(e);
		new Ajax.Updater(element.dTarget, element.dHref, {
			method: 'get',
			onComplete: function() {
				setLinks(element,element.dTarget);
				new Effect.Highlight(element.dTarget, {duration: 1});
			}
		});
	}

	function setLinks(e, target) {
		(target) ? selector = '#'+target+' ' : selector = '';
		$$(selector+'a.dynamic').invoke('dynamicize');
	}

	Event.observe(window, 'load', setLinks);
</pre>
<h3>Download &amp; Demo</h3>
<ul>
<li><a href="/demo/dynamic_links_demo/index.html">View a Demo</a></li>
<li><a href="/demo/dynamic_links_demo/protolinks.zip">Download the source.</a></li>
</ul>
<h3>How You Use It</h3>
<p>I&#8217;m big on javascript that is unobtrusive &#8211;  so other from including the script (along with prototype.js) all you have to do is assign  a class and target to your designated anchor tags.  Here&#8217;s a breakdown:</p>
<ul>
<li>You give the target element an ID in HTML.</li>
<li>You set the target value of the link tag to the ID of the element.</li>
<li>You assign the class of the anchor tag to &#8216;dynamic&#8217;.</li>
</ul>
<p>So the link in the example below would load test.html into the div with the ID of content.</p>
<pre name="code" class="html">
	&lt;div id="content"&gt; This content will be replaced once
	the link below is clicked.&lt;/div&gt;
	&lt;a target="content" href="demo.html" class="dynamic"&gt;Load Demo&lt;/a&gt;
</pre>
<h3>Important Lessons Learned</h3>
<p>I said at the beginning of this post I&#8217;m not really a javascript expert so this was a learning process for me. The greatest challenge for me was understanding how binding works &#8211; it&#8217;s something I&#8217;m still slightly confused on actually.  How to reference functions with callbacks was an additional challenge. Overall I would say there were three main &#8216;gotchas&#8217; that stumped me for a while.</p>
<p><strong>Callbacks need to be functions to call functions:</strong> if you use a callback like &#8216;onComplete&#8217; you can&#8217;t just say &#8216;onComplete: myfunction()&#8217;.  Instead you must do something like &#8216;onComplete: function() { myfunction(); }&#8217;.  If you don&#8217;t the function get&#8217;s executed as the assignment to the callback is interpreted.  I believe I&#8217;m explaining that right.  In my case the effect was rendering immediately when you clicked on the link as opposed to delaying until the new content had loaded.  This was very bad because if the new content contained dynamic links the script couldn&#8217;t bind the event behaviors to them.</p>
<p><strong>Elements need to be extracted from an Event object:</strong> in my dynamicallyLoad function I wanted to refer to the object that triggered the event as &#8216;this&#8217;.  I thought I could because I binded the function to it as an event listener but that&#8217;s where I confused myself.  What you need to do is reference the Event object and then get the element from that.  That is why the first line of the function reads &#8216;element = Event.element(e);&#8217;.</p>
<p>This script is not rocket science, but it is a useful starting place for me in a lot of projects that need to make minor use of AJAX updates on click.  I&#8217;ve already expanded this to be less generic to suit the current project I wrote it for.  I&#8217;ll share with you more basic prototype lessons as I get more chances to utilize it in forthcoming projects.</p>
<ul>
<li><a href="/demo/prototypelinks/protolinks.js">Download the code.</a></li>
</ul>
<p><emote><strong>Note:</strong> I bundled the source with a compressed version of Scriptaculous and Prototype.  You can learn more about these compressed versions of prototype at the <a href="http://groups.google.com/group/prototype-core/files">Google Code project page</a>.</emote></p>
]]></content:encoded>
			<wfw:commentRss>http://donttrustthisguy.com/2008/01/07/simple-ajax-links-with-prototypejs/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
