<?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>{ Code: Impossible } &#187; Uncategorized</title>
	<atom:link href="http://codeimpossible.com/category/uncategorized/feed/" rel="self" type="application/rss+xml" />
	<link>http://codeimpossible.com</link>
	<description>this = HowI.Roll();</description>
	<lastBuildDate>Thu, 29 Jul 2010 02:58:45 +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>Get databases in sql backup plan with sql</title>
		<link>http://codeimpossible.com/2010/07/22/get-databases-in-sql-backup-plan-with-sql/</link>
		<comments>http://codeimpossible.com/2010/07/22/get-databases-in-sql-backup-plan-with-sql/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 03:37:39 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[database-maintenance]]></category>
		<category><![CDATA[SQL]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=891</guid>
		<description><![CDATA[I helped Tamara figure this out the other day and thought others might want to know. She needed to know which databases would be backed up when a given backup plan was executed. The server was a sql 2000 server and the machine she was using didn&#8217;t have enterprise manager installed.

    SELECT
 [...]]]></description>
			<content:encoded><![CDATA[<p>I helped Tamara figure this out the other day and thought others might want to know. She needed to know which databases would be backed up when a given backup plan was executed. The server was a sql 2000 server and the machine she was using didn&#8217;t have enterprise manager installed.</p>
<pre style="display: block; overflow: auto: width: 550px;"><code class="prettyprint">
    SELECT
        *
    FROM
        msdb.dbo.sysdbmaintplans
    LEFT JOIN msdb.dbo.sysdbmaintplan_databases
    ON msdb.dbo.sysdbmaintplan_databases.plan_id = msdb.dbo.sysdbmaintplans.plan_id
    WHERE
        msdb.dbo.sysdbmaintplans.plan_name = 'PUT YOUR PLAN NAME HERE'
</code></pre>
<p>So if anyone out there finds themselves needing to know which databases will be backed up by a given backup plan, and for whatever reason you don&#8217;t have Sql Management Studio or Enterprise Manager then this should work.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2010/07/22/get-databases-in-sql-backup-plan-with-sql/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing Assemblies to GAC with PowerShell</title>
		<link>http://codeimpossible.com/2010/07/21/installing-assemblies-to-gac-with-powershell/</link>
		<comments>http://codeimpossible.com/2010/07/21/installing-assemblies-to-gac-with-powershell/#comments</comments>
		<pubDate>Wed, 21 Jul 2010 19:48:43 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[batch files]]></category>
		<category><![CDATA[powershell]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=886</guid>
		<description><![CDATA[I just finished my first ever powershell script and I&#8217;m pretty proud of it &#8211; even though I did borrow a good portion of it.
We&#8217;re starting a pretty long-term project at work &#8211; it&#8217;s scheduled for a final deliverable date set in July of 2011 &#8211; and with our small(er) dev team I&#8217;m pretty certain [...]]]></description>
			<content:encoded><![CDATA[<p>I just finished my first ever powershell script and I&#8217;m pretty proud of it &#8211; even though <a href="http://weblogs.asp.net/adweigert/archive/2008/10/31/powershell-install-gac-gacutil-for-powershell.aspx">I did borrow a good portion of it</a>.</p>
<p>We&#8217;re starting a pretty long-term project at work &#8211; it&#8217;s scheduled for a final deliverable date set in July of 2011 &#8211; and with our small(er) dev team I&#8217;m pretty certain more hands than my own will be working on this over the course of the entire project.</p>
<p>This new project is going to have a few external dependencies (Moq, StructureMap, possibly MvcTurbine) and I wanted a quicker and friendlier way for a new developer coming into the project to get up-to-speed environment wise. I originally started with a batch file. I know, I know. It&#8217;s my comfort zone. Too many years of not having something like powershell at my finger-tips.</p>
<p>After about 10 minutes of fighting with batch language limitations <a href="http://twitter.com/codeimpossible/statuses/19095201324">I decided to move on and try my hand at using powershell</a> to help automate the developer environment setup.</p>
<p>So I borrowed some code from Adam Weigerts blog to bypass the need for the gacutil (and the .Net Framework SDK, a whopping 100mb download!). Once I had this, I just had to come up with the code to recurse over all the .dll files that are stored in sub-folders within a &#8220;Source Dependencies&#8221; folder. </p>
<p>From concept to finish I think this took me about an hour to come up with, I&#8217;m no programming super soldier so anyone who is doing windows development should be able to throw together a powershell script to automate their common, repetitive and annoying tasks.</p>
<p>The code is included below, I&#8217;ll be adding to it as the project goes on, pushing in some other environment setup features (dev db creation/sync would be the next feature for this). Now that I&#8217;ve taken a swing at PowerShell I&#8217;m really happy with it and I really am sorry it took so long for me to use it.</p>
<p>If you&#8217;re still automating things with Batch files, you&#8217;re missing out. Big.</p>
<pre><code class="prettyprint" style="width:560px; overflow: auto; display: block;">
BEGIN {
    Clear-Host
    $ErrorActionPreference = "Stop"

    if ( $null -eq ([AppDomain]::CurrentDomain.GetAssemblies() |? { $_.FullName -eq "System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" }) ) {
        [System.Reflection.Assembly]::Load("System.EnterpriseServices, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a") | Out-Null
    }

    $publish = New-Object System.EnterpriseServices.Internal.Publish
}

PROCESS {
    $files=get-childitem ".\Source Dependencies" *.dll -rec|where-object {!($_.psiscontainer)}
    foreach( $file in $files ) {
        $assembly = $file.fullname
        if ( -not (Test-Path $assembly -type Leaf) ) {
            throw "The assembly '$assembly' does not exist."
        }

        if ( [System.Reflection.Assembly]::LoadFile( $assembly ).GetName().GetPublicKey().Length -eq 0 ) {
          throw "The assembly '$assembly' must be strongly signed."
        }

        Write-Output "Installing: $assembly"

        $publish.GacInstall( $assembly )
    }
}
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2010/07/21/installing-assemblies-to-gac-with-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Comments stink!</title>
		<link>http://codeimpossible.com/2010/07/16/comments-stink/</link>
		<comments>http://codeimpossible.com/2010/07/16/comments-stink/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 05:28:26 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[code-style]]></category>
		<category><![CDATA[opinionated]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=619</guid>
		<description><![CDATA[I&#8217;ve been thinking about the whole Comments-as-a-code-smell argument for a very long time. When I first heard this idea, I was in the comments are definitely needed side of the argument.
&#8220;Who could hate comments so much that they would label them as a code smell?&#8221; I thought.
Well, I had an epiphany the other day.
I&#8217;ve never [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been thinking about the whole <a href="http://memeagora.blogspot.com/2008/11/comments-code-smell.html" target="_blank">Comments-as-a-code-smell argument</a> for a very long time. When I first heard this idea, I was in the comments are definitely needed side of the argument.</p>
<p><em>&#8220;Who could hate comments so much that they would label them as a code smell?&#8221;</em> I thought.</p>
<p>Well, I had an epiphany the other day.</p>
<p><strong>I&#8217;ve never seen a block of code that actually needed a comment. Ever.</strong></p>
<p>If you have a section of code that feels too complex, instead of adding a comment do any/all of the following and you can, in almost every case, reduce the need for comments by 100%:</p>
<ol>
<li>add a sourcecontrol commit comment</li>
<li>do a simple refactor (<a href="http://www.industriallogic.com/xp/refactoring/composeMethod.html" target="_blank">Compose Method</a> ftw people),</li>
<li>use more descriptive variable/function/class/whatever names.</li>
</ol>
<p>If you do all of these things and the code you are working on still seems too complex, you may have bigger problems with your overall architecture/design and adding a comment isn&#8217;t going to help. In this case it&#8217;s time to go back to the drawing board.</p>
<p>Also, everytime you commit a changeset into sourcecontrol that contains a section of code commented out god kills a kitten. Please think of the kittens.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2010/07/16/comments-stink/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Migrating Asp.net MVC Projects from MVC 1.0 to 2.0</title>
		<link>http://codeimpossible.com/2010/04/06/migrating-asp-net-mvc-projects-from-mvc-1-0-to-2-0/</link>
		<comments>http://codeimpossible.com/2010/04/06/migrating-asp-net-mvc-projects-from-mvc-1-0-to-2-0/#comments</comments>
		<pubDate>Tue, 06 Apr 2010 06:35:35 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=837</guid>
		<description><![CDATA[The Asp.net Mvc 2.0 RTM came out last month and a lot of people are converting their projects over. If you&#8217;re just starting to manually move your projects over then stop what you are doing, download and run the Mvc Converter. It will save you eons of time and frustration.
If you are like me, however, [...]]]></description>
			<content:encoded><![CDATA[<p>The<a href="http://haacked.com/archive/2010/03/11/aspnet-mvc2-released.aspx" target="_blank"> Asp.net Mvc 2.0 RTM came out last month</a> and a lot of people are converting their projects over. If you&#8217;re just starting to manually move your projects over then stop what you are doing, <a href="http://weblogs.asp.net/leftslipper/archive/2010/03/10/migrating-asp-net-mvc-1-0-applications-to-asp-net-mvc-2-rtm.aspx" target="_blank">download and run the Mvc Converter</a>. It will save you eons of time and frustration.</p>
<p>If you are like me, however, and started porting your project over manually and are now knee deep in WTFBBQ sauce then follow the steps below and your project should be up and running in no time.</p>
<p>1. Back up your project. Just in case.</p>
<p>2. Open your project file(s) inside your favorite text editor (one with a decent find/replace system). Open the Find &amp; Replace dialog and find <code>"603c0e0b-db56-11dc-be95-000d561079b0"</code>, replacing it with <code>"F85E285D-A4E0-4152-9332-AB1D724D3325"</code>. My project turned up 1 result.</p>
<p>3. Open the Web.Config files in the root of the project and the root of the /Views folder. Open the Find &amp; Replace dialog again, this time searching for <code>"System.Web.Mvc, Version=1.0.0.0"</code> and replacing it with <code>"System.Web.Mvc, Version=2.0.0.0"</code>.</p>
<p>4. Add the following BindingRedirect to the bottom of the root Web.Config, just before the &lt;/Configuration&gt; node.</p>
<pre class="prettyprint"><code>
&lt;runtime&gt;
  &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
    &lt;dependentAssembly&gt;
      &lt;assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/&gt;
      &lt;bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/&gt;
    &lt;/dependentAssembly&gt;
  &lt;/assemblyBinding&gt;
&lt;/runtime&gt;
</code></pre>
<p>5. Open the solution in Visual Studio and replace the references to System.Web.Mvc 1.0 with the 2.0 assembly.<br />
6. Finally, and only if you really need them, open a new MVC 2.0 project and copy all the files in the /Scripts folder to your project. </p>
<p>Enjoy your freshly migrated project!</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2010/04/06/migrating-asp-net-mvc-projects-from-mvc-1-0-to-2-0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PAX East in Pictures</title>
		<link>http://codeimpossible.com/2010/04/02/pax-east-in-pictures/</link>
		<comments>http://codeimpossible.com/2010/04/02/pax-east-in-pictures/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 03:26:39 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[conferences]]></category>
		<category><![CDATA[Gaming]]></category>
		<category><![CDATA[Photos]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=816</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[
<a href='http://codeimpossible.com/2010/04/02/pax-east-in-pictures/dsc03919/' title='The rockband stage on the second floor was the place to be from noon to 1pm. These guys were one of the better rockband bands to take the stage on saturday.'><img width="150" height="150" src="http://codeimpossible.com/wp-content/uploads/2010/04/DSC03919-150x150.jpg" class="attachment-thumbnail" alt="" title="The rockband stage on the second floor was the place to be from noon to 1pm. These guys were one of the better rockband bands to take the stage on saturday." /></a>
<a href='http://codeimpossible.com/2010/04/02/pax-east-in-pictures/dsc03917/' title='He struck tons of crazy poses but I only managed to get this one of him alone.'><img width="150" height="150" src="http://codeimpossible.com/wp-content/uploads/2010/04/DSC03917-150x150.jpg" class="attachment-thumbnail" alt="" title="He struck tons of crazy poses but I only managed to get this one of him alone." /></a>
<a href='http://codeimpossible.com/2010/04/02/pax-east-in-pictures/dsc03915/' title='One of (if not, the) best costumes I saw at PAX.'><img width="150" height="150" src="http://codeimpossible.com/wp-content/uploads/2010/04/DSC03915-150x150.jpg" class="attachment-thumbnail" alt="" title="One of (if not, the) best costumes I saw at PAX." /></a>
<a href='http://codeimpossible.com/2010/04/02/pax-east-in-pictures/dsc03912/' title='I feel bad admitting that I hadn&#039;t played a ColecoVision before attending PAX East.'><img width="150" height="150" src="http://codeimpossible.com/wp-content/uploads/2010/04/DSC03912-150x150.jpg" class="attachment-thumbnail" alt="" title="I feel bad admitting that I hadn&#039;t played a ColecoVision before attending PAX East." /></a>
<a href='http://codeimpossible.com/2010/04/02/pax-east-in-pictures/dsc03909/' title='When I took this picture there were two older guys playing the Atari 2600, they were laughing, joking, pushing each other out of the way like a couple of kids. It was awesome.'><img width="150" height="150" src="http://codeimpossible.com/wp-content/uploads/2010/04/DSC03909-150x150.jpg" class="attachment-thumbnail" alt="" title="When I took this picture there were two older guys playing the Atari 2600, they were laughing, joking, pushing each other out of the way like a couple of kids. It was awesome." /></a>
<a href='http://codeimpossible.com/2010/04/02/pax-east-in-pictures/dsc03904/' title='The cosplayers invested some serious time into their costumes. Every one of them blew me away.'><img width="150" height="150" src="http://codeimpossible.com/wp-content/uploads/2010/04/DSC03904-150x150.jpg" class="attachment-thumbnail" alt="" title="The cosplayers invested some serious time into their costumes. Every one of them blew me away." /></a>
<a href='http://codeimpossible.com/2010/04/02/pax-east-in-pictures/dsc03899/' title='Not only did this guy have the bad ass costume but his &quot;wookie yell&quot; was perfect.'><img width="150" height="150" src="http://codeimpossible.com/wp-content/uploads/2010/04/DSC03899-150x150.jpg" class="attachment-thumbnail" alt="" title="Not only did this guy have the bad ass costume but his &quot;wookie yell&quot; was perfect." /></a>
<a href='http://codeimpossible.com/2010/04/02/pax-east-in-pictures/dsc03896/' title='The family that kills zombies together...'><img width="150" height="150" src="http://codeimpossible.com/wp-content/uploads/2010/04/DSC03896-150x150.jpg" class="attachment-thumbnail" alt="" title="The family that kills zombies together..." /></a>
<a href='http://codeimpossible.com/2010/04/02/pax-east-in-pictures/dsc03885/' title='Sega released the 3D (using a periscope style viewer and LCD shutters to establish the effect) arcade video game Buck Rogers: Planet of Zoom in 1983. The user controls a spaceship that must destroy enemy ships and avoid obstacles; Buck is never seen, except assumedly in the illustration on the side of the game cabinet, and its only real connections to Buck Rogers are the use of the name and the outer space setting.'><img width="150" height="150" src="http://codeimpossible.com/wp-content/uploads/2010/04/DSC03885-150x150.jpg" class="attachment-thumbnail" alt="" title="Sega released the 3D (using a periscope style viewer and LCD shutters to establish the effect) arcade video game Buck Rogers: Planet of Zoom in 1983. The user controls a spaceship that must destroy enemy ships and avoid obstacles; Buck is never seen, except assumedly in the illustration on the side of the game cabinet, and its only real connections to Buck Rogers are the use of the name and the outer space setting." /></a>
<a href='http://codeimpossible.com/2010/04/02/pax-east-in-pictures/dsc03884/' title='Joust 2: Survival of the Fittest is an arcade game produced by Williams Electronics in 1986 as the sequel to Joust. Although most Williams Electronics games in the 1980s used horizontal video monitors, vertical monitors like those in Pac-Man and Galaga were very common.'><img width="150" height="150" src="http://codeimpossible.com/wp-content/uploads/2010/04/DSC03884-150x150.jpg" class="attachment-thumbnail" alt="" title="Joust 2: Survival of the Fittest is an arcade game produced by Williams Electronics in 1986 as the sequel to Joust. Although most Williams Electronics games in the 1980s used horizontal video monitors, vertical monitors like those in Pac-Man and Galaga were very common." /></a>
<a href='http://codeimpossible.com/2010/04/02/pax-east-in-pictures/dsc03877/' title='The Vectrex is an 8-bit video game console that was developed by Western Technologies/Smith Engineering. It was licensed and distributed first by General Consumer Electric (GCE), and then by Milton Bradley Company after their purchase of GCE.'><img width="150" height="150" src="http://codeimpossible.com/wp-content/uploads/2010/04/DSC03877-150x150.jpg" class="attachment-thumbnail" alt="" title="The Vectrex is an 8-bit video game console that was developed by Western Technologies/Smith Engineering. It was licensed and distributed first by General Consumer Electric (GCE), and then by Milton Bradley Company after their purchase of GCE." /></a>
<a href='http://codeimpossible.com/2010/04/02/pax-east-in-pictures/dsc03869/' title='Just watching this was an experience. Playing it made my mind fold in upon itself.'><img width="150" height="150" src="http://codeimpossible.com/wp-content/uploads/2010/04/DSC03869-150x150.jpg" class="attachment-thumbnail" alt="" title="Just watching this was an experience. Playing it made my mind fold in upon itself." /></a>

]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2010/04/02/pax-east-in-pictures/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lessons Learned</title>
		<link>http://codeimpossible.com/2010/03/10/lessons-learned/</link>
		<comments>http://codeimpossible.com/2010/03/10/lessons-learned/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 15:06:26 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[my-mistakes-let-me-show-you-them]]></category>
		<category><![CDATA[oh-crap]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=812</guid>
		<description><![CDATA[lessons learned this morning:
a) Even if it&#8217;s simple code you &#8220;know&#8221; will work you must test it. No excuses.
b) In programming, nothing happens by &#8220;magic&#8221;. There is a tangible reason that that thing that should be working isn&#8217;t.
c) Don&#8217;t assume something couldn&#8217;t be true simply because it doesn&#8217;t make any sense.
]]></description>
			<content:encoded><![CDATA[<p>lessons learned this morning:<br />
a) Even if it&#8217;s simple code you &#8220;know&#8221; will work you <strong>must</strong> test it. No excuses.<br />
b) In programming, nothing happens by &#8220;magic&#8221;. There is a tangible reason that that thing that should be working isn&#8217;t.<br />
c) Don&#8217;t assume something couldn&#8217;t be true simply because it doesn&#8217;t make any sense.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2010/03/10/lessons-learned/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>W.O.M.M. #6 &#8211; enumerateOver()</title>
		<link>http://codeimpossible.com/2010/03/07/w-o-m-m6-enumerateover/</link>
		<comments>http://codeimpossible.com/2010/03/07/w-o-m-m6-enumerateover/#comments</comments>
		<pubDate>Mon, 08 Mar 2010 04:17:52 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jsoq]]></category>
		<category><![CDATA[Open Source]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=478</guid>
		<description><![CDATA[
I&#8217;ve been focusing more and more on  my port of Ling-to-Objects, Jsoq the past few weeks. It&#8217;s still in really early stages and I&#8217;m not quite sure about it&#8217;s actual usefulness but I&#8217;m learning a lot about JavaScript and having a ton of fun along the way!
Jsoq deals with arrays a lot. About 95% [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" title="works-on-my-machine-starburst" src="http://codeimpossible.com/wp-content/uploads/2009/06/works-on-my-machine-starburst.jpg" alt="works-on-my-machine-starburst" /></p>
<p>I&#8217;ve been focusing more and more on <a href="http://bitbucket.org/codeimpossible/jsoq"> my port of Ling-to-Objects, Jsoq</a> the past few weeks. It&#8217;s still in really early stages and I&#8217;m not quite sure about it&#8217;s actual usefulness but I&#8217;m learning a lot about JavaScript and having a ton of fun along the way!</p>
<p>Jsoq deals with arrays a lot. About 95% of it&#8217;s use cases involve either looping through, altering, or creating arrays. Having a ton of <code>for</code> loops in my code just seems so&#8230; not right. For loops have always seemed dirty to me. They just aren&#8217;t elegant enough. </p>
<p>Here is your normal, average, everyday <code>for</code> loop in Javascript.</p>
<pre class="prettyprint"><code>
var array = "1,2,3,4,5,6,7,8,9,10".split(',');

for(var i = -1, l = array.length; ++i &lt; l;) {
    alert(array[i]);
}
</code></pre>
<p>This works. It&#8217;s reliable and gets the message across. But what if we needed to loop over an array and get all the items that matched a condition? Using a <code>for</code> loop the code could look something like:</p>
<pre class="prettyprint"><code>
var array = [ 1, 2, 3, 4, 5, 1, 2, 3, 4 ];
var results = [];
var condition = function(i) { return i%2 == 0; };

for(var itt = -1, len = array.length; ++itt &lt; len;) {
	if( condition(array[itt]) ) {
		results.push(array[itt]);
	}
}
</code></pre>
<p>This does work, I&#8217;ve written code like this many times before, and while <em>technically</em> there isn&#8217;t anything wrong with it I think there is still room for improvement.</p>
<p>Jsoq is going to be handling arrays all over the place so the solution to this problem <em>needs</em> to be simple.</p>
<p>Here&#8217;s what I need:</p>
<ul>
<li>to loop over an entire collection and perform an action on each item.</li>
<li>If that action produces a result, the item is to be pushed into an array and returned to after the loop is done</li>
<p>.</p>
<li>Also: it needs to be readable, someone else coming along should be able to determine what this thing is doing without too much difficulty. So I had my work cut out for me. </li>
</ul>
<p>A few hours later I had a decent function that I could use to replace a lot of the <code>for</code> loops I had. After some more refactoring I was able to wipe them all out and replace them with calls to <code>enumerateOver()</code>. Here is the latest version from source control:</p>
<pre class="prettyprint"><code>
function enumerateOver(collection, work) {
	var result = [], val = [];

	if (isArray(collection)) {
		try {
			for (var i = -1, l = collection.length; ++i < l;) {
				result = work(collection[i], i);
				if (typeof result !== "undefined" &#038;&#038; result != null) {
					val.push(result);
				}
			}
		}catch (e) {
			if (e != jsoq.$break) throw(e);
		}

		if (val.length > 0) {
			return val;
		}
	}else {
		try {
			val = work(collection, 0);
		}
		catch (e) {
			if (e != jsoq.$break) throw(e);
		}
		if (typeof val !== 'undefined') {
			return val;
		}
	}
	return result == null ? [] : result;
}
</code></pre>
<p>And here is the code to replace the <code>for</code> loops above, re-written to use <code>enumerateOver()</code></p>
<pre class="prettyprint"><code>
var results2 = enumerateOver(array, function(i, c) {
     return i%2 == 0;
});
</code></pre>
<p>So by implmenting this function I was able to come up with a more readable, testable and streamlined codebase. Is this suitable for everyone? Definitely not, but I did it for a few reasons:</p>
<ol>
<li>Like I mentioned before. I&#8217;ve never been at ease with <code>for</code> loops and being able to replace them all with calls to a single function was a huge win for me</li>
<li>The normal use-case didn&#8217;t fit right. I needed to not only iterate over arrays but also return the results of work performed on those items. Doing this the &#8220;regular&#8221; way just wouldn&#8217;t work (see previous reason)</li>
<li>I thought this was a fun problem to solve</li>
</ol>
<p>If you have any feedback, good, bad, or indifferent add a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2010/03/07/w-o-m-m6-enumerateover/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using jQuery on an Iframe</title>
		<link>http://codeimpossible.com/2010/03/04/using-jquery-on-an-iframe/</link>
		<comments>http://codeimpossible.com/2010/03/04/using-jquery-on-an-iframe/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 01:10:39 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[jquery-extensions]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=803</guid>
		<description><![CDATA[The other day I had to alter the stylesheets in a child IFrame when a user selected an item from a drop-down. My first draft was pretty ugly, it ivolved getting the DOM from the child IFrame (by getting it&#8217;s contentWindow or contentDocument property) then getting the  of the DOM and looping over all [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I had to alter the stylesheets in a child IFrame when a user selected an item from a drop-down. My first draft was pretty ugly, it ivolved getting the DOM from the child IFrame (by getting it&#8217;s <a href="http://www-archive.mozilla.org/docs/dom/domref/dom_frame_ref5.html">contentWindow</a> or <a href="http://www-archive.mozilla.org/docs/dom/domref/dom_frame_ref4.html">contentDocument</a> property) then getting the <head> of the DOM and looping over all the child items&#8230; yuck!</p>
<p>I coded up this jQuery extension method which will return a jQuery-wrapped DOM instance for any of the matched IFrames.</p>
<pre class="prettyprint"><code>
(function($) {
    $.fn.extend({
        dom: function () {
            var $this = $(this);
            var getDom = function(o) {
                if( !o || (!o.contentWindow &#038;&#038; !o.contentDocument) ) {
                    return null;
                }

                var doc = (o.contentWindow || o.contentDocument);

                return doc.document || doc;
            };

            var dom = getDom($this[0]);

            return dom === null ? $this : $(dom);
        }
    });
})(jQuery);
</code></pre>
<p>So with this, getting the styles for a child IFrame is as easy as:</p>
<pre class="prettyprint"><code>
$('iframe').dom().find('head link').each(function(index, item) {
    alert(item.href);
});
</code></pre>
<p><em>Unfortunately, this code will only work if your IFrame is hosting content that is on the same domain as its parent.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2010/03/04/using-jquery-on-an-iframe/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Solving &#8220;$(document).ready is not a function&#8221; and other problems</title>
		<link>http://codeimpossible.com/2010/01/13/solving-document-ready-is-not-a-function-and-other-problems/</link>
		<comments>http://codeimpossible.com/2010/01/13/solving-document-ready-is-not-a-function-and-other-problems/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 01:29:29 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code-style]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=767</guid>
		<description><![CDATA[Has this ever happened to you: you&#8217;ve been working on a customer&#8217;s site, writing some really awesome jQuery flashy, fadey, scrolly, interactivey thing, you deploy it, and everything is awesome. The customer rejoices and the customer&#8217;s customers rejoice. Rejoicing is had by everyone. 
And then you get an email one day:

&#8220;Everything is broken. We&#8217;ve kidnapped [...]]]></description>
			<content:encoded><![CDATA[<p>Has this ever happened to you: you&#8217;ve been working on a customer&#8217;s site, writing some really awesome jQuery flashy, fadey, scrolly, interactivey thing, you deploy it, and everything is awesome. The customer rejoices and the customer&#8217;s customers rejoice. Rejoicing is had by everyone. </p>
<p>And then you get an email one day:</p>
<blockquote><p>
&#8220;Everything is broken. We&#8217;ve kidnapped your dog. Fix our site or you&#8217;ll never see Spartacus again.&#8221;</p></blockquote>
<p>And before you have time to wonder why you ever named your dog &#8220;Spartacus&#8221; to begin with (i mean <strong>come. on.</strong>), you&#8217;re off in debug hell. You load the site and see all sorts of weird errors:</p>
<p><code>“$().ready is not a function”</code></p>
<p><code>“$(document) doesn’t support this property or method”</code></p>
<p>Or my personal favorite: </p>
<p><code>“null is null or not an object”</code></p>
<p>You open up FireFox, activate FireBug, load the console, and type “alert($)”, press run, and instead of seeing the expected jQuery function:</p>
<pre class="prettyprint"><code>
function (E, F) {
    return new (o.fn.init)(E, F);
}
</code></pre>
<p>You instead get:</p>
<pre class="prettyprint"><code>
function $(element) {
    if (arguments.length > 1) {
        for (var i = 0, elements = [], length = arguments.length; i < length; i++) {
            elements.push($(arguments[i]));
        }
        return elements;
    }
    if (Object.isString(element)) {
        element = document.getElementById(element);
    }
    return Element.extend(element);
}
</code></pre>
<p>Or even:</p>
<pre class="prettyprint"><code>
function $(id) {
    return document.getElementById(id);
}
</code></pre>
<p><strong>DOH!</strong> Looks like another javascript library has been loaded and has overwritten the <code>$()</code> shortcut for jQuery. Woe is I. Why can’t we all just get along?!? </p>
<p>Well, we can’t stop people from including their favorite javascript libraries, but what we can do is prevent our code from suffering as a result. We’ll need a nice, big beefy, bodyguard to make sure our code isn’t messed with while it’s out clubbing with Prototype, Scriptaculous or even MooTools (who invited <em>him</em>??!?).</p>
<p>Here’s what our bodyguard function will look like</p>
<pre class="prettyprint"><code>
( function($) {

} ) ( jQuery );
</code></pre>
<p>So what this does is call our anonymous function and pass the <code>jQuery</code> object. This will scope ‘$’ to within our little function so we won’t step on anyone else’s toes (and they won’t bump into us while we’re on the dance floor and spill our drink everywhere). Okay, I think I've taken the clubbing metaphor far enough.</p>
<p>Basically this will allow our code to run and use the <code>$</code> shortcut for JQuery as if it were loaded without any of these other libraries on the page. </p>
<p>Here is what the completed code would look like:</p>
<pre class="prettyprint"><code>
&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" type="text/javascript"&gt;
&lt;/script&gt;

&lt;script src="http://ajax.googleapis.com/ajax/libs/prototype/1.6.1.0/prototype.js" type="text/javascript">
&lt;/script&gt;
&lt;script src="http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.3/scriptaculous.js" type="text/javascript">
&lt;/script&gt;

&lt;script type="text/javascript"&gt;
( function($) {
    // we can now rely on $ within the safety of our “bodyguard” function
    $(document).ready( function() { alert("nyah nyah! I’m able to use '$'!!!!");  } );
} ) ( jQuery );

//this will fail
$(document).ready( function() { alert('fail?'); } );
&lt;/script&gt;
</code></pre>
<p>I love using this simple self-calling anonymous function style when working with jQuery because it saves me from typing <code>jQuery()</code>, which really does look a lot more ugly than using the <code>$()</code> shortcut. It also protects my code from any scoping issues and lets the code function normally when <a href="http://docs.jquery.com/Core/jQuery.noConflict">jQuery is put into no conflict mode</a>. </p>
<p>My opinion, if you're doing work in jQuery on sites that you don't control 100%, you should be using this method to protect your code and your clients.</p>
<p><strong>Updated: changed link for jquery to use 1.4.1 at the google CDN (tsk, tsk, tsk I was using the googlecode.com link)</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2010/01/13/solving-document-ready-is-not-a-function-and-other-problems/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>this.year = new Year(); this.year.Resolutions =</title>
		<link>http://codeimpossible.com/2010/01/05/this-year-new-year-this-year-resolutions/</link>
		<comments>http://codeimpossible.com/2010/01/05/this-year-new-year-this-year-resolutions/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 04:04:48 +0000</pubDate>
		<dc:creator>Jared</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://codeimpossible.com/?p=763</guid>
		<description><![CDATA[I&#8217;ve spent the last few days going over what I want to accomplish this year, what I think I definitely could do, what might challenge me and what is just this side of impossible. Whenever I&#8217;ve made my resolutions known in the past its always been in a passing conversation with a friend of family [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent the last few days going over what I want to accomplish this year, what I think I definitely could do, what might challenge me and what is just this side of impossible. Whenever I&#8217;ve made my resolutions known in the past its always been in a passing conversation with a friend of family member. I never wrote them down or tried to keep track of them once the conversation was over so this year I decided to post them publicly to give me that extra bit of motivation, and also I&#8217;ll be able to check back here throughout the year and see how I&#8217;m measuring up.</p>
<p>These are in no particular order.</p>
<p><strong>I need to grow more as a professional.</strong> Last year I went to my first conference (MSDEVCON) and it was a total blast. I met a lot of truly awesome and intelligent people and learned a billion things that I didn&#8217;t know before. After that I attended Stack Overflows Dev Days in Boston and it was the same experience all over again. This year My goal is to start attending more conferences/events (as many as I can afford with time and $$$) to grow myself as a professional.</p>
<p><strong>Make more mistakes. </strong>I made my fair share of mistakes in 2009 and (more importantly) I learned a lot from them: about myself, my skills, and what I am capable of. I&#8217;m addicted. I&#8217;m going to put myself more out in the open and make some more mistakes so I can learn a lot more in 2010.</p>
<p><strong>I need to lose at least 25lbs this year.</strong> I&#8217;ve let myself go over the past few years and it&#8217;s time to take my health more seriously. 25lbs probably doesn&#8217;t sound like a lot and honestly it&#8217;s a lot less than I need to lose but I&#8217;ve never been good at staying fit so hopefully I achieve this goal relatively early and am able to keep the weight off the rest of the year.</p>
<p><strong>No more sugary drinks, especially soda.</strong> I&#8217;m looking at you Mt. Dew. I&#8217;m not sure what happened but between the end of the year work rush and the holiday (fr)antics I&#8217;ve been downing soda like it&#8217;s going out of style. Time for that to end.</p>
<p><strong>Eliminate debt.</strong> This goal is a bit lofty but my goal is to eliminate 80% of all my debts this year. This is going to be a tough one to pull off, what with the recent job change and our new house but it&#8217;s needed.</p>
<p><strong>Finish </strong><em><strong>something</strong></em><strong>. </strong>I started <a href="http://code.google.com/p/myrkat" target="_blank">way</a> <a href="http://code.google.com/p/jsoq" target="_blank">too</a> <a href="http://codeimpossible.com/jsoq" target="_blank">many</a> <a href="http://whatdidijusteat.com" target="_blank">side</a> projects last year, and I finished&#8230; none. Not one project I started in 2009 saw what I would call a 1.0 release. Time to crap or get off the pot. I aim to crap. My goal will be to promote at least 2 of the projects I started in 2009 to a 1.0 release this year.</p>
<p><strong>More play.</strong> Tamara and I didn&#8217;t get a vacation last year and we are dying for some time away. This is going to be tough with all my debt elimination going on but the more debt I get rid of the more I can save.</p>
<p><strong>More sleep.</strong> Tamara reminds me all the time how little sleep I get ( about 4-5 hours a night at most ) and it really started to show during the holidays. I simply ran myself into the ground. Time to recharge and see what I can really do.</p>
]]></content:encoded>
			<wfw:commentRss>http://codeimpossible.com/2010/01/05/this-year-new-year-this-year-resolutions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
