<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
    <channel>
        <title>Jeff Kunkle - Blogs at Near Infinity</title>


        <link>http://www.nearinfinity.com/blogs/</link>
        <description>Employee Blogs</description>
        <language>en</language>
        <copyright>Copyright 2012</copyright>
        <lastBuildDate>Thu, 26 Jan 2012 15:22:16 -0500</lastBuildDate>
        <generator>http://www.sixapart.com/movabletype/</generator>
        <docs>http://www.rssboard.org/rss-specification</docs>
        
        <item>
            <title>Automatic Code Coverage Switching for Vows.js</title>
            <description><![CDATA[<p>If you've used <a href="http://nodejs.org">Node.js</a> lately you've likely run across <a href="http://vowsjs.org/">Vows</a>, the asynchronous behavior driven development test framework for Node. Vows does a really nice job of forcing you to separate your setup logic from your assertions, but that's not what this post is about.</p>

<p>Vows can generate test coverage reports with its --cover-plain, --cover-html, and --cover-json options. Unfortunately, creating code coverage metrics isn't as straightforward as simply including these options in your call to vows. You need to</p>

<ol>
<li>Pre-instrument your code using <a href="https://github.com/visionmedia/node-jscoverage">node-jscoverage</a>.</li>
<li>Require the instrumented versions of your code from your tests.</li>
</ol>

<p>The first prerequisite is fairly easy to satisfy, although you need to remember to re-run node-jscoverage any time you change the source files you're interested in covering. Setting up a script using something like <a href="https://github.com/balupton/watchr">watchr</a> to re-instrument your files if anything changes might be a good option. Anyway, simply executing the following (assuming you've installed node-jscoverage and added it to your path) from the root of your node project will create the instrumented versions of the files in your lib directory:</p>

<pre class="prettyprint">
node-jscoverage lib lib-cov
</pre>

<p>The second prerequisite is not as straightforward to resolve as you might expect unless you want to generate the code coverage on every test run. Why? Because requiring the instrumented code from your test is not the same as requiring the un-instrumented versions. Consider</p>

<pre class="prettyprint lang-js">
// test/myfile_test.js
var fut = require('../lib/myfile.js'); // regular version
var fut = require('../lib-cov/myfile.js'); // instrumented version
</pre>

<p>Since the statement requiring the file under test is in every test you write, having to change it when you want to run the instrumented or un-instrumented files is, in my opinion, not an option. So, on my current project we wrote the following javascript to to serve as a replacement to requiring your files under test.</p>

<pre class="prettyprint lang-js">
// test/coverage.js
var covererageOn = process.argv.some(function(arg) {
  return /^--cover/.test(arg);  
});

if (covererageOn) {
  console.log('Code coverage on');

  exports.require = function(path) {
    var instrumentedPath = path.replace('/lib', '/lib-cov');

    try {
      require.resolve(instrumentedPath);
      return require(instrumentedPath);
    } catch (e) {
      console.log('Coverage on, but no instrumented file found at ' 
        + instrumentedPath);
      return require(path);
    }
  }
} else {
  console.log('Code coverage off');
  exports.require = require;
}
</pre>

<p>In essence, the script checks the process arguments to see if one of the vows --cover-* arguments were passed and changes its require method to substitute /lib-cov for any /lib references. If none of the coverage arguments are detected it simply requires the file as usual. Since your files under test normally use relative references to other files in your lib directory, they get covered too. Check out the example below to see how you would use the script in a test.</p>

<pre class="prettyprint lang-js">
// test/mytest.js
var vows = require('vows');
var assert = require('assert');
var coverage = require('coverage');
var fileUnderTest = coverage.require('../lib/myfile.js');

vows.describe('your test').addBatch({
    // do some testing
}).export(module);
</pre>
]]></description>
            <link>http://www.nearinfinity.com/blogs/jeff_kunkle/automatic_code_coverage_switch.html</link>
            <guid>http://www.nearinfinity.com/blogs/jeff_kunkle/automatic_code_coverage_switch.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Node</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">javascript</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">node.js</category>
            
            <pubDate>Thu, 26 Jan 2012 15:22:16 -0500</pubDate>
        </item>
        
        <item>
            <title>Parsing pcap Files in Node.js with pcap-parser</title>
            <description><![CDATA[<p>On my current project we've been using <a href="http://nodejs.org">Node.js</a> for an app that does a lot of packet capture and processing. In the past we used <a href="https://github.com/mranney/node_pcap">node-pcap</a> for packet capture but were looking for an easier way to simply parse raw pcap files. It turns out the <a href="http://wiki.wireshark.org/Development/LibpcapFileFormat">pcap file format</a> is pretty simple as was writing a node module to parse it.</p>

<p>The module, called <a href="https://github.com/nearinfinity/node-pcap-parser">pcap-parser</a>, can be used to parse any pcap file or readable pcap stream, such as the piped output of <a href="http://www.tcpdump.org/">tcpdump</a>. As packets are parsed, pcap-parser emits relevant events to which your node program can listen. It's a really simple way to process a theoretically infinite stream of pcap data. The code below shows a basic example of it in action. Please check out the <a href="https://github.com/nearinfinity/node-pcap-parser">project page</a> for more details.</p>

<pre class="prettyprint">
var pcapp = require('pcap-parser');

var parser = new pcapp.Parser('/path/to/file.pcap');
// var parser = new pcapp.Parser(process.stdin);

parser.on('packet', function(packet) {
  console.log(packet.header);
  console.log(packet.data);
});

parser.parse(); // to kick things off
</pre> 
]]></description>
            <link>http://www.nearinfinity.com/blogs/jeff_kunkle/parsing_pcap_files_in_nodejs_w.html</link>
            <guid>http://www.nearinfinity.com/blogs/jeff_kunkle/parsing_pcap_files_in_nodejs_w.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Node</category>
            
            
                <category domain="http://www.sixapart.com/ns/types#tag">javascript</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">node</category>
            
                <category domain="http://www.sixapart.com/ns/types#tag">pcap</category>
            
            <pubDate>Thu, 12 Jan 2012 08:00:00 -0500</pubDate>
        </item>
        
        <item>
            <title>Rails 3 Performance Monitoring with System Metrics</title>
            <description><![CDATA[<p>System Metrics is a new Rails 3 Engine providing a clean web interface to the performance metrics instrumented with <code>ActiveSupport::Notifications</code>. It will collect and display the notifications baked into Rails and any additional custom ones you add using <code>ActiveSupport::Notification#instrument</code>.</p>

<p>System Metrics is not intended to be a replacement for performance monitoring solutions such as New Relic. However, it is especially handy for quickly identifying performance problems in a development environment. It's also a great alternative for private networks disconnected from the Internet.</p>

<p>You can find more information about System Metrics on the <a href="http://nearinfinity.github.com/system-metrics">System Metrics site</a>. Please kick the tires and let us know what you think.</p>

<p><img src="/blogs/2011/08/22/system-metrics/smdetails.png" alt="System Metrics Detail View" title="" /></p>
]]></description>
            <link>http://www.nearinfinity.com/blogs/jeff_kunkle/rails_3_performance_monitoring.html</link>
            <guid>http://www.nearinfinity.com/blogs/jeff_kunkle/rails_3_performance_monitoring.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Ruby</category>
            
            
            <pubDate>Mon, 22 Aug 2011 09:42:18 -0500</pubDate>
        </item>
        
        <item>
            <title>Are You Really Done?</title>
            <description><![CDATA[<p>People often have a hard time determining if they're done with a
software development task. It's a great idea to sit down with your team
and together decide what you're going to consider as criteria for
declaring a task done. If you haven't done that yet, here's one
question you can ask yourself to help decide if you're done.</p>

<blockquote>
  <p>Is there any reason I'll need to think about this code again in the
  near future?</p>
</blockquote>

<p>If you didn't quite implement all the unit tests you think you should
have, the answer is yes and <strong>you're not done</strong>. If you cut a corner or
two to squeeze it in before the end of the iteration, the answer is yes
and <strong>you're not done</strong>. If you're uncomfortable with the implementation
and would like to refactor it, the answer is yes and <strong>you're not done</strong>.
If there are a few details on the UI you left out in the interest of
time, the answer is yes and <strong>you're not done</strong>.</p>

<p>Too many times I've seen people close out a task only to revisit it the
next week to polish up some loose ends, write a few more tests,
refactor a confusing piece, etc. Don't do it.</p>

<p>Software development is hard enough without having to keep mental notes of
all the needed tweaks and adjustments to things you've already <em>done</em>.
Your goal should be to knock out a task so totally and completely that
you can get it out of your brain and focus on the next one. Doing so
will do wonders for your sense of accomplishment.</p>
]]></description>
            <link>http://www.nearinfinity.com/blogs/jeff_kunkle/are_you_really_done.html</link>
            <guid>http://www.nearinfinity.com/blogs/jeff_kunkle/are_you_really_done.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Agile Development</category>
            
            
            <pubDate>Fri, 13 May 2011 21:19:22 -0500</pubDate>
        </item>
        
        <item>
            <title>Ruby Default Arguments and nil</title>
            <description><![CDATA[<p>Ruby's default arguments are a really handy language feature that I recently discovered aren't as handy as I once thought. I was trying to track down an error I was getting in the following snippet of code in my ActiveRecord model object:</p>

<pre class="prettyprint">
  1 def as_json(options={})
  2   options[:methods] ||= []
  3   options[:methods] << :full_name
  4   super(options)
  5 end
</pre>

<p>When this method was executed in order to convert the object into a JSON representation, I received this error (with line numbers adjusted for this example):</p>

<pre class="prettyprint">
  NoMethodError: undefined method '[]' for nil:NilClass
    from MyModel:2:in 'as_json'
</pre>

<p>I stared at this for a while until it dawned on me that explicitly passing 'nil' to as_json might not result in options being set to the default empty hash, and indeed it does not. I suppose it's technically correct, since nil is an instance of NilClass in Ruby and not some special value as it is in many other languages. It's just not what I was expecting and not what I want. For all the books, blog posts, and tutorials I've read, you'd think I would have picked up on this somewhere along the way.</p>

<p>Curiously though, can anyone think of a valid use case for not assigning the default value to a nil argument? I'm sure there are some, but they're not coming to mind.</p>
]]></description>
            <link>http://www.nearinfinity.com/blogs/jeff_kunkle/ruby_default_arguments_and_nil.html</link>
            <guid>http://www.nearinfinity.com/blogs/jeff_kunkle/ruby_default_arguments_and_nil.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Ruby</category>
            
            
            <pubDate>Mon, 07 Feb 2011 09:00:00 -0500</pubDate>
        </item>
        
        <item>
            <title>Lessons Learned Building an HTTPS Everywhere Safari Extension Clone</title>
            <description><![CDATA[<p>Ever since hearing about <a href="http://codebutler.com/firesheep">Firesheep</a> I've wanted a Safari extension similar to the <a href="https://www.eff.org/https-everywhere">HTTPS Everywhere</a> extension for Firefox. Frankly, I was puzzled that one didn't already exist, so I set out to write it. The result is <a href="http://www.nearinfinity.com/home/opensource/ssl-everywhere.html">SSL Everywhere</a>. The journey is this blog post.</p>

<p>I started the project as an effort to protect myself and others from Firesheep when using Safari on an open public wireless network, much like those found in coffee shops, hotels, and airports everywhere. Firesheep works by <a href="https://secure.wikimedia.org/wikipedia/en/wiki/Session_hijacking">hijacking your session</a>, which is basically a way of stealing your active login without needing your username or password. </p>

<p>My goal with SSL Everywhere was to protect someone from a session hijacking attack by ensuring all requests to the originating website were tunneled through SSL. This seemed trivial until I thought about the various kinds of requests that would need to be secured.</p>

<ul>
<li>the original HTML page</li>
<li>images</li>
<li>external JavaScript files</li>
<li>external CSS files</li>
<li>inline frames (iframes)</li>
<li>object or embed tags for things like videos or applets</li>
<li>Ajax requests</li>
<li>requests for the favicon</li>
</ul>

<p>It wasn't until I started to tackle each of the list items that I realized just how limited Safari's extension API is, and ultimately that <strong>one could never build a foolproof extension to protect Safari users from session hijacking attacks</strong>.</p>

<h1>Lessons Learned</h1>

<p>If you've spent any significant time writing Safari extensions, you may already be aware of the many restrictions and challenges I wrestled with for hours. Much of what I learned was trial and error, despite <a href="http://developer.apple.com/library/safari/#documentation/Tools/Conceptual/SafariExtensionGuide/Introduction/Introduction.html">well written documentation from Apple</a>. While the documentation does a fair job of describing many of the things you can do with an extension, it doesn't provide as much detail on what you <em>can't</em> do. That's what you'll find below.</p>

<h2>No Access to Raw Cookies</h2>

<p>The key to avoiding a session hijacking attempt is making sure the attacker can't access the session cookie, or cookies, your browser sends on each request. This can obviously be done by making sure all requests take place over an SSL connection. Unfortunately, you can't guarantee this won't happen since Safari extensions have no opportunity to intercept webpage requests before they occur. A user could easily type http://twitter.com into their address bar and SSL Everywhere couldn't stop the request.</p>

<p>The other option I pursued was having SSL Everywhere attempt to mark session cookies as secure since the browser will not send cookies marked as secure over a non-SSL connection. However, a Safari extension has no additional ability to manipulate cookies than normal JavaScript running on a page, meaning there is no way to read a cookie's path or expiration date for example. So, there's no way for the SSL Everywhere extension to simply mark a cookie as secure without having to guess at, or omit, other cookie information which may be important to the operation of the website.</p>

<h2>No beforeload for favicons, Ajax Calls, or Stylesheet References</h2>

<p>Apple was responsible for adding the beforeload event to Webkit. This gives scripts (and extensions) the ability to decide whether an external resource should be loaded or not. As stated in the Safari Extensions Development Guide, </p>

<blockquote>
  <p>Safari 5.0 and later (and other Webkit-based browsers) generates a "beforeload" event before loading each sub-resource belonging to a webpage. The "beforeload" event is generated before loading every script, iframe, image, or style sheet specified in the webpage, for example.</p>
</blockquote>

<p>I was thrilled after reading those two sentences because it was exactly what I needed. That is, until I discovered there's no beforeload event fired when the browser requests a website's favicon, makes an Ajax request, or loads an image reference defined in a stylesheet. This leaves a loophole where I can't stop a non-secure favicon reference, Ajax call, or CSS image reference from exposing the session cookies I can't properly mark as secure.</p>

<h2>src Attribute Can Not be Changed in beforeload Event Handlers</h2>

<p>I ultimately wanted to have a beforeload event listener that would </p>

<ol>
<li>inspect the source URL being requested</li>
<li>rewrite the source URL to a secure https: version if necessary</li>
<li>replace the resource's insecure reference with the secure https: URL</li>
<li>allow the loading of the resource to proceed with the new, secure URL</li>
</ol>

<p>Following the above procedure results in the resource being requested with the SSL-secured URL as desired, but will not stop the original load with the original, insecure, URL. You just end up making two requests for the same resource; one over SSL, the other not. Again, another point of exposure for the cookies.</p>

<h2>beforeload != before request</h2>

<p>It turns out that all the effort described above to leverage the beforeload event was futile. Preventing a resource from loading, as described in Apple's example of <a href="http://developer.apple.com/library/safari/documentation/Tools/Conceptual/SafariExtensionGuide/MessagesandProxies/MessagesandProxies.html#//apple_ref/doc/uid/TP40009977-CH14-SW9">blocking unwanted content</a>, stops it from being inserted into the DOM, but does not prevent it from being requested by the browser anyway.</p>

<p>Apple's example documentation states</p>

<blockquote>
  <p>If your script responds to a "beforeload" event by calling event.preventDefault(), the pending sub-resource is not loaded. This is a useful technique for blocking ads...</p>
</blockquote>

<p>Should I have really expected that "the pending sub-resource is not loaded" doesn't imply that it's not requested? Perhaps I wasn't sharp enough to catch that nuance, but once again the cookies are exposed.</p>

<h2>Host Page Prototypes Can Not be Changed</h2>

<p>When I discovered the beforeload event doesn't fire on Ajax requests, I decided to try to override the XMLHttpRequest <code>open</code> method and rewrite any insecure URLs to a secure version before yielding to the original <code>open</code> implementation. What I found was that you can't modify the prototypes of the page your start or end scripts are being injected into.</p>

<p>I suspect this has something to do with start and end scripts being secluded in their own separate, and randomly named, namespace. Changing around object prototypes never resulted in any errors, it just didn't change the prototypes of the host page and therefore couldn't change the XMLHttpRequest object. Again, another point of exposure for the precious cookies.</p>

<h1>Status of SSL Everywhere</h1>

<p>If you've read this far it should be obvious that SSL Everywhere cannot guarantee protection against session hijacking attacks, including those from Firesheep. However, it does enhance security by automatically redirecting you to secure versions of many websites and rewriting insecure links to their SSL-encrypted equivalents. If you must use Safari to access popular websites when connected to an open WiFi network, you're probably better off doing it with SSL Everywhere.</p>

<p>We don't offer a pre-built version of the extension for easy installation into Safari because we don't want people to casually install it and forget that it's not completely secure for all sites. If people find it valuable nonetheless, then we may consider creating the extension bundle in the future.</p>

<h1>Try It!</h1>

<p>If you'd like to try SSL Everywhere you can find the <a href="https://github.com/nearinfinity/ssl-everywhere.safariextension">source code on Github</a>. It's open source software licensed under the GPL version 2 license, primarily because it borrows code from <a href="https://www.eff.org/https-everywhere">HTTPS Everywhere</a>. If you can come up with solutions to any of the problems I encountered, please let me know!</p>
]]></description>
            <link>http://www.nearinfinity.com/blogs/jeff_kunkle/lessons_learned_building_an_ht.html</link>
            <guid>http://www.nearinfinity.com/blogs/jeff_kunkle/lessons_learned_building_an_ht.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">JavaScript</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Mac OS X</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Security</category>
            
            
            <pubDate>Tue, 14 Dec 2010 08:31:55 -0500</pubDate>
        </item>
        
        <item>
            <title>Mini Confluence Adds Diff/Change Viewing</title>
            <description><![CDATA[<p><img alt="Mini Confluence Diff View" src="http://www.nearinfinity.com/blogs/2010/12/10/diff.png" width="252" height="535" class="mt-image-right" style="float: right; margin: 0 0 20px 20px;" />
Last Thursday we published version 1.1 of <a href="http://www.miniconfluence.com">Mini Confluence</a>, which includes a new release of the Confluence plugin and iPhone client. The new plugin is available immediately, while the iPhone client will likely be published to the App Store within a week or two. But, you won't get any of the new features without updating the plugin, so do that now.</p>

<h2>View Diffs/Changes to Pages and News</h2>

<p>One really cool feature in this release is the ability to view historical changes of a page or news item. You'll now see a "View change..." link just below the author's name on any page or news item. Tapping that link will bring up the change view shown here.</p>

<p>Swiping left to right will take you to older versions of the content while swiping right to left will return you to newer versions. The view for each version shows what changed from the previous version. Additionally, tapping the View button at the top right will show you the rendered content of the specific version for which you're viewing the changes. It's pretty cool!</p>

<p>Please see the <a href="http://www.miniconfluence.com/blog/2010/12/09/mini_confluence_1.1_released.html">Mini Confluence 1.1 Release blog post</a> for full details on everything that changed in the new version.</p>
]]></description>
            <link>http://www.nearinfinity.com/blogs/jeff_kunkle/mini_confluence_adds_diffchang.html</link>
            <guid>http://www.nearinfinity.com/blogs/jeff_kunkle/mini_confluence_adds_diffchang.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">General</category>
            
            
            <pubDate>Mon, 13 Dec 2010 09:00:00 -0500</pubDate>
        </item>
        
        <item>
            <title>Environment Specific Default Attachment Options for Paperclip</title>
            <description><![CDATA[<p><a href="https://github.com/thoughtbot/paperclip">Paperclip</a> is a popular Ruby file attachment solution for ActiveRecord. Following some basic setup, you can specify an attachment to an ActiveRecord model by calling the has_attached_file class method as shown in the example below.</p>

<pre class="prettyprint">
class Photo < ActiveRecord::Base
  has_attached_file :image,
    :styles => { :medium => '350x350>', :thumb => '100x100#' },
    :url    => ':class/:id/:style.:extension',
    :path   => ':rails_root/assets/:class/:id_partition/:style.:extension'
end
</pre>

<p>I love how easy it is to specify an attachment, but I don't like having to specify the :url and :path on all attachments for two reasons:</p>

<ol>
<li>It's not <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself">DRY</a>. With the <a href="https://github.com/thoughtbot/paperclip/wiki/Interpolations">Paperclip interpolations</a> I'm using, the :url and :path are never going to change within an environment no matter how many attachments I have across all my models.</li>
<li>Between environments I do need to change the path. In development I keep the attachments in :rails_root/assets but in production I want them somewhere else.</li>
</ol>

<p>Fortunately, changing the Paperclip attachment defaults per environment is really easy. In your environment config files, do something like the following.</p>

<pre class="prettyprint">
# development.rb (or use environment.rb to setup defaults for all)
Paperclip::Attachment.default_options[:url] = ':class/:id/:style.:extension'
Paperclip::Attachment.default_options[:path] = ':rails_root/assets/:class/:id_partition/:style.:extension'

# production.rb
Paperclip::Attachment.default_options[:url] = ':class/:id/:style.:extension'
Paperclip::Attachment.default_options[:path] = '/usr/local/assets/:class/:id_partition/:style.:extension'
</pre>

<p>Adding those defaults in your environment configuration files means you can keep your models DRY and free of any ugly code used to change options depending on the environment. Isn't this nicer?</p>

<pre class="prettyprint">
class Photo < ActiveRecord::Base
  has_attached_file :image, 
    :styles => { :medium => '350x350>', :thumb => '100x100#' }
end
</pre>
]]></description>
            <link>http://www.nearinfinity.com/blogs/jeff_kunkle/environment_specific_default_a.html</link>
            <guid>http://www.nearinfinity.com/blogs/jeff_kunkle/environment_specific_default_a.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Ruby</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Web Development</category>
            
            
            <pubDate>Tue, 07 Dec 2010 09:09:34 -0500</pubDate>
        </item>
        
        <item>
            <title>Conferences are Not For Learning</title>
            <description><![CDATA[<p>Near Infinity has the <a href="http://www.nearinfinity.com/home/currentopenings.html" title="Awesome Training Program">most generous training program</a> I've heard of among our competitors, and certainly rivals the best in the industry. Colleagues occasionally ask me for opinions about a conference or training course they're considering. My stock answer for such inquiries has always been to "attend a good training class for depth of understanding on a narrow topic and pick a conference for more broad but shallower knowledge of many areas." I think the training course advice is still accurate, but I was wrong about conferences.</p>

<p>The best conferences aren't about learning at all. They're about inspiration. I finally realized this at RailsConf last week, despite having attended dozens of conferences during the past ten years. Surprisingly, I found most of the topics rather boring, most of the presenters unpolished, and most of the presentations poorly constructed and minimally rehearsed. The things I enjoyed most were the keynotes from Dave Thomas and David Heinemeier Hansson, a performance-related presentation by Aaron Patterson, an entrepreneurial story by Tom Preston-Werner, and a reflection talk by Keavy McMinn on her journey from artist to programmer. Why did I enjoy them? Because they caused me to look at things differently, forced me to think critically about my choices, and motivated me to act. Only one of these was technical in nature by the way, just one! </p>

<p>A good conference should inspire you to do something. No talk is long enough to teach you anything immediately useful. The best you can hope for is exposure to lots of stuff you might want to look into after the conference. Of course you could get the same level of exposure by reading the conference agenda, Googling each topic, and reading through some documentation on each homepage. What you can't get is the inspiration from a great speaker, motivational story, or engaged community. </p>

<p>So the next time you contemplate attending a conference, do your best to judge the inspiration potential. After all, if you're not going to do anything different after the conference, why bother going?</p>
]]></description>
            <link>http://www.nearinfinity.com/blogs/jeff_kunkle/conferences_are_not_for_learni.html</link>
            <guid>http://www.nearinfinity.com/blogs/jeff_kunkle/conferences_are_not_for_learni.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">General</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Ruby</category>
            
            
            <pubDate>Mon, 15 Nov 2010 09:45:50 -0500</pubDate>
        </item>
        
        <item>
            <title>Is system refactoring possible?</title>
            <description><![CDATA[<p>People have talked about it for years. Even if you're new, you've certainly been on the receiving end of more war stories than you care to remember; it's that old legacy system. You know, the one that started out small but now has all kinds functionality tacked on here or growing out of there. Corporate architects most certainly call this growth subsystems but you know better. It's really just the junk that's built up over time because the <em>system</em> was never refactored.</p>

<p>It's widely accepted that refactoring is a best practice for keeping code simple, DRY, and maintainable. What doesn't seem so widely accepted is the habit of applying the same practices at a broader system level. </p>

<p>Why don't we refactor systems? I started thinking about this very question during a recent all-day system design presentation, one of several in a series mind you. As I ingested slide after slide of barely visible text accompanied by Visio diagrams packed with boxes and arrows pointing in every direction, I wondered how things became so complicated. </p>

<p>In my experience, there seems to be some kind of stigma around reworking (aka refactoring) interconnected systems. New features are always bolted on to our existing systems, but nothing is ever redesigned, reorganized, or re-anything'ed. Over time, we end up with bolts on top of bolts until the thought of reworking any part of the system is completely overwhelming. </p>

<p>So why is the concept of refactoring an interconnected system so foreign when it's been used so successfully for more discrete pieces of software? Is it possible?</p>
]]></description>
            <link>http://www.nearinfinity.com/blogs/jeff_kunkle/is_system_refactoring_possible.html</link>
            <guid>http://www.nearinfinity.com/blogs/jeff_kunkle/is_system_refactoring_possible.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Agile Development</category>
            
            
            <pubDate>Mon, 01 Nov 2010 11:16:50 -0500</pubDate>
        </item>
        
        <item>
            <title>Protect your Rails Model Objects with Grant</title>
            <description><![CDATA[<p>Near Infinity recently announced the release of <a href="http://github.com/nearinfinity/grant">Grant</a>, a Ruby on Rails plugin for securing and auditing access to your Rails model objects, and I'm here to tell you a little bit about it. There are two primary pieces of Grant, model security and model audit. I'll be focusing on model security for this post and will address model audit in a later entry.</p>

<p>Grant's model security is deliberately designed to force the developer to make conscious security decisions about what CRUD operations a user should be allowed to perform on your model objects. It doesn't care how you choose to authenticate and authorize your users to perform a CRUD operation, it only cares that you actually do it.</p>

<p>Rather than specify which operations are restricted, Grant restricts all CRUD operations unless they're explicitly granted to the user. It also restricts adding or removing items from <em>has_many</em> and <em>has_and_belongs_to_many</em> associations. Only allowing operations explicitly granted forces you to make conscious security decisions. While it obviously can't ensure you make the correct decisions, it should help ease the latent fear that you've inadvertently forgotten to secure something.</p>

<p>Enough talk, let me show you an example of how you might use it. To enable model security you simply include the Grant::ModelSecurity module in your model class. In this example you see three grant statements. The first grants find (aka read) permission to everyone. The second example grants create, update, and destroy permission when the passed block evaluates to true, which in this case happens when the model is editable by the current user. You can put any code you want in that block as long as it returns a boolean value. Similarly, the third grant statement permits additions and removals from the tags association when it's block evaluates to true. A Grant::ModelSecurityError is raised if any grant block evaluates to false or nil.</p>

<pre class="prettyprint">
class EditablePage < ActiveRecord::Base
  include Grant::ModelSecurity
  has_many :tags

  grant(:find) { true }
  grant(:create, :update, :destroy) do |user, model| 
    model.editable_by_user? user 
  end
  grant(:add => :tags, :remove => :tags) do |user, model, associated_model| 
    model.editable_by_user? user 
  end

  def editable_by_user? user
    user.administrator?
  end
end
</pre>

<p>There's a lot more to the grant statement than shown in the above example. For instance, you can have multiple grant statements for the same action. Ultimate permission to perform the action will not be granted unless all grant blocks evaluate to true.</p>

<p>As you can see, Grant is pretty simple to use, but it's not going to do the dirty work for you. It's up to you to make the proper security decisions. Grant's just there to make sure you don't forget. </p>
]]></description>
            <link>http://www.nearinfinity.com/blogs/jeff_kunkle/protect_your_rails_model_objec.html</link>
            <guid>http://www.nearinfinity.com/blogs/jeff_kunkle/protect_your_rails_model_objec.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Ruby</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Security</category>
            
            
            <pubDate>Wed, 18 Nov 2009 14:00:00 -0500</pubDate>
        </item>
        
        <item>
            <title>Groovy&apos;s Safe Navigation Operator Not as Safe as I Thought</title>
            <description><![CDATA[<p>The safe navigation operator is almost certainly my favorite operator in Groovy. It allows you to guard against <code>NullPointerException</code>(s) much more cleanly than defining a nasty if/else mess. Consider the following example.</p>

<pre name="code" class="prettyprint lang-groovy">
class Book {
    String title
    Author author
}

class Author {
    String firstName
    String lastName
}

def author = new Author(firstName:'Jason')
def book = new Book(title:'Say no to NPEs', author:author)

println book.author?.lastName
</pre>

<p>Did you see that <code>?.</code> operator on the last line of the code sample? That's the safe navigation operator, and it's the equivalent of writing the following if statement (although it's much more readable).</p>

<pre name="code" class="prettyprint lang-groovy">
if (book.author != null) {
    println book.author.lastName
}
</pre>

<p>The safe navigation operator essentially checks to see if the object you're about to invoke a method on is <code>null</code>. If it is <code>null</code>, it simply skips the method invocation and returns <code>null</code>. If it isn't <code>null</code>, it proceeds as usual. It works for method chaining too, so if you're worried about <code>book</code> being <code>null</code>, you could write</p>

<pre name="code" class="prettyprint lang-groovy">
println book?.author?.lastName
</pre>

<p>This way, if either <code>book</code> or <code>author</code> are <code>null</code>, you simply print out <code>null</code> instead of causing a NullPointerException.</p>

<p>Since learning about the safe navigation operator, I've used it successfully in dozens of classes without any problem. Until last week. Consider the following line of code .</p>

<pre name="code" class="prettyprint lang-groovy">
println book?.author?.firstName?.trim().concat(" is great.")
</pre>

<p>Thanks to the safe navigation operator we can write this concatenation of <code>firstName</code> and a sentence fragment without worrying about <code>NullPointerException</code>(s) and ugly if blocks. Or so I thought.</p>

<p>Looking at this line of code, I thought for sure I was safe from any sneaky <code>NullPointerException</code>. If <code>book</code>, <code>author</code> or <code>firstName</code> are <code>null</code> I'll simply end up printing <code>null</code> and not have to worry about the <code>concat()</code> method. After all, if the <code>trim()</code> method succeeds, there's no sense in guarding it's result for <code>null</code>. And that's where I was wrong.</p>

<p>I naively assumed the method chain would stop once the safe navigation operator encountered a <code>null</code> when in fact it does not. While the <code>trim()</code> method is safe from being called on a <code>null</code> <code>firstName</code> object, it will return <code>null</code>, upon which the <code>concat()</code> method is called. Oops!</p>
]]></description>
            <link>http://www.nearinfinity.com/blogs/jeff_kunkle/groovys_safe_navigation_operat.html</link>
            <guid>http://www.nearinfinity.com/blogs/jeff_kunkle/groovys_safe_navigation_operat.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Groovy</category>
            
            
            <pubDate>Tue, 14 Apr 2009 06:50:00 -0500</pubDate>
        </item>
        
        <item>
            <title>Use DNS Search Domains for Shorter URLs</title>
            <description><![CDATA[While I was reading through some Apple documentation on Bonjour I stumbled across a discussion on link-local addressing and DNS search domains. While the details of link-local addressing aren't that important here, the discussion on DNS search domains triggered a little light bulb in my brain.<div><br /></div><div>You see, DNS search domains are used as a guide to help your computer lookup an IP address when something simple like "blogs" is typed into your browser's URL. If you setup a DNS search domain of "nearinfinity.com", typing "blogs" will force your computer to first check if there's an address for "blogs.nearinfinity.com". If not it falls back to its default behavior.</div><div><br /></div><div>If you're a person that spends a lot of time on a small number of websites, you could use DNS search domains to your advantage to make navigating to those sites a snap. For instance, I just setup "nearinfinity.com" as an entry in my DNS search domains on my Mac. Simply go to the network preferences pane, click the advanced button at the bottom left, and then the DNS tab on the resulting popup.</div><div><br /></div><div><span class="mt-enclosure mt-enclosure-image" style="display: inline;"><img alt="dns_search_domains_osx.jpg" src="http://www.nearinfinity.com/blogs/assets/jkunkle/dns_search_domains_osx.jpg" width="600" height="450" class="mt-image-none" style="" /></span></div><div><br /></div><div>So now, whenever I type "blogs" in my URL I get "blogs.nearinfinity.com". Whenever I type "support" I get "support.nearinfinity.com". I think you probably get the idea. I know I'm no genius for discovering this since it's precisely the reason for having search domains. I just never thought to use them before.</div>]]></description>
            <link>http://www.nearinfinity.com/blogs/jeff_kunkle/use_dns_search_domains_for_sho.html</link>
            <guid>http://www.nearinfinity.com/blogs/jeff_kunkle/use_dns_search_domains_for_sho.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">General</category>
            
                <category domain="http://www.sixapart.com/ns/types#category">Mac OS X</category>
            
            
            <pubDate>Sat, 24 Jan 2009 20:01:37 -0500</pubDate>
        </item>
        
        <item>
            <title>Use Caution when Mixing JUnit 3 and 4</title>
            <description><![CDATA[<p>Quick quiz, what is the output from the following JUnit test?</p>

<pre class="prettyprint lang-java">package com.nearinfinity.sandbox;
import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class ModelTest extends TestCase {

    @Before
    public void setUp() {
        System.out.println("Setup called.");
    }

    @After
    public void teardown() {
        System.out.println("Teardown called.");
    }
 
    @Test
    public void testSomething() {
        assertTrue(true);
    }
 
}
</pre>

<p>If you said</p>

<pre><code>Setup has been called.
Teardown has been called.
</code></pre>

<p>you'd be wrong. Don't feel bad though, I spent about two hours staring at a similar test until I finally figured out what was going on. So, what's the problem?</p>

<p>The problem lies in the mixed use of JUnit 3 and 4 concepts. The astute reader will notice that this test extends the JUnit 3 <em>junit.framework.TestCase</em> while also using JUnit 4 annotations. So which wins, the base class methods, the annotations, or both? Well, it turns out that the JUnit 3 base class conventions win out and the annotations are ignored. With that said, can you now guess what the test output is? Did you guess</p>

<pre><code>Setup has been called.
</code></pre>

<p>If not, don't feel bad. It's not immediately obvious. It turns out that the <em>testSomething</em> test method runs because it starts with the word <em>test</em>, not because it's decorated with the <em>org.junit.Test</em> annotation. The <em>setUp</em> method runs because it overrides <em>junit.framework.TestCase</em>'s <em>setUp</em> method, not because it has a <em>org.junit.Before</em> annotation. Lastly, the <em>teardown</em> method doesn't run at all because it does not override the base class <em>tearDown</em> method due to the lowercase "d" and as we've seen, the <em>org.junit.After</em> annotation has no effect.</p>

<p>That lower case "d" cost me two hours of my life, which I now consider time well spent. It made me realize that my test's inheritance chain ultimately led to <em>junit.framework.TestCase</em>. The fact that the test had worked in the past was a textbook case of dumb luck.</p>

<p>So, if your JUnit 4 test classes start acting strange, make sure that base class you're extending doesn't ultimately lead to a <em>junit.framework.TestCase</em>. </p>

<p></p>]]></description>
            <link>http://www.nearinfinity.com/blogs/jeff_kunkle/use_caution_when_mixing_junit.html</link>
            <guid>http://www.nearinfinity.com/blogs/jeff_kunkle/use_caution_when_mixing_junit.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Java</category>
            
            
            <pubDate>Mon, 31 Dec 2007 07:30:00 -0500</pubDate>
        </item>
        
        <item>
            <title>Application Versus Database Security</title>
            <description><![CDATA[<p>
The merits of placing security in the application layer versus the database is a debate I seem to find myself in regularly. As an application developer, I've historically argued for application-level security. It was something I understood well and felt like I had some control over. Over time, I've come to understand the debate from many perspectives and have adjusted my convictions accordingly.
</p>
<p>
For the record, I don't believe there is any absolutely correct answer. There are valid arguments for each side of the debate. My perspective has mostly been shaped through experience developing custom software for clients. I have little experience developing commercial software and surmise that your thoughts on the subject may differ if that's your day job.
</p>
<p>
In my experience, most customers view their data as the most important aspect of any system, not the application. They want to be sure their data is safe at all times. What if someone accesses the database through a different application, a third-party data broker or directly via a SQL client? How do you protect the data in those situations if all the restrictions are resident in the application? I hear these questions all the time.
</p>
<p>
The rebuttal to this argument that I hear most often is that nobody will ever access the data outside of the application. This seems like an obviously shortsighted statement to me and I don't think anyone actually believes it. It's more of a synonym for saying that you'd rather not worry about security at the database layer because it's out of your control, too hard, etc. Pick your favorite excuse. I've probably used them all myself.
</p>
<p>
What it all boils down to is that the database is very likely to outlive your application. In fact, it'll probably outlive your application and several subsequent ones. Why would a customer want to pay someone to rebuild the security logic each time? It's tedious, expensive, and error prone. Additionally, you're application may not be the only one accessing the database. What are the odds that two development teams implement security constraints the same exact way in each application? Not good, I promise.
</p>
<p>
As I stated in the beginning, I've definitely changed my perspectives on application versus database-level security. I was certainly an application-level security bigot before, but I find it difficult to continue my unwavering ways when looking at the problem more critically. I just hope my fellow colleagues don't renounce me for siding with the DBAs on this one.
</p>]]></description>
            <link>http://www.nearinfinity.com/blogs/jeff_kunkle/application_versus_database_security.html</link>
            <guid>http://www.nearinfinity.com/blogs/jeff_kunkle/application_versus_database_security.html</guid>
            
                <category domain="http://www.sixapart.com/ns/types#category">Security</category>
            
            
            <pubDate>Mon, 26 Nov 2007 07:30:00 -0500</pubDate>
        </item>
        
    </channel>
</rss>

