Skip to content

Instantly share code, notes, and snippets.

@ahoward
Last active December 20, 2015 18:19

Revisions

  1. ahoward revised this gist Aug 7, 2013. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions action.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    # it's not critical for understanding
    # but here is the associated server-side action
    #

    def version
    @program = load_program!
    @version = @program.versions.find(params[:version_id])

    if stale?(:last_modified => @version.updated_at, :etag => @version.cache_key)
    render
    end
    end
  2. ahoward revised this gist Aug 7, 2013. 1 changed file with 5 additions and 1 deletion.
    6 changes: 5 additions & 1 deletion quiz.js
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,8 @@
    // today's quiz is simple - fork this code and explain, in english, what it does. suggest simpler alternatives.
    // today's quiz is simple:
    //
    // fork this code and explain, in english, what it does.
    //
    // suggest simpler alternatives.
    //

    if(state != 'complete'){
  3. ahoward created this gist Aug 7, 2013.
    34 changes: 34 additions & 0 deletions quiz.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    // today's quiz is simple - fork this code and explain, in english, what it does. suggest simpler alternatives.
    //

    if(state != 'complete'){

    var get = function(){
    jq.ajax({
    'type' : 'GET',
    'url' : url,
    'cache' : false,

    'success' : function(html){
    version.replaceWith(html);
    }
    });
    };

    var head = function(callback){
    jq.ajax({
    'type' : 'HEAD',
    'url' : url,

    'success' : function(res, code, xhr){
    var server_last_modified = xhr.getResponseHeader("Last-Modified");

    if(Date.parse(server_last_modified) > Date.parse(last_modified)){
    callback();
    };
    }
    });
    };

    head(get);
    };