<?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>dweebd</title>
	<atom:link href="http://www.dweebd.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dweebd.com</link>
	<description>Web Freshness</description>
	<lastBuildDate>Wed, 29 Feb 2012 09:50:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rails View Annotator</title>
		<link>http://www.dweebd.com/ruby/rails-view-annotator/</link>
		<comments>http://www.dweebd.com/ruby/rails-view-annotator/#comments</comments>
		<pubDate>Wed, 29 Feb 2012 09:50:15 +0000</pubDate>
		<dc:creator>duncanbeevers</dc:creator>
				<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.dweebd.com/?p=310</guid>
		<description><![CDATA[A Sea of Views
Ruby on Rails projects tend to generate a large number of view files. In a recent, fairly-young project I found we had nearly 300 different files under app/views. On an older project we had over 1,400. These files are often intertwined, sometimes in non-obvious ways. When it comes time to make a [...]]]></description>
			<content:encoded><![CDATA[<h3>A Sea of Views</h3>
<p>Ruby on Rails projects tend to generate a large number of view files. In a recent, fairly-young project I found we had nearly 300 different files under <tt>app/views</tt>. On an older project we had over 1,400. These files are often intertwined, sometimes in non-obvious ways. When it comes time to make a change to such an application&#8217;s front-end, it can be difficult to locate exactly what file generated the markup seen in the browser.</p>
<h3>Sign-Posts</h3>
<p>To alleviate this pain, I wrote a simple wrapper around <a href="http://api.rubyonrails.org/classes/ActionView/PartialRenderer.html#method-i-render" title="ActionView::PartialRenderer#render">ActionView::PartialRenderer#render</a> that bracketed the method&#8217;s output with html comments indicating which file had been rendered.</p>
<pre>
&lt;!-- begin: app/views/user/_bio.html.haml -->
&lt;div class='bio'>Ed's Bio&lt;/div>
&lt;!-- end: app/views/user/_bio.html.haml -->
</pre>
<h3>Adding Context</h3>
<p>After throwing the code up on github, <a href="https://github.com/hinrik">hinrik</a> pointed out that knowing the file containing the markup in question was only half of the equation. Often the difficulty in working with nested view files is knowing where a view was called from. At his request, I extended my wrapper to indicate the view&#8217;s inclusion point.</p>
<pre>
&lt;!-- begin: app/views/user/_bio.html.haml  (from app/views/user/show.html.haml:4) -->
&lt;div class='bio'>Ed's Bio&lt;/div>
&lt;!-- end: app/views/user/_bio.html.haml  (from app/views/user/show.html.haml:4) -->
</pre>
<h3>Who This Helps</h3>
<p>This was originally written to help me get a quick overview of the views structure of an existing project. I created the code as a gem and added it to the <tt>:development</tt> group. It turned out to be useful for the other developers on the team, but the real winners were designers. The designers who worked on this project also worked on several other projects simultaneously, not all Ruby on Rails. This tool enabled them to zero-in on the spots they needed to adjust without having to have a complete mental map of the project&#8217;s view structure.</p>
<h3>The Code</h3>
<p>rails_view_annotator has been <a href="http://www.rubygems.org/gems/rails_view_annotator">published as a gem</a>, and its source is <a href="https://github.com/duncanbeevers/rails_view_annotator">hosted on github</a>. Installation is as simple as adding <tt>gem 'rails_view_annotator'</tt> to a project&#8217;s Gemfile.</p>
<p>It has also been listed on <a href="https://www.ruby-toolbox.com/projects/rails_view_annotator"></a> under <a href="https://www.ruby-toolbox.com/categories/rails_instrumentation">Rails Instrumentation</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dweebd.com/ruby/rails-view-annotator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hash value mapping</title>
		<link>http://www.dweebd.com/ruby/hash-value-mapping/</link>
		<comments>http://www.dweebd.com/ruby/hash-value-mapping/#comments</comments>
		<pubDate>Thu, 09 Dec 2010 02:54:39 +0000</pubDate>
		<dc:creator>duncanbeevers</dc:creator>
				<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.dweebd.com/?p=284</guid>
		<description><![CDATA[Ever have to map all the keys of a Hash, or Hash-like Ruby object?  For example, you have a Hash mapping keys to the binary contents of several files, and you want to present those file contents as Base64.
Imagine we have a Hash that looks something like this:
pictures_hash = &#123;
  'goblins' =&#62; PICTURE_OF_GOBLINS,
 [...]]]></description>
			<content:encoded><![CDATA[<p>Ever have to map all the keys of a Hash, or Hash-like Ruby object?  For example, you have a Hash mapping keys to the binary contents of several files, and you want to present those file contents as Base64.</p>
<p>Imagine we have a Hash that looks something like this:<br />
<pre class="ruby">pictures_hash = <span class="br0">&#123;</span>
  <span class="st0">'goblins'</span> <span class="sy0">=&gt;</span> PICTURE_OF_GOBLINS,
  <span class="st0">'kittens'</span> <span class="sy0">=&gt;</span> PICTURE_OF_KITTENS
<span class="br0">&#125;</span></pre></p>
<p>If you were just doing this mapping inline, it might look like this:</p>
<p><pre class="ruby donot">pictures_hash.<span class="me1">inject</span><span class="br0">&#40;</span><span class="br0">&#123;</span><span class="br0">&#125;</span><span class="br0">&#41;</span> <span class="kw1">do</span> <span class="sy0">|</span>accumulate, <span class="br0">&#40;</span>key, binary<span class="br0">&#41;</span><span class="sy0">|</span>
  accumulate<span class="br0">&#91;</span>key<span class="br0">&#93;</span> = <span class="kw4">Base64</span>.<span class="me1">encode64</span><span class="br0">&#40;</span>binary<span class="br0">&#41;</span>
  accumulate
<span class="kw1">end</span></pre></p>
<p>Instead of typing out almost-identical code over and over again, here&#8217;s an implementation as a simple block-receiving method on Hash itself.</p>
<p><pre class="ruby"><span class="kw1">class</span> <span class="kw4">Hash</span>
  <span class="kw1">def</span> map_values
    inject<span class="br0">&#40;</span><span class="kw2">self</span>.<span class="me1">dup</span><span class="br0">&#41;</span> <span class="kw1">do</span> <span class="sy0">|</span>a, <span class="br0">&#40;</span>k,v<span class="br0">&#41;</span><span class="sy0">|</span>
      a<span class="br0">&#91;</span>k<span class="br0">&#93;</span> = <span class="kw1">yield</span><span class="br0">&#40;</span>v<span class="br0">&#41;</span>
      a
    <span class="kw1">end</span>
  <span class="kw1">end</span>
<span class="kw1">end</span></pre></p>
<p>Now the code to Base64 encode the file contents becomes this much simpler snippet.</p>
<p><pre class="ruby">pictures_hash.<span class="me1">map_values</span> <span class="kw1">do</span> <span class="sy0">|</span>binary<span class="sy0">|</span>
  <span class="kw4">Base64</span>.<span class="me1">encode64</span><span class="br0">&#40;</span>binary<span class="br0">&#41;</span>
<span class="kw1">end</span></pre></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dweebd.com/ruby/hash-value-mapping/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby RegExp match variables really are local</title>
		<link>http://www.dweebd.com/ruby/ruby-regexp-match-variables-really-are-local/</link>
		<comments>http://www.dweebd.com/ruby/ruby-regexp-match-variables-really-are-local/#comments</comments>
		<pubDate>Fri, 26 Feb 2010 19:18:04 +0000</pubDate>
		<dc:creator>duncanbeevers</dc:creator>
				<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.dweebd.com/?p=275</guid>
		<description><![CDATA[While reading Yehuda Katz&#8217; blog post concerning mental models about Ruby&#8217;s behavior, I was a bit rankled by his reference to implicit locals created by running regular expressions with match clauses.
I was nearly certain that the dollar-sign prefix on the variables ensured the variables were global, but had to verify for myself.
Surprisingly, I found that [...]]]></description>
			<content:encoded><![CDATA[<p>While reading <a href="http://yehudakatz.com/2010/02/25/rubys-implementation-does-not-define-its-semantics/">Yehuda Katz&#8217; blog post</a> concerning mental models about Ruby&#8217;s behavior, I was a bit rankled by his reference to <strong>implicit locals</strong> created by running regular expressions with match clauses.</p>
<p>I was nearly certain that the dollar-sign prefix on the variables ensured the variables were global, but had to verify for myself.</p>
<p>Surprisingly, I found that the matches truly were local.</p>
<p><pre class="ruby"><span class="kw1">class</span> RegGlobalTester
  <span class="kw1">def</span> hello
    <span class="br0">&#91;</span> $<span class="nu0">1</span>, <span class="st0">&quot;hello&quot;</span>.<span class="me1">match</span><span class="br0">&#40;</span><span class="sy0">/</span>h<span class="sy0">/</span><span class="br0">&#41;</span>, goodbye, $<span class="nu0">1</span> <span class="br0">&#93;</span>
  <span class="kw1">end</span>
&nbsp;
  <span class="kw1">def</span> goodbye
    <span class="br0">&#91;</span> $<span class="nu0">1</span>, <span class="st0">&quot;goodbye&quot;</span>.<span class="me1">match</span><span class="br0">&#40;</span><span class="sy0">/</span><span class="br0">&#40;</span>g<span class="br0">&#41;</span><span class="sy0">/</span><span class="br0">&#41;</span>, $<span class="nu0">1</span> <span class="br0">&#93;</span>
  <span class="kw1">end</span>
<span class="kw1">end</span></pre></p>
<p><pre class="bash">RegGlobalTester.new.hello
 =<span class="sy0">&gt;</span> <span class="br0">&#91;</span>nil, <span class="co0">#&lt;MatchData &quot;h&quot;&gt;, [nil, #&lt;MatchData &quot;g&quot; 1:&quot;g&quot;&gt;, &quot;g&quot;], nil]</span></pre></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dweebd.com/ruby/ruby-regexp-match-variables-really-are-local/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Keep your production credentials encrypted, hassle-free</title>
		<link>http://www.dweebd.com/mac-os/keep-your-production-credentials-encrypted-hassle-free/</link>
		<comments>http://www.dweebd.com/mac-os/keep-your-production-credentials-encrypted-hassle-free/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 05:33:19 +0000</pubDate>
		<dc:creator>duncanbeevers</dc:creator>
				<category><![CDATA[mac os]]></category>

		<guid isPermaLink="false">http://www.dweebd.com/?p=260</guid>
		<description><![CDATA[Previously, I demonstrated how to set up an encrypted store in Mac OS, but didn&#8217;t describe why you might want to do such a thing.
Encrypt
Using an encrypted store like this can help keep your company&#8217;s sensitive passwords safe should your computer be compromised.
We use Capistrano to deploy to production servers, and in our deploy.rb cap [...]]]></description>
			<content:encoded><![CDATA[<p>Previously, I demonstrated how to set up an <a href="/mac-os/setting-up-an-encrypted-store-in-mac-os/">encrypted store in Mac OS</a>, but didn&#8217;t describe why you might want to do such a thing.</p>
<h3>Encrypt</h3>
<p>Using an encrypted store like this can help keep your company&#8217;s sensitive passwords safe should your computer be compromised.<br />
We use <a href="http://www.capify.org/index.php/Capistrano">Capistrano</a> to deploy to production servers, and in our <tt>deploy.rb</tt> cap variables are read from environment variables, and then forwarded on to the production machines.</p>
<p><pre class="ruby">set <span class="re3">:live_production_mysql_pass</span>, ENV<span class="br0">&#91;</span><span class="st0">'PROD_MYSQL_PASS'</span><span class="br0">&#93;</span></pre></p>
<p>Now obviously, we don&#8217;t want these sensitive variables set all the time, only when it&#8217;s time to deploy.  To achieve this, we simply execute a shell script, stored on the secure volume, which sets the appropriate variables.</p>
<h3>Store Your Secrets</h3>
<p>When the secure volume is mounted, a custom <tt>.bash_profile</tt> is loaded which bootstraps your original <tt>~/.bash_profile</tt> and adds your secrets to the environment:<br />
<pre class="bash"><span class="kw3">source</span> ~<span class="sy0">/</span>.bash_profile
<span class="kw3">export</span> <span class="re2">PROD_MYSQL_PASS=</span><span class="st0">'top-secret'</span>
&nbsp;
<span class="kw3">echo</span> <span class="st0">&quot;Exported secure environment, please close this terminal when you're through&quot;</span>
<span class="kw3">export</span> <span class="re2">PS1=</span><span class="st0">&quot;SECURE $PS1&quot;</span></pre></p>
<p>When this script is executed, the environment variables within it are set, and a warning to close the terminal is emitted.<br />
In order to automate the steps of mounting the secure volume, launching the interactive shell, and unmounting the volume, we have to use a couple of different tools.</p>
<h3>Mount, Execute, Eject</h3>
<p>The first is <tt>hdid</tt> which mounts a volume by filename.  The output of this command provides both the device file, like <tt>/dev/disk1</tt> and the mount point, like <tt>/Volumes/Vault</tt>.</p>
<p>The mount point is used to construct the path to the custom bash profile which initializes sensitive environment variables in a new interactive shell, launched with a pristine environment.  This results in an isolated terminal with mingled secure and user-specific environment variables and settings.  Additionally, the secure volume remains mounted for the lifespan of this secure session, allowing your deploy to read files like production ssh keys, or any other restricted resource, from this secure location.</p>
<p>Finally, when the interactive terminal exits, <tt>hdiutil</tt> ejects the disk device for the mounted volume.</p>
<h3>Set It Up</h3>
<p>The code to do all of this is stored in a bash function.  Add the following lines to your <tt>~/.bash_profile</tt> or equivalent and set the <tt>VAULT_DMG</tt> variable to the name of your encrypted disk image.</p>
<p><pre class="bash"><span class="co0"># Read Secure Volume credentials for deploy</span>
<span class="re2">VAULT_DMG=</span>~<span class="sy0">/</span>Vault.dmg
<span class="kw1">function</span> sv <span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
    <span class="re2">SECURE_MOUNT_INFO=</span><span class="sy0">`</span>hdid <span class="re1">$VAULT_DMG</span><span class="sy0">`</span>;
    <span class="re2">SECURE_MOUNT_DEVICE=</span><span class="sy0">`</span><span class="kw3">echo</span> -e <span class="re1">$SECURE_MOUNT_INFO</span> <span class="sy0">|</span> <span class="kw2">cut</span> -d <span class="st0">' '</span> -f1<span class="sy0">`</span>;
    <span class="re2">SECURE_MOUNT_PATH=</span><span class="sy0">`</span><span class="kw3">echo</span> -e <span class="re1">$SECURE_MOUNT_INFO</span> <span class="sy0">|</span> <span class="kw2">cut</span> -d <span class="st0">' '</span> -f2<span class="sy0">`</span>;
    bash --init-file <span class="re1">$SECURE_MOUNT_PATH</span><span class="sy0">/</span>.bash_profile;
    hdiutil eject <span class="re1">$SECURE_MOUNT_DEVICE</span> <span class="sy0">&amp;&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null;
    <span class="kw3">unset</span> SECURE_MOUNT_INFO SECURE_MOUNT_PATH SECURE_MOUNT_DEVICE
<span class="br0">&#125;</span></pre></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dweebd.com/mac-os/keep-your-production-credentials-encrypted-hassle-free/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Subdomains in development using ghost</title>
		<link>http://www.dweebd.com/mac-os/subdomains-in-development-using-ghost/</link>
		<comments>http://www.dweebd.com/mac-os/subdomains-in-development-using-ghost/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 00:36:41 +0000</pubDate>
		<dc:creator>duncanbeevers</dc:creator>
				<category><![CDATA[mac os]]></category>

		<guid isPermaLink="false">http://www.dweebd.com/?p=213</guid>
		<description><![CDATA[The Problem
Using subdomains with Rails is kind of a pain.  The only official support for subdomains is as asset hosts, as described in the AssetTagHelper documentation.
Matthew Hollingworth&#8217;s subdomain_routes covers most of the gaps in dealing with subdomains in Rails, including; generating subdomain routes, scoping resources to subdomains, and exposing subdomain information to controllers.
What I [...]]]></description>
			<content:encoded><![CDATA[<h3>The Problem</h3>
<p>Using subdomains with Rails is kind of a pain.  The only official support for subdomains is as asset hosts, <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html">as described in the AssetTagHelper documentation</a>.</p>
<p>Matthew Hollingworth&#8217;s <a href="http://github.com/mholling/subdomain_routes/">subdomain_routes</a> covers most of the gaps in dealing with subdomains in Rails, including; generating subdomain routes, scoping resources to subdomains, and exposing subdomain information to controllers.</p>
<p>What I want to talk about is how I deal with subdomains in a development-environment context.</p>
<h3>Hands off my <tt>/etc/hosts</tt></h3>
<p>Most of the resources I&#8217;ve seen regarding working with domain names in Rails involve manually modifying the system&#8217;s <tt>/etc/hosts</tt> file, though Eloy Duran&#8217;s <a href="http://github.com/alloy/passengerpane">PassengerPane</a> makes it simple for those developing with <a href="http://www.modrails.com/">Phusion Passenger</a>.</p>
<p>Robby Russell <a href="http://robbyonrails.com/articles/2009/01/12/get-to-know-a-gem-ghost">calls out</a> the gem <tt><a href="http://github.com/bjeanes/ghost">ghost</a></tt>, which makes managing custom domains and subdomains drop-dead simple.  The gem provides the ability to map domain names to arbitrary IPs, but in development you probably just want to map everything to the <a href="http://en.wikipedia.org/wiki/Loopback">loopback address</a> <tt>127.0.0.1</tt>.</p>
<h3>Putting it into practice</h3>
<p>I like to have each application manage its own domain-to-ip mappings, so I need to make sure all of the domains the application will use are accessible.  How you go about this is up to you, but here&#8217;s simple example showing how to use <tt>ghost</tt> to manage four <tt>cdn</tt> hosts, the <tt>www</tt> subdomain, and the canonical domain name from <tt>config/environments/development.rb</tt>.</p>
<p><pre class="ruby"><span class="kw1">if</span> hostname = ENV<span class="br0">&#91;</span><span class="st0">'RAILS_HOSTNAME'</span><span class="br0">&#93;</span>
  <span class="kw3">require</span> <span class="st0">'ghost'</span>
  cdn_domain_templates = <span class="br0">&#40;</span><span class="nu0">1</span>..<span class="nu0">4</span><span class="br0">&#41;</span>.<span class="me1">map</span> <span class="br0">&#123;</span> <span class="sy0">|</span>i<span class="sy0">|</span> <span class="st0">'cdn%d.%%s'</span> <span class="sy0">%</span> i <span class="br0">&#125;</span>
  <span class="br0">&#40;</span>cdn_domain_templates <span class="sy0">+</span> <span class="br0">&#91;</span> <span class="st0">'www.%s'</span>, <span class="st0">'%s'</span> <span class="br0">&#93;</span><span class="br0">&#41;</span>.<span class="me1">each</span> <span class="kw1">do</span> <span class="sy0">|</span>template<span class="sy0">|</span>
    Host.<span class="me1">add</span><span class="br0">&#40;</span>template <span class="sy0">%</span> hostname<span class="br0">&#41;</span>
  <span class="kw1">end</span>
<span class="kw1">end</span></pre></p>
<p>After starting your application in development mode, <tt>ghost</tt> will attempt to map these domain names if necessary.  It escalates its permissions via <tt>sudo</tt> so you may be prompted to enter your password.</p>
<p><pre class="bash">$ ghost list
Listing <span class="nu0">6</span> host<span class="br0">&#40;</span>s<span class="br0">&#41;</span>:
      cdn1.devdomain.com -<span class="sy0">&gt;</span> <span class="nu0">127.0</span><span class="nu0">.0</span><span class="nu0">.1</span>
      cdn2.devdomain.com -<span class="sy0">&gt;</span> <span class="nu0">127.0</span><span class="nu0">.0</span><span class="nu0">.1</span>
      cdn3.devdomain.com -<span class="sy0">&gt;</span> <span class="nu0">127.0</span><span class="nu0">.0</span><span class="nu0">.1</span>
      cdn4.devdomain.com -<span class="sy0">&gt;</span> <span class="nu0">127.0</span><span class="nu0">.0</span><span class="nu0">.1</span>
           devdomain.com -<span class="sy0">&gt;</span> <span class="nu0">127.0</span><span class="nu0">.0</span><span class="nu0">.1</span>
       www.devdomain.com -<span class="sy0">&gt;</span> <span class="nu0">127.0</span><span class="nu0">.0</span><span class="nu0">.1</span></pre></p>
<p>I typically leave these hostnames sitting around, but cleaning them up is as simple as issuing the command <tt>sudo ghost empty</tt>.  The advantage to leaving the host entries in place is that the initial security escalation needed to establish the entries is bypassed on subsequent launches of the application.</p>
<h3>Working in Parallels</h3>
<p>If you use <a href="http://www.amazon.com/gp/product/B001K6OEV4?ie=UTF8&#038;tag=duncanbeevers-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=B001K6OEV4">Parallels</a> to run your application through its paces on <a href="http://www.amazon.com/gp/product/B002DHGMK0?ie=UTF8&#038;tag=duncanbeevers-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=B002DHGMK0">Windows</a>, it can be convenient to use the same domain names within the virtual machine and in <a href="http://www.amazon.com/gp/product/B001AMHWP8?ie=UTF8&#038;tag=duncanbeevers-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=B001AMHWP8">OS X</a>.</p>
<p>By default, virtual hosts within Parallels are set up to use Bridged Networking, causing the host to appear as a peer on the same LAN as the Mac on which it&#8217;s running.  This means that in order to reach the Mac, the virtual host needs to know the Mac&#8217;s IP, which may be subject to change.  To insulate yourself from this hassle, you can instead isolate the virtual host on a new subnet.</p>
<p>To do this, first go the Network Preferences in Parallels and enable DHCP for Shared Networking:<br />
<img src="http://www.dweebd.com/wp-content/uploads/2010/01/Parallels-Global-Preferences.png" alt="Parallels Global Preferences" title="Parallels Global Preferences" width="500" class="alignnone size-full wp-image-243" /></p>
<p>Next, configure the virtual host to use Shared Networking:<br />
<img src="http://www.dweebd.com/wp-content/uploads/2010/01/Parallels-Virtual-Machine-Preferences.png" alt="Parallels Virtual Machine Preferences" title="Parallels Virtual Machine Preferences" width="500" class="alignnone size-full wp-image-248" /></p>
<p>Finally, update the virtual host&#8217;s <a href="http://en.wikipedia.org/wiki/Hosts_file">hosts file</a>, located at <tt>%SystemRoot%\system32\drivers\etc\</tt> to map your application&#8217;s domains and subdomains to the IP belonging to the virtual network adapter managed by Parallels.</p>
<p><img src="http://www.dweebd.com/wp-content/uploads/2010/01/Configure-Hosts.png" alt="Configure Hosts" title="Configure Hosts" width="500" class="alignnone size-full wp-image-251" /></p>
<p>Now you should be able to access your application by hostname from the virtual host and can therefore copy and paste URLs between environments.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dweebd.com/mac-os/subdomains-in-development-using-ghost/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript cast to Number</title>
		<link>http://www.dweebd.com/ruby/javascript-cast-to-number/</link>
		<comments>http://www.dweebd.com/ruby/javascript-cast-to-number/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 19:00:39 +0000</pubDate>
		<dc:creator>duncanbeevers</dc:creator>
				<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.dweebd.com/?p=208</guid>
		<description><![CDATA[Another interesting technique I spotted in the gRaphaël code base is the use of a prefixed + used to cast a variable to a numeric type.
var data = &#91; undefined, null, 1, 10.2, new Date&#40;&#41; &#93;;
for &#40;var i = 0, len = data.length; i &#60; len; i++&#41;
  console.log&#40;'cast %o: %o', data&#91;i&#93;, +data&#91;i&#93;&#41;;
If you run [...]]]></description>
			<content:encoded><![CDATA[<p>Another interesting technique I spotted in the <a href="http://g.raphaeljs.com/">gRaphaël</a> code base is the use of a prefixed <tt>+</tt> used to cast a variable to a numeric type.</p>
<p><pre class="javascript"><span class="kw2">var</span> data <span class="sy0">=</span> <span class="br0">&#91;</span> undefined<span class="sy0">,</span> <span class="kw2">null</span><span class="sy0">,</span> <span class="nu0">1</span><span class="sy0">,</span> <span class="nu0">10.2</span><span class="sy0">,</span> <span class="kw2">new</span> Date<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#93;</span><span class="sy0">;</span>
<span class="kw1">for</span> <span class="br0">&#40;</span><span class="kw2">var</span> i <span class="sy0">=</span> <span class="nu0">0</span><span class="sy0">,</span> len <span class="sy0">=</span> data.<span class="me1">length</span><span class="sy0">;</span> i <span class="sy0">&lt;</span> len<span class="sy0">;</span> i<span class="sy0">++</span><span class="br0">&#41;</span>
  console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">'cast %o: %o'</span><span class="sy0">,</span> data<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="sy0">,</span> <span class="sy0">+</span>data<span class="br0">&#91;</span>i<span class="br0">&#93;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></p>
<p>If you run this code, notice how casting <tt>undefined</tt> returns <tt>NaN</tt> which will ripple through your calculations.  However, my favorite thing about this technique is how it handles <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Date">Date</a> objects.  The following examples are equivalent.</p>
<p><pre class="javascript"><span class="kw2">var</span> now <span class="sy0">=</span> <span class="kw2">new</span> Date<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">'now.valueOf: %o'</span><span class="sy0">,</span> now.<span class="me1">valueOf</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
console.<span class="me1">log</span><span class="br0">&#40;</span><span class="st0">'+now: %o'</span><span class="sy0">,</span> <span class="sy0">+</span>now<span class="br0">&#41;</span><span class="sy0">;</span></pre></p>
<p>Nice.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dweebd.com/ruby/javascript-cast-to-number/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>If A Then B</title>
		<link>http://www.dweebd.com/javascript/if-a-then-b/</link>
		<comments>http://www.dweebd.com/javascript/if-a-then-b/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 17:00:23 +0000</pubDate>
		<dc:creator>duncanbeevers</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.dweebd.com/?p=201</guid>
		<description><![CDATA[In hacking on the gRaphaël code base, I came across a recurring pattern syntax pattern I hadn&#8217;t encountered in JavaScript before.
Essentially, instead of using this very common conditional construct:
if &#40;a&#41; b;
The author uses:
!a &#38;&#38; b;
Similarly,
if &#40;a&#41; b; else c;
Is written:
!a &#38;&#38; b; a &#38;&#38; c;
I was curious about the performance difference between the styles, and [...]]]></description>
			<content:encoded><![CDATA[<p>In hacking on the <a href="http://g.raphaeljs.com/">gRaphaël</a> code base, I came across a recurring pattern syntax pattern I hadn&#8217;t encountered in JavaScript before.</p>
<p>Essentially, instead of using this very common conditional construct:<br />
<pre class="javascript"><span class="kw1">if</span> <span class="br0">&#40;</span>a<span class="br0">&#41;</span> b<span class="sy0">;</span></pre></p>
<p><a href="http://dmitry.baranovskiy.com/">The author</a> uses:<br />
<pre class="javascript"><span class="sy0">!</span>a <span class="sy0">&amp;&amp;</span> b<span class="sy0">;</span></pre></p>
<p>Similarly,<br />
<pre class="javascript"><span class="kw1">if</span> <span class="br0">&#40;</span>a<span class="br0">&#41;</span> b<span class="sy0">;</span> <span class="kw1">else</span> c<span class="sy0">;</span></pre></p>
<p>Is written:<br />
<pre class="javascript"><span class="sy0">!</span>a <span class="sy0">&amp;&amp;</span> b<span class="sy0">;</span> a <span class="sy0">&amp;&amp;</span> c<span class="sy0">;</span></pre></p>
<p>I was curious about the performance difference between the styles, and <a href="http://gist.github.com/282944">wrote a benchmark</a> to compare them.</p>
<p>I only tested in <a href="http://nightly.webkit.org/builds/trunk/mac/1">WebKit nightly 53415</a>, but I found that in every case, the if / if-else construct outperformed the pure-logic construct.  The differences in performance are admittedly negligible, so I&#8217;ll be sticking to if-else for readability, and I&#8217;ll accept the performance benefit as a happy side-effect.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dweebd.com/javascript/if-a-then-b/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Cookie Path Handling Inconsistencies</title>
		<link>http://www.dweebd.com/javascript/cookie-path-handling-inconsistencies/</link>
		<comments>http://www.dweebd.com/javascript/cookie-path-handling-inconsistencies/#comments</comments>
		<pubDate>Wed, 02 Sep 2009 21:17:59 +0000</pubDate>
		<dc:creator>duncanbeevers</dc:creator>
				<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.dweebd.com/?p=186</guid>
		<description><![CDATA[Cookies stored with a path option are treated somewhat differently in Internet Explorer than they are in many other browsers.  The issues are especially prevalent in modern web applications with &#8220;clean&#8221; urls.
For example, a cookie stored with a path of /movies/the-wizard-of-speed-and-time is not visible to Internet Explorer users visiting /movies/the-wizard-of-speed-and-time, but is visible to [...]]]></description>
			<content:encoded><![CDATA[<p>Cookies stored with a path option are treated somewhat differently in Internet Explorer than they are in many other browsers.  The issues are especially prevalent in modern web applications with &#8220;clean&#8221; urls.</p>
<p>For example, a cookie stored with a path of <tt>/movies/the-wizard-of-speed-and-time</tt> is <strong>not visible</strong> to Internet Explorer users visiting <a href="#">/movies/the-wizard-of-speed-and-time</a>, but is visible to Safari and to Firefox users.</p>
<p><a href="http://www.amazon.com/gp/product/6303340997?ie=UTF8&#038;tag=duncanbeevers-20&#038;linkCode=as2&#038;camp=1789&#038;creative=9325&#038;creativeASIN=6303340997"><img src="/images/the-wizard-of-speed-and-time.png" alt="The Wizard of Speed and Time" title="The Wizard of Speed and Time" /></a><img src="http://www.assoc-amazon.com/e/ir?t=duncanbeevers-20&#038;l=as2&#038;o=1&#038;a=6303340997" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></p>
<p>To deal with this issue it is necessary to issue the cookie with a path one directory higher than the specific page you&#8217;re looking at.  Additionally, the cookie name needs to be disambiguated from other movie-specific cookies since the path scope <tt>/movies</tt> is no longer exclusive to a single movie.</p>
<p>Also remember, cookie paths are case-sensitive, so your application should either issue a cookie whose path matches the request the user issues, or the user should be redirected to a canonical, normalized url.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dweebd.com/javascript/cookie-path-handling-inconsistencies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Run Safari 3.2.1 alongside Safari 4</title>
		<link>http://www.dweebd.com/mac-os/run-safari-321-alongside-safari-4/</link>
		<comments>http://www.dweebd.com/mac-os/run-safari-321-alongside-safari-4/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 00:08:28 +0000</pubDate>
		<dc:creator>duncanbeevers</dc:creator>
				<category><![CDATA[mac os]]></category>

		<guid isPermaLink="false">http://www.dweebd.com/?p=175</guid>
		<description><![CDATA[It&#8217;s important to be able to test your application across multiple versions of major browsers. Safari&#8217;s use of a system-wide Webkit makes this a little difficult, but fortunately enterprising developers have worked to package up a stand-alone version of Safari 3.2.1.
Download Safari 3.2.1 Stand-Alone.


]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s important to be able to test your application across multiple versions of major browsers. Safari&#8217;s use of a system-wide Webkit makes this a little difficult, but fortunately enterprising developers <a href="http://www.clintandrewhall.com/blog/2009/03/run-safari-3-and-safari-4-beta-on-the-same-mac/#more-63">have worked to package up</a> a stand-alone version of Safari 3.2.1.</p>
<p><a href="http://www.dweebd.com/data/Safari%203.2.1.app.zip">Download Safari 3.2.1 Stand-Alone</a>.<br />
<a href="http://www.dweebd.com/data/Safari%203.2.1.app.zip"><img src="http://www.dweebd.com/images/browser_logos/safari256.png" alt="Safari 3.2.1" title="Safari 3.2.1" /><br />
</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dweebd.com/mac-os/run-safari-321-alongside-safari-4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Day-of-week Predicates</title>
		<link>http://www.dweebd.com/ruby/day-of-week-predicates/</link>
		<comments>http://www.dweebd.com/ruby/day-of-week-predicates/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 21:06:18 +0000</pubDate>
		<dc:creator>duncanbeevers</dc:creator>
				<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.dweebd.com/?p=171</guid>
		<description><![CDATA[When business logic dictates that something only happens on Saturday, this snippet can help keep your code and tests legible.
module DatePredicates
  Date::DAYNAMES.each_with_index do &#124;day_name, i&#124;
    define_method &#34;#{day_name}?&#34; do i == wday end
  end
end
&#160;
class Date
  include DatePredicates
end
Date.today.Tuesday?
=&#62; true
]]></description>
			<content:encoded><![CDATA[<p>When business logic dictates that something <strong>only</strong> happens on Saturday, this snippet can help keep your code and tests legible.</p>
<p><pre class="ruby"><span class="kw1">module</span> DatePredicates
  <span class="re2">Date::DAYNAMES</span>.<span class="me1">each_with_index</span> <span class="kw1">do</span> <span class="sy0">|</span>day_name, i<span class="sy0">|</span>
    define_method <span class="st0">&quot;#{day_name}?&quot;</span> <span class="kw1">do</span> i == wday <span class="kw1">end</span>
  <span class="kw1">end</span>
<span class="kw1">end</span>
&nbsp;
<span class="kw1">class</span> <span class="kw4">Date</span>
  <span class="kw1">include</span> DatePredicates
<span class="kw1">end</span></pre></p>
<p><pre class="bash">Date.today.Tuesday?
=<span class="sy0">&gt;</span> <span class="kw2">true</span></pre></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dweebd.com/ruby/day-of-week-predicates/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.593 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-29 02:50:37 -->

