<?xml version="1.0" encoding="utf-8" ?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <id>http://nutrun.com/</id>
  <link href="http://nutrun.com/" rel="alternate" type="text/html" />
  <title>nutrun</title>
  <subtitle>nutrun atom feed</subtitle>
  <updated>2011-03-02T00:00:00Z</updated>
  <author>
    <name>George Malamidis</name>
  </author>
  
  <entry>
    <id>http://nutrun.com/weblog/2011/03/02/earl-webified-strings.html</id>
    <published>2011-03-02T00:00:00Z</published>
    <updated>2011-03-02T00:00:00Z</updated>
    <link href="http://nutrun.com/weblog/2011/03/02/earl-webified-strings.html" rel="alternate" type="text/html" />
    <title>Earl - webified strings</title>
    <author>
      <name>George Malamidis</name>
      <uri>http://nutrun.com</uri>
    </author>
    <content type="html">
      &lt;div class=&quot;article&quot;&gt;
  
  
  &lt;p&gt;
    &lt;a href=&quot;https://gist.github.com/852228&quot;&gt;Earl&lt;/a&gt;
    makes Ruby strings do web stuff like extracting urls or finding redirect destinations.
  &lt;/p&gt;
  &lt;pre&gt;
text = &quot;Blah blah http://tinyurl.com/4bnjzbu blah http://tinyurl.com/4tefu9f&quot;

text.urls # =&amp;gt; [&quot;http://tinyurl.com/4bnjzbu&quot;, &quot;http://tinyurl.com/4tefu9f&quot;]

&quot;http://tinyurl.com/4tefu9f&quot;.location # =&amp;gt; &quot;http://nutrun.com/&quot;
  &lt;/pre&gt;
&lt;/div&gt;
    </content>
  </entry>
  
  <entry>
    <id>http://nutrun.com/weblog/2010/11/17/supercharged-ruby-console-output.html</id>
    <published>2010-11-17T00:00:00Z</published>
    <updated>2010-11-17T00:00:00Z</updated>
    <link href="http://nutrun.com/weblog/2010/11/17/supercharged-ruby-console-output.html" rel="alternate" type="text/html" />
    <title>Supercharged ruby console output</title>
    <author>
      <name>George Malamidis</name>
      <uri>http://nutrun.com</uri>
    </author>
    <content type="html">
      &lt;div class=&quot;article&quot;&gt;
          
          
          &lt;p&gt;
            &lt;a href=&quot;https://gist.github.com/703943&quot;&gt;https://gist.github.com/703943&lt;/a&gt;
          &lt;/p&gt;
        &lt;/div&gt;
    </content>
  </entry>
  
  <entry>
    <id>http://nutrun.com/weblog/2010/06/24/sinatra-reloader.html</id>
    <published>2010-06-24T00:00:00Z</published>
    <updated>2010-06-24T00:00:00Z</updated>
    <link href="http://nutrun.com/weblog/2010/06/24/sinatra-reloader.html" rel="alternate" type="text/html" />
    <title>Sinatra reloader</title>
    <author>
      <name>George Malamidis</name>
      <uri>http://nutrun.com</uri>
    </author>
    <content type="html">
      &lt;div class=&quot;article&quot;&gt;
          
          
          &lt;p&gt;
            When I first started using it to write web apps a couple of years ago,
            &lt;a href=&quot;http://www.sinatrarb.com/&quot; title=&quot;Sinatra&quot;&gt;Sinatra&lt;/a&gt;
            supported code reloading in development mode. That feature was dropped from the core of Sinatra at some point and we just got used to restarting the app every time we made a change whilst developing, it's not that huge an overhead, especially considering Sinatra's fast start up.
          &lt;/p&gt;
          &lt;p&gt;
            I recently had to work on a Rails codebase for a while, which reminded me that code reloading without restarting in dev mode is functionality I don't mind spoiling myself with. At the time,
            &lt;a href=&quot;http://twitter.com/abhinay&quot; title=&quot;&quot;&gt;Abs&lt;/a&gt;
            pointed me to
            &lt;a href=&quot;http://github.com/rkh/sinatra-reloader&quot; title=&quot;rkh's sinatra-reloader at master - GitHub&quot;&gt;sinatra-reloader&lt;/a&gt;
            which I installed and used in a couple of apps and it works well. As I'm writing this, I'm also looking at
            &lt;a href=&quot;http://github.com/rack/rack/blob/master/lib/rack/reloader.rb&quot; title=&quot;lib/rack/reloader.rb at master from rack's rack - GitHub&quot;&gt;Rack::Reloader&lt;/a&gt;,
            which I've never used and seems somewhat different with its own set of interesting features.
            &lt;a href=&quot;http://rtomayko.github.com/shotgun/&quot; title=&quot;shotgun(1) - reloading rack development server&quot;&gt;Shotgun&lt;/a&gt;
            is out of the question for me, because it feels like manually restarting the app is faster than the time Shotgun takes to load everything per request.
          &lt;/p&gt;
          &lt;p&gt;
            &lt;a href=&quot;http://rvm.beginrescueend.com/&quot; title=&quot;RVM: Ruby Version Manager -
        RVM Ruby Version Manager - Documentation&quot;&gt;RVM&lt;/a&gt;
            has prompted me to switch between Ruby versions more often than in the past, resulting in installing gems more frequently than I used to, which in turn brings out an OCD side of me when it comes to gems that download other gems as dependencies. That's the one thing that bugs me about sinatra-reloader and since I found myself with a bit of time on my hands, I wrote my own Sinatra reloader which I've put in
            &lt;a href=&quot;http://gist.github.com/450814&quot; title=&quot;gist: 450814 - Code reloading for Sinatra- GitHub&quot;&gt;this gist&lt;/a&gt;
            in case someone else finds it useful.
          &lt;/p&gt;
          &lt;p&gt;
            It works by reloading all source files and routes when it detects a change. This is less efficient than selectively reloading only code from files that have changed, although I tried it in a few of my projects without noticeable penalties. A thing to watch out for is that once a constant has been loaded, it will still be around after you delete the code that declares it. Restarting is required for such changes to take effect. I've also noticed a similar issue with classes that extend
            &lt;code&gt;Sequel::Model&lt;/code&gt;
            - if I run a migration and don't restart, database field mappings don't get updated, because Sequel makes those mappings at the time
            &lt;code&gt;Sequel::Model&lt;/code&gt;
            is subclassed.
          &lt;/p&gt;
          &lt;p&gt;
            In summary, if you don't mind installing a bunch of gems you're likely to never use, I recommend
            &lt;a href=&quot;http://github.com/rkh/sinatra-reloader&quot; title=&quot;rkh's sinatra-reloader at master - GitHub&quot;&gt;sinatra-reloader&lt;/a&gt;.
            If you're after code reloading which you might want to customise with a couple of lines of code on the spot to suit your particular project's needs,
            &lt;a href=&quot;http://gist.github.com/450814&quot; title=&quot;gist: 450814 - Code reloading for Sinatra- GitHub&quot;&gt;this&lt;/a&gt;
            can be a starting point.
          &lt;/p&gt;
        &lt;/div&gt;
    </content>
  </entry>
  
  <entry>
    <id>http://nutrun.com/weblog/2009/12/22/incremental-deployment.html</id>
    <published>2009-12-22T00:00:00Z</published>
    <updated>2009-12-22T00:00:00Z</updated>
    <link href="http://nutrun.com/weblog/2009/12/22/incremental-deployment.html" rel="alternate" type="text/html" />
    <title>Incremental deployment</title>
    <author>
      <name>George Malamidis</name>
      <uri>http://nutrun.com</uri>
    </author>
    <content type="html">
      &lt;div class=&quot;article&quot;&gt;
          
          
          &lt;p&gt;
            I've recently had a chance to look at a high availability system designed and built by
            &lt;a href=&quot;http://www.forward.co.uk/&quot; title=&quot;Forward: Connecting business with customers and people with products online&quot;&gt;Forward&lt;/a&gt;
            colleagues
            &lt;a href=&quot;http://adkent.com/&quot; title=&quot;adkent.com&quot;&gt;Andy Kent&lt;/a&gt;
            and
            &lt;a href=&quot;http://oobaloo.co.uk/&quot; title=&quot;Paul Ingles - Articles&quot;&gt;Paul Ingles&lt;/a&gt;.
            It is a critical web service with a very high impact of failure. Essentially, it
            &lt;b&gt;must&lt;/b&gt;
            stay up at all times.
          &lt;/p&gt;
          &lt;p&gt;
            The service is hosted on
            &lt;a href=&quot;http://aws.amazon.com/ec2/&quot; title=&quot;Amazon Elastic Compute Cloud (Amazon EC2)&quot;&gt;Amazon EC2&lt;/a&gt;.
            It makes use of EC2's geographically distributed regions and different availability zones within each region, fronted by
            &lt;a href=&quot;http://aws.amazon.com/elasticloadbalancing/&quot; title=&quot;Elastic Load Balancing&quot;&gt;AWS Elastic Load Balancing&lt;/a&gt;
            and additional global DNS fail over outside of EC2/AWS.
          &lt;/p&gt;
          &lt;p&gt;
            &lt;a href=&quot;http://www.flickr.com/photos/nutrun/4206247218/&quot; title=&quot;high-availability-arch by nutrunflickr, on Flickr&quot;&gt;
              &lt;img alt=&quot;high-availability-arch&quot; height=&quot;309&quot; src=&quot;http://farm5.static.flickr.com/4008/4206247218_4b8f165e0b_o.png&quot; width=&quot;497&quot;&gt;&lt;/a&gt;
          &lt;/p&gt;
          &lt;p&gt;A part of the project that struck me as particularly interesting is the deployment strategy Paul and Andy settled on. Regardless of how much trust we have in our builds and QA process, deployments become a whole different, much more stressful activity when critical systems like the one under discussion are involved. Andy mentioned it is important to find the balance between what to automate and bits that should require manual input.&lt;/p&gt;
          &lt;pre&gt;
# deploy.rb

task :us_1b do
  set :region, 'us-east-1'
  set :servers, us_1b
  # More US 1b specific setup...
end

task :eu_1a do
  set :region, 'eu-west-1'
  set :servers, eu_1a
  # More EU 1a specific setup...
end&lt;/pre&gt;
          &lt;p&gt;
            This service is
            &lt;em&gt;incrementally deployed one availability zone at a time&lt;/em&gt;,
            e.g.
            &lt;code&gt;cap us_1b deploy&lt;/code&gt;.
            Each deployment step is manual - it requires someone to push the button. This means that if something goes wrong, only part of the system will be affected, achieving significant redundancy. If the failure was severe enough to bring the system down, only one availability zone in one region will fail and the load balancers will make sure that this failure is transparent to end users and does not overall affect the entire system.
          &lt;/p&gt;
        &lt;/div&gt;
    </content>
  </entry>
  
  <entry>
    <id>http://nutrun.com/weblog/2009/11/10/deployment-setup-automation.html</id>
    <published>2009-11-10T00:00:00Z</published>
    <updated>2009-11-10T00:00:00Z</updated>
    <link href="http://nutrun.com/weblog/2009/11/10/deployment-setup-automation.html" rel="alternate" type="text/html" />
    <title>Deployment setup automation</title>
    <author>
      <name>George Malamidis</name>
      <uri>http://nutrun.com</uri>
    </author>
    <content type="html">
      &lt;div class=&quot;article&quot;&gt;
          
          
          &lt;p&gt;Part of my work these days has to do with building and deploying numerous experimental applications with varying life cycles. Many of these applications get built and put on a server in less than a day only to be shut down and never looked at again a couple of days later, others get turned off and revisited after some time, while others graduate to larger, wider scope systems.&lt;/p&gt;
          &lt;p&gt;This means that I get to deploy applications for the first time more frequently than usual. Also, because we deploy to virtualised infrastructures (including an internal cloud, Slicehost and Amazon EC2), slice instances (servers) tend to get rebuilt more often than they would in the absence of virtualisation. First time deployments are generally more involved than subsequent ones because there is setup up to be made and software to be installed in order for the host servers to accommodate the application.&lt;/p&gt;
          &lt;p&gt;One way to treat first time deployment woes is to create and maintain images of the system in the state required to host the application. I find this to work well when dealing with moderate numbers of applications and servers, whereas creating and keeping images up to date has a tendency to become tedious and inflexible as the number of applications and images increases.&lt;/p&gt;
          &lt;p&gt;
            As an alternative, we can move prerequisite system setup and installations responsibility closer to the application code, in the form of an
            &lt;code&gt;after&lt;/code&gt;
            hook to the
            &lt;code&gt;deploy:setup task&lt;/code&gt;
            that we call the first time we deploy an application with Capistrano. Here's some Capistrano code that performs one time setup tasks.
          &lt;/p&gt;
          &lt;pre&gt;
namespace :util do
  task :install_libraries do
    sudo 'apt-get install libxml2 libxml2-dev libmysqlclient15-dev -y'
  end  
end

after 'deploy:setup', 'util:install_libraries'&lt;/pre&gt;
          &lt;p&gt;With this approach, the application knows how to setup the system the way it needs it to be next time it gets deployed for the first time. As an added benefit, the Capistrano code serves as documentation for the application's system requirements.&lt;/p&gt;
        &lt;/div&gt;
    </content>
  </entry>
  
  <entry>
    <id>http://nutrun.com/weblog/2009/08/29/vcs-practices-over-features.html</id>
    <published>2009-08-29T00:00:00Z</published>
    <updated>2009-08-29T00:00:00Z</updated>
    <link href="http://nutrun.com/weblog/2009/08/29/vcs-practices-over-features.html" rel="alternate" type="text/html" />
    <title>VCS practices over features</title>
    <author>
      <name>George Malamidis</name>
      <uri>http://nutrun.com</uri>
    </author>
    <content type="html">
      &lt;div class=&quot;article&quot;&gt;
          
          
          &lt;p&gt;
            I've often heard people I know and respect say that
            &lt;cite&gt;
              &lt;a href=&quot;http://git-scm.com/&quot; title=&quot;Git - Fast Version Control System&quot;&gt;git&lt;/a&gt;
              is leaps and bounds better than
              &lt;a href=&quot;http://subversion.tigris.org/&quot; title=&quot;subversion.tigris.org&quot;&gt;Subversion&lt;/a&gt;
            &lt;/cite&gt;.
            I've been a relatively early adopter of git, it's been my VCS of choice for almost two years now. Even though I find it superior to most of the competition I struggle to justify the &quot;leaps and bounds&quot; claim and would rather more modestly call it &quot;a step forward&quot;.
          &lt;/p&gt;
          &lt;p&gt;This is probably due to the practices we find benefit our development process. Git puts great emphasis on branching, something we generally tend to avoid (to clarify, I'm not referring to local branching). We concentrate on feedback based on the usage of our applications. This means that we strive to commit as often as possible and, most importantly, deploy to production at a constant rate. Grossly simplified, the process is: identify a small coherent feature, build it, commit it to the master branch and deploy. No part of the codebase is owned by a subdivision of the team, everyone works on everything.&lt;/p&gt;
          &lt;p&gt;
            By far the most popular git commands we issue are
            &lt;code&gt;git pull&lt;/code&gt;,
            &lt;code&gt;git add&lt;/code&gt;
            and
            &lt;code&gt;git push&lt;/code&gt;,
            not that different to
            &lt;code&gt;svn update&lt;/code&gt;
            and
            &lt;code&gt;svn commit&lt;/code&gt;.
          &lt;/p&gt;
          &lt;p&gt;When I first started using git I was wondering if I had developed a fear of branching because of Subversion's inefficiencies in that area. In reality, I think that an environment where every developer constantly has an up to date understanding of the codebase and especially a current grasp of the design and overall vision will always be more efficient than working remotely and having merge checkpoints, no matter how cleverly the VCS handles branching. This is why I think a faster, distributed, superior at merging VCS is not something more dramatic than a desirable step forward.&lt;/p&gt;
        &lt;/div&gt;
    </content>
  </entry>
  
  <entry>
    <id>http://nutrun.com/weblog/2009/08/15/hello-world-nginx-module.html</id>
    <published>2009-08-15T00:00:00Z</published>
    <updated>2009-08-15T00:00:00Z</updated>
    <link href="http://nutrun.com/weblog/2009/08/15/hello-world-nginx-module.html" rel="alternate" type="text/html" />
    <title>Hello world nginx module</title>
    <author>
      <name>George Malamidis</name>
      <uri>http://nutrun.com</uri>
    </author>
    <content type="html">
      &lt;div class=&quot;article&quot;&gt;
          
          
          &lt;p&gt;
            Several times over the past few months I made short lived attempts of delving into the mechanics of
            &lt;a href=&quot;http://nginx.net/&quot; title=&quot;nginx&quot;&gt;nginx&lt;/a&gt;
            modules. Although an invaluable resource to anyone seriously interested in the subject,
            &lt;a href=&quot;http://www.evanmiller.org/nginx-modules-guide.html&quot; title=&quot;Emiller's Guide to Nginx Module Development&quot;&gt;Emiller's Guide To Nginx Module Development&lt;/a&gt;
            doesn't at the time of this writing include a quick-start example I could hack together and see in action. Getting something to run as quickly as possible is my preferred way of starting the study of new things and every time I caught myself searching the web for a &quot;Hello world nginx module&quot;.
          &lt;/p&gt;
          &lt;p&gt;
            I will not go into any details,
            &lt;a href=&quot;http://www.evanmiller.org/nginx-modules-guide.html&quot; title=&quot;Emiller's Guide to Nginx Module Development&quot;&gt;Emiller's Guide&lt;/a&gt;
            does an excellent job at that, I'm only going to mention the steps I believe are absolutely necessary to write, compile and run an nginx handler module that responds to every request with the string &quot;Hello world&quot;.
          &lt;/p&gt;
          &lt;p&gt;
            There is a minimum of two files required for writing an nginx module, the first should be called
            &lt;code&gt;config&lt;/code&gt;
            and looks something like this:
          &lt;/p&gt;
          &lt;pre&gt;
ngx_addon_name=ngx_http_hello_world_module
HTTP_MODULES=&quot;$HTTP_MODULES ngx_http_hello_world_module&quot;
NGX_ADDON_SRCS=&quot;$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_hello_world_module.c&quot;&lt;/pre&gt;
          &lt;p&gt;
            The second is the module's implementation in C and nginx convention suggests a name like
            &lt;code&gt;ngx_http_modulename_module.c&lt;/code&gt;,
            in this case
            &lt;code&gt;ngx_http_hello_world_module.c&lt;/code&gt;.
          &lt;/p&gt;
          &lt;pre&gt;
#include &amp;lt;ngx_config.h&amp;gt;
#include &amp;lt;ngx_core.h&amp;gt;
#include &amp;lt;ngx_http.h&amp;gt;

static char *ngx_http_hello_world(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);

static ngx_command_t  ngx_http_hello_world_commands[] = {

  { ngx_string(&quot;hello_world&quot;),
    NGX_HTTP_LOC_CONF|NGX_CONF_NOARGS,
    ngx_http_hello_world,
    0,
    0,
    NULL },

    ngx_null_command
};


static u_char  ngx_hello_world[] = &quot;hello world&quot;;

static ngx_http_module_t  ngx_http_hello_world_module_ctx = {
  NULL,                          /* preconfiguration */
  NULL,                          /* postconfiguration */

  NULL,                          /* create main configuration */
  NULL,                          /* init main configuration */

  NULL,                          /* create server configuration */
  NULL,                          /* merge server configuration */

  NULL,                          /* create location configuration */
  NULL                           /* merge location configuration */
};


ngx_module_t ngx_http_hello_world_module = {
  NGX_MODULE_V1,
  &amp;amp;ngx_http_hello_world_module_ctx, /* module context */
  ngx_http_hello_world_commands,   /* module directives */
  NGX_HTTP_MODULE,               /* module type */
  NULL,                          /* init master */
  NULL,                          /* init module */
  NULL,                          /* init process */
  NULL,                          /* init thread */
  NULL,                          /* exit thread */
  NULL,                          /* exit process */
  NULL,                          /* exit master */
  NGX_MODULE_V1_PADDING
};


static ngx_int_t ngx_http_hello_world_handler(ngx_http_request_t *r)
{
  ngx_buf_t    *b;
  ngx_chain_t   out;

  r-&amp;gt;headers_out.content_type.len = sizeof(&quot;text/plain&quot;) - 1;
  r-&amp;gt;headers_out.content_type.data = (u_char *) &quot;text/plain&quot;;

  b = ngx_pcalloc(r-&amp;gt;pool, sizeof(ngx_buf_t));

  out.buf = b;
  out.next = NULL;

  b-&amp;gt;pos = ngx_hello_world;
  b-&amp;gt;last = ngx_hello_world + sizeof(ngx_hello_world);
  b-&amp;gt;memory = 1;
  b-&amp;gt;last_buf = 1;

  r-&amp;gt;headers_out.status = NGX_HTTP_OK;
  r-&amp;gt;headers_out.content_length_n = sizeof(ngx_hello_world);
  ngx_http_send_header(r);

  return ngx_http_output_filter(r, &amp;amp;out);
}


static char *ngx_http_hello_world(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
  ngx_http_core_loc_conf_t  *clcf;

  clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
  clcf-&amp;gt;handler = ngx_http_hello_world_handler;

  return NGX_CONF_OK;
}&lt;/pre&gt;
          &lt;p&gt;
            Both
            &lt;code&gt;config&lt;/code&gt;
            and
            &lt;code&gt;ngx_http_hello_world_module.c&lt;/code&gt;
            should be placed in the same directory, let's say
            &lt;code&gt;/etc/ngxhelloworld&lt;/code&gt;.
            Modules are compiled into the nginx binary. To do so,
            &lt;a href=&quot;http://wiki.nginx.org/NginxInstall&quot; title=&quot;NginxInstall&quot;&gt;download the nginx source&lt;/a&gt;,
            uncompress, and in the nginx source directory run:
          &lt;/p&gt;
          &lt;pre&gt;
./configure --add-module=/etc/ngxhelloworld
make
sudo make install&lt;/pre&gt;
          &lt;p&gt;
            Finally, add a module directive to nginx's configuration (default is
            &lt;code&gt;/usr/local/nginx/conf/nginx.conf&lt;/code&gt;)
            to enable the module for a location.
          &lt;/p&gt;
          &lt;pre&gt;
location = /hello {
  hello_world;
}&lt;/pre&gt;
          &lt;p&gt;
            At this point, we can start nginx and navigating to
            &lt;code&gt;http://localhost/hello&lt;/code&gt;
            will yield the result of all this labor.
          &lt;/p&gt;
          &lt;p&gt;
            Alongside Emiller's Guide, I also found reading
            &lt;a href=&quot;http://wiki.nginx.org/Nginx3rdPartyModules&quot; title=&quot;Nginx3rdPartyModules&quot;&gt;nginx third party module&lt;/a&gt;
            code helpful.
          &lt;/p&gt;
        &lt;/div&gt;
    </content>
  </entry>
  
  <entry>
    <id>http://nutrun.com/weblog/2009/08/06/asynchronous-session-content-injection.html</id>
    <published>2009-08-06T00:00:00Z</published>
    <updated>2009-08-06T00:00:00Z</updated>
    <link href="http://nutrun.com/weblog/2009/08/06/asynchronous-session-content-injection.html" rel="alternate" type="text/html" />
    <title>Asynchronous session content injection</title>
    <author>
      <name>George Malamidis</name>
      <uri>http://nutrun.com</uri>
    </author>
    <content type="html">
      &lt;div class=&quot;article&quot;&gt;
  
  
  &lt;p&gt;Applying a clear distinction between stateless and stateful content when designing a web application is tricky but worth tackling early so that content not specific to user sessions can benefit from web caching. The technique we are trying out for &lt;a href=&quot;http://www.scramble.com/&quot; title=&quot;&quot;&gt;scramble.com&lt;/a&gt; reminds me of what I described in &lt;a href=&quot;http://nutrun.com/weblog/state-separation/&quot; title=&quot;nutrun  » Blog Archive   » State separation&quot;&gt;State separation&lt;/a&gt; and was introduced to me by &lt;a href=&quot;http://www.neophiliac.net/&quot; title=&quot;ne•o•phil•i•ac&quot;&gt;Mike Jones&lt;/a&gt; who was inspired by the &lt;em&gt;Dynamically Update Cached Pages&lt;/em&gt; chapter in &lt;a href=&quot;http://www.pragprog.com/titles/fr_arr/advanced-rails-recipes&quot; title=&quot;The Pragmatic Bookshelf | Advanced Rails Recipes&quot;&gt;Advanced Rails Recipes&lt;/a&gt;.&lt;/p&gt;
  &lt;p&gt;&lt;a href=&quot;http://www.flickr.com/photos/nutrun/3794424247/&quot; title=&quot;asynchronous-session-content-injection by nutrunflickr, on Flickr&quot;&gt;&lt;img alt=&quot;asynchronous-session-content-injection&quot; height=&quot;242&quot; src=&quot;http://farm3.static.flickr.com/2501/3794424247_30b0d5cc52_o.png&quot; width=&quot;331&quot;&gt;&lt;/a&gt;&lt;/p&gt;
  &lt;p&gt;The idea involves serving non session specific resources independent from personalized content and use AJAX calls to inject the page with session specific content.&lt;/p&gt;
  &lt;pre&gt;
require 'rubygems'
require 'sinatra'
require 'json'

configure do
  enable :sessions
end

get '/' do
  headers['Cache-Control'] = 'max-age=60, must-revalidate'
  erb :index
end

get '/userinfo' do
  if session[:user]
    JSON.dump(:user =&amp;gt; session[:user])
  else
    halt 401
  end
end

get '/login' do
  session[:user] = 'rock'
  redirect '/'
end

get '/logout' do
  session.clear
  redirect '/'
end
  &lt;/pre&gt;
  &lt;p&gt;Notice some of the headers for &lt;code&gt;'/'&lt;/code&gt;:&lt;/p&gt;

  &lt;pre&gt;
$ curl -I http://localhost:4567/
Cache-Control: max-age=60, must-revalidate
Set-Cookie: rack.session=BAh7AA%3D%3D%0A; path=/
  &lt;/pre&gt;
  &lt;p&gt;The &lt;code&gt;Cache-Control&lt;/code&gt; policy instructs a web cache to keep this version of the resource for 60 seconds before requesting a fresh one. &lt;code&gt;Set-Cookie&lt;/code&gt; however will usually cause a web cache to never store the response and always query its back end.&lt;/p&gt;
  &lt;p&gt;The following configuration tells &lt;a href=&quot;http://varnish.projects.linpro.no/&quot; title=&quot;Varnish - Trac&quot;&gt;Varnish&lt;/a&gt; to throw away the cookie from any request/response that doesn' match one of the URLs that require authorization, thus causing it to react to response cache policies.&lt;/p&gt;
  &lt;pre&gt;
sub vcl_recv {
  if (req.url !~ &quot;^(/login|/logout|/userinfo)&quot;) {
    unset req.http.cookie;
  }
}

sub vcl_fetch {
  if (req.url !~ &quot;^(/login|/logout|/userinfo)&quot;) {
    unset obj.http.set-cookie;
  }
}
  &lt;/pre&gt;
  &lt;p&gt;A snippet from the HTML response for &lt;code&gt;'/'&lt;/code&gt;:&lt;/p&gt;
  &lt;pre&gt;
&amp;lt;h1&amp;gt;Hi&amp;lt;/h1&amp;gt;
&amp;lt;div id=&quot;nav&quot;&amp;gt;
  &amp;lt;a href=&quot;/login&quot; class=&quot;login-control&quot;&amp;gt;Login&amp;lt;/a&amp;gt;
&amp;lt;/div&amp;gt;
  &lt;/pre&gt;
  &lt;p&gt;... and the javascript for asynchronously injecting session data to the page:&lt;/p&gt;
  &lt;pre&gt;
$(function() {
  $.getJSON('/userinfo', function(data) {
    $('h1').text('Hi ' + data.user);
    $('#nav .login-control').attr('href', '/logout').html('logout');
  })
})
  &lt;/pre&gt;
  &lt;p&gt;In summary, it is likely that a website will have significant amounts of content that is intended for everyone without the need for personalization. The performance of serving that content can benefit from web caching, but that becomes difficult as many websites' user experience depends on the presence of user sessions. Separating stateless from session specific content at the resource level and using a combination of HTTP and AJAX to merge the results of requests for both types of resources will make stateless content cacheable by decoupling it from the unnecessary cookie dependency.&lt;/p&gt;
  &lt;p&gt;Runnable code example: &lt;a href=&quot;http://pastie.org/573878&quot;&gt;http://pastie.org/573878&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;
    </content>
  </entry>
  
  <entry>
    <id>http://nutrun.com/weblog/2009/05/18/rackcacheheaders-code.html</id>
    <published>2009-05-18T00:00:00Z</published>
    <updated>2009-05-18T00:00:00Z</updated>
    <link href="http://nutrun.com/weblog/2009/05/18/rackcacheheaders-code.html" rel="alternate" type="text/html" />
    <title>Rack::CacheHeaders code</title>
    <author>
      <name>George Malamidis</name>
      <uri>http://nutrun.com</uri>
    </author>
    <content type="html">
      &lt;div class=&quot;article&quot;&gt;
          
          
          &lt;p&gt;
            A few months ago I
            &lt;a href=&quot;http://nutrun.com/weblog/rack-cache-headers/&quot; title=&quot;nutrun  » Blog Archive   » Rack cache headers&quot;&gt;wrote&lt;/a&gt;
            about a possible method for centrally configuring HTTP cache headers in
            &lt;a href=&quot;http://rack.rubyforge.org/&quot; title=&quot;Rack: a Ruby Webserver Interface&quot;&gt;Rack&lt;/a&gt;
            based web applications which I called
            &lt;code&gt;Rack::CacheHeaders&lt;/code&gt;.
            This is useful if your application's architecture involves tools like
            &lt;a href=&quot;http://www.squid-cache.org/&quot; title=&quot;squid : Optimising Web Delivery&quot;&gt;Squid&lt;/a&gt;
            or
            &lt;a href=&quot;http://varnish.projects.linpro.no/&quot; title=&quot;Varnish - Trac&quot;&gt;Varnish&lt;/a&gt;,
            or if you are generally interested in harvesting the numerous advantages of HTTP caching for your web application.
          &lt;/p&gt;
          &lt;p&gt;
            The code has evolved a bit since and proven useful in a number of production systems. I created a
            &lt;a href=&quot;http://gist.github.com/113441&quot; title=&quot;gist: 113441 - GitHub&quot;&gt;gist&lt;/a&gt;
            of
            &lt;code&gt;Rack::CacheHeaders&lt;/code&gt;
            in case someone else finds it handy. The tool is not exhaustive in terms of policies as found in the HTTP
            &lt;a href=&quot;http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html&quot; title=&quot;HTTP/1.1: Caching in HTTP&quot;&gt;specs&lt;/a&gt;,
            it's a collection of the ones we needed in the projects it's been used so far. Consider adding ones you need to the gist to make the code more complete and widely useful.
          &lt;/p&gt;
          &lt;p&gt;
            &lt;code&gt;Rack::CacheHeaders&lt;/code&gt;
            allows configuring HTTP cache policy response headers based on request URI patterns. For example, to set the
            &lt;code&gt;Cache-Control: max-age&lt;/code&gt;
            header for a
            &lt;code&gt;/guitars/:id&lt;/code&gt;
            resource to one hour:
          &lt;/p&gt;
          &lt;pre&gt;
Rack::CacheHeaders.configure do |cache|
  cache.max_age(/^\/guitars\/d+$/, 3600)
end&lt;/pre&gt;
          &lt;p&gt;
            &lt;a href=&quot;http://gist.github.com/113441&quot; title=&quot;gist: 113441 - GitHub&quot;&gt;Download/develop Rack::CacheHeaders&lt;/a&gt;
          &lt;/p&gt;
        &lt;/div&gt;
    </content>
  </entry>
  
  <entry>
    <id>http://nutrun.com/weblog/2009/02/28/97-things-every-software-architect-should-know.html</id>
    <published>2009-02-28T00:00:00Z</published>
    <updated>2009-02-28T00:00:00Z</updated>
    <link href="http://nutrun.com/weblog/2009/02/28/97-things-every-software-architect-should-know.html" rel="alternate" type="text/html" />
    <title>97 Things Every Software Architect Should Know</title>
    <author>
      <name>George Malamidis</name>
      <uri>http://nutrun.com</uri>
    </author>
    <content type="html">
      &lt;div class=&quot;article&quot;&gt;
          
          
          &lt;p&gt;
            A few months ago I wrote one of the axioms for a community effort called
            &lt;a href=&quot;http://97-things.near-time.net/wiki&quot; title=&quot;Home Page for 97 Things 		 [97 Things] : Near-Time&quot;&gt;97 Things Every Software Architect Should Know&lt;/a&gt;
            which was driven and edited by
            &lt;a href=&quot;http://www.monson-haefel.com/&quot; title=&quot;Monson-Haefel's Web Site&quot;&gt;Richard Monson-Haefel&lt;/a&gt;.
            This collection of principles, as contributed by an impressive range of software architects around the world, was recently released as a
            &lt;a href=&quot;http://oreilly.com/catalog/9780596522698/index.html&quot; title=&quot;97 Things Every Software Architect Should Know | O'Reilly Media&quot;&gt;book&lt;/a&gt;
            by
            &lt;a href=&quot;http://oreilly.com/&quot; title=&quot;O'Reilly Media - Spreading the knowledge of technology innovators&quot;&gt;O'Reilly Media&lt;/a&gt;
            and is well worth a look if you're interested in pragmatic advice based on how some of our colleagues approach technology projects.
          &lt;/p&gt;
        &lt;/div&gt;
    </content>
  </entry>
  
</feed>
